├── .github └── workflows │ ├── build_quickjs.yml │ └── build_quickjs_qjs_ns.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── cmake └── ios.toolchain.cmake ├── include ├── Blob │ ├── Android │ │ ├── arm64 │ │ │ └── SnapshotBlob.h │ │ ├── armv7a │ │ │ └── SnapshotBlob.h │ │ └── x64 │ │ │ └── SnapshotBlob.h │ ├── Linux │ │ └── SnapshotBlob.h │ ├── Win32 │ │ └── SnapshotBlob.h │ ├── Win64 │ │ └── SnapshotBlob.h │ ├── Win64MD │ │ └── SnapshotBlob.h │ ├── iOS │ │ ├── arm64 │ │ │ └── SnapshotBlob.h │ │ └── bitcode │ │ │ └── SnapshotBlob.h │ ├── macOS │ │ └── SnapshotBlob.h │ └── macOS_arm64 │ │ └── SnapshotBlob.h ├── libplatform │ ├── libplatform-export.h │ └── libplatform.h ├── quickjs-msvc.h ├── v8-platform.h ├── v8.h └── v8config.h ├── make_android.sh ├── make_bc.sh ├── make_ios.sh ├── make_linux64.sh ├── make_ns.bat ├── make_ohos.sh ├── make_osx.sh ├── make_osx_arm64.sh ├── make_osx_dylib.sh ├── make_ps.bat ├── make_wasm.sh ├── make_win.sh ├── puer-build.json ├── quickjs ├── _VERSION ├── cutils.c ├── cutils.h ├── libbf.c ├── libbf.h ├── libregexp-opcode.h ├── libregexp.c ├── libregexp.h ├── libunicode-table.h ├── libunicode.c ├── libunicode.h ├── list.h ├── quickjs-atom.h ├── quickjs-opcode.h ├── quickjs.c ├── quickjs.h └── unicode_gen_def.h ├── src └── v8-impl.cc └── win ├── CMakeLists.txt ├── make_win32.bat ├── make_win64.bat ├── make_win64md.bat └── make_win64md_dll.bat /.github/workflows/build_quickjs.yml: -------------------------------------------------------------------------------- 1 | name: build quickjs backend 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | inputs: 7 | tag_date: 8 | description: 'tag date' 9 | required: true 10 | is_build_for_ohos: 11 | description: 'Build for harmony platform' 12 | type: boolean 13 | default: true 14 | required: false 15 | jobs: 16 | build_macos: 17 | name: macOS 18 | runs-on: macos-13 19 | steps: 20 | - uses: actions/checkout@v3 21 | - name: Run build script 22 | run: | 23 | cd $GITHUB_WORKSPACE 24 | chmod +x make_osx.sh 25 | sh ./make_osx.sh 26 | cp -r include $GITHUB_WORKSPACE/qjs/quickjs/Inc 27 | cp -r puer-build.json $GITHUB_WORKSPACE/qjs/quickjs/ 28 | cp -r $GITHUB_WORKSPACE/qjs ~/ 29 | - uses: actions/upload-artifact@v3 30 | with: 31 | name: qjs_v8_bin 32 | path: ~/qjs/**/* 33 | 34 | build_macos_dll: 35 | name: macOS 36 | runs-on: macos-13 37 | steps: 38 | - uses: actions/checkout@v3 39 | - name: Run build script 40 | run: | 41 | cd $GITHUB_WORKSPACE 42 | chmod +x make_osx_dylib.sh 43 | sh ./make_osx_dylib.sh 44 | cp -r $GITHUB_WORKSPACE/qjs ~/ 45 | - uses: actions/upload-artifact@v3 46 | with: 47 | name: qjs_v8_bin 48 | path: ~/qjs/**/* 49 | 50 | build_macos_arm64: 51 | name: macOS_arm64 52 | runs-on: macos-13 53 | steps: 54 | - uses: actions/checkout@v3 55 | - name: Run build script 56 | run: | 57 | cd $GITHUB_WORKSPACE 58 | chmod +x make_osx_arm64.sh 59 | sh ./make_osx_arm64.sh 60 | cp -r include $GITHUB_WORKSPACE/qjs/quickjs/Inc 61 | cp -r $GITHUB_WORKSPACE/qjs ~/ 62 | - uses: actions/upload-artifact@v3 63 | with: 64 | name: qjs_v8_bin 65 | path: ~/qjs/**/* 66 | 67 | build_ios: 68 | name: iOS 69 | runs-on: macos-13 70 | steps: 71 | - uses: actions/checkout@v3 72 | - name: Run build script 73 | run: | 74 | cd $GITHUB_WORKSPACE 75 | chmod +x make_ios.sh 76 | sh ./make_ios.sh 77 | cp -r $GITHUB_WORKSPACE/qjs ~/ 78 | - uses: actions/upload-artifact@v3 79 | with: 80 | name: qjs_v8_bin 81 | path: ~/qjs/**/* 82 | 83 | build_android: 84 | name: Android 85 | runs-on: ubuntu-20.04 86 | steps: 87 | - uses: actions/checkout@v3 88 | - name: Install NDK 89 | run: | 90 | cd ~ 91 | wget -O NDK -q https://dl.google.com/android/repository/android-ndk-r21b-linux-x86_64.zip 92 | sudo apt install unzip -y 93 | unzip -q NDK 94 | - name: Run build script 95 | run: | 96 | cd $GITHUB_WORKSPACE 97 | chmod +x make_android.sh 98 | ANDROID_NDK=~/android-ndk-r21b ./make_android.sh 99 | cp -r $GITHUB_WORKSPACE/qjs ~/ 100 | - uses: actions/upload-artifact@v3 101 | with: 102 | name: qjs_v8_bin 103 | path: ~/qjs/**/* 104 | 105 | build_ohos: 106 | if: github.event.inputs.is_build_for_ohos == 'true' 107 | name: OHOS 108 | runs-on: ubuntu-20.04 109 | steps: 110 | - uses: actions/checkout@v3 111 | - name: Install NDK 112 | run: | 113 | cd ~ 114 | curl -O https://repo.huaweicloud.com/harmonyos/os/4.1-Release/ohos-sdk-windows_linux-public.tar.gz 115 | tar xvfz ohos-sdk-windows_linux-public.tar.gz 116 | cd ohos-sdk/linux 117 | unzip -o -d ./ native-linux-x64-4.1.7.5-Release.zip 118 | - name: Run build script 119 | run: | 120 | cd $GITHUB_WORKSPACE 121 | chmod +x make_ohos.sh 122 | OHOS_NDK_HOME=~/ohos-sdk/linux/native ./make_ohos.sh 123 | cp -r $GITHUB_WORKSPACE/qjs ~/ 124 | - uses: actions/upload-artifact@v3 125 | with: 126 | name: qjs_v8_bin 127 | path: ~/qjs/**/* 128 | 129 | build_linux: 130 | name: Linux 131 | runs-on: ubuntu-20.04 132 | steps: 133 | - uses: actions/checkout@v3 134 | - name: Install LibC++ 135 | run: | 136 | sudo apt-get update 137 | sudo apt-get install clang 138 | sudo apt-get install build-essential 139 | sudo apt-get install libc++-dev 140 | sudo apt-get install libc++abi-dev 141 | - name: Run build script 142 | run: | 143 | cd $GITHUB_WORKSPACE 144 | chmod +x make_linux64.sh 145 | ./make_linux64.sh 146 | cp -r $GITHUB_WORKSPACE/qjs ~/ 147 | - uses: actions/upload-artifact@v3 148 | with: 149 | name: qjs_v8_bin 150 | path: ~/qjs/**/* 151 | 152 | build_wasm: 153 | name: wasm 154 | runs-on: ubuntu-20.04 155 | steps: 156 | - uses: actions/checkout@v3 157 | - name: Install LibC++ 158 | run: | 159 | sudo apt-get update 160 | sudo apt-get install clang 161 | sudo apt-get install build-essential 162 | sudo apt-get install libc++-dev 163 | sudo apt-get install libc++abi-dev 164 | - name: Run build script 165 | run: | 166 | cd $GITHUB_WORKSPACE 167 | chmod +x make_wasm.sh 168 | ./make_wasm.sh 169 | cp -r $GITHUB_WORKSPACE/qjs ~/ 170 | - uses: actions/upload-artifact@v3 171 | with: 172 | name: qjs_v8_bin 173 | path: ~/qjs/**/* 174 | 175 | build_window_dll: 176 | name: Windows 177 | runs-on: windows-2019 178 | steps: 179 | - uses: actions/checkout@v3 180 | - uses: msys2/setup-msys2@v2 181 | with: 182 | update: true 183 | install: 'cmake make mingw-w64-x86_64-gcc mingw-w64-x86_64-dlfcn' 184 | - shell: msys2 {0} 185 | run: | 186 | sh ./make_win.sh 187 | - name: Build 188 | run: | 189 | cd win 190 | .\make_win64.bat 191 | - uses: ilammy/msvc-dev-cmd@v1 192 | - name: Merge Libs 193 | run: | 194 | cd win 195 | LIB.EXE /OUT:quickjs.dll.lib ..\build\libquickjs.dll.a build\Release\v8qjs.lib 196 | - name: Prepare 197 | shell: msys2 {0} 198 | run: | 199 | mkdir -p qjs/quickjs/Lib/Win64/ 200 | cp win/quickjs.dll.lib qjs/quickjs/Lib/Win64/ 201 | cp build/msys-quickjs.dll qjs/quickjs/Lib/Win64/ 202 | cp build/libquickjs.dll.a qjs/quickjs/Lib/Win64/ 203 | cp /mingw64/bin/libgcc_s_seh-1.dll qjs/quickjs/Lib/Win64/ 204 | cp /mingw64/bin/libwinpthread-1.dll qjs/quickjs/Lib/Win64/ 205 | - uses: actions/upload-artifact@v3 206 | with: 207 | name: qjs_v8_bin 208 | path: qjs/**/* 209 | 210 | build_window_dll_md: 211 | name: Windows MD 212 | runs-on: windows-2019 213 | steps: 214 | - uses: actions/checkout@v3 215 | - name: Insatll MSVC 216 | uses: microsoft/setup-msbuild@v1.1 217 | - uses: msys2/setup-msys2@v2 218 | with: 219 | update: true 220 | install: 'cmake make mingw-w64-x86_64-gcc mingw-w64-x86_64-dlfcn' 221 | - shell: msys2 {0} 222 | run: | 223 | sh ./make_win.sh 224 | - name: Build 225 | run: | 226 | cd win 227 | .\make_win64md.bat 228 | - uses: ilammy/msvc-dev-cmd@v1 229 | - name: Merge Libs 230 | run: | 231 | cd win 232 | LIB.EXE /OUT:quickjs.dll.lib ..\build\libquickjs.dll.a build\Release\v8qjs.lib 233 | - name: Prepare 234 | shell: msys2 {0} 235 | run: | 236 | mkdir -p qjs/quickjs/Lib/Win64MD/ 237 | cp win/quickjs.dll.lib qjs/quickjs/Lib/Win64MD/ 238 | cp build/msys-quickjs.dll qjs/quickjs/Lib/Win64MD/ 239 | cp build/libquickjs.dll.a qjs/quickjs/Lib/Win64MD/ 240 | cp /mingw64/bin/libgcc_s_seh-1.dll qjs/quickjs/Lib/Win64MD/ 241 | cp /mingw64/bin/libwinpthread-1.dll qjs/quickjs/Lib/Win64MD/ 242 | - uses: actions/upload-artifact@v3 243 | with: 244 | name: qjs_v8_bin 245 | path: qjs/**/* 246 | 247 | build_window_dll_md_dll: 248 | name: Windows MD_dll 249 | runs-on: windows-2019 250 | steps: 251 | - uses: actions/checkout@v3 252 | - name: Insatll MSVC 253 | uses: microsoft/setup-msbuild@v1.1 254 | - uses: msys2/setup-msys2@v2 255 | with: 256 | update: true 257 | install: 'cmake make mingw-w64-x86_64-gcc mingw-w64-x86_64-dlfcn' 258 | - shell: msys2 {0} 259 | run: | 260 | sh ./make_win.sh 261 | - name: Build 262 | run: | 263 | cd win 264 | .\make_win64md_dll.bat 265 | - uses: ilammy/msvc-dev-cmd@v1 266 | - name: Merge Libs 267 | run: | 268 | cd win 269 | LIB.EXE /OUT:quickjs.dll.lib ..\build\libquickjs.dll.a build\Release\v8qjs.lib 270 | - name: Prepare 271 | shell: msys2 {0} 272 | run: | 273 | mkdir -p qjs/quickjs/Lib/Win64DLL/ 274 | cp win/quickjs.dll.lib qjs/quickjs/Lib/Win64DLL/ 275 | cp win/build/Release/v8qjs.dll qjs/quickjs/Lib/Win64DLL/ 276 | cp build/msys-quickjs.dll qjs/quickjs/Lib/Win64DLL/ 277 | cp build/libquickjs.dll.a qjs/quickjs/Lib/Win64DLL/ 278 | cp /mingw64/bin/libgcc_s_seh-1.dll qjs/quickjs/Lib/Win64DLL/ 279 | cp /mingw64/bin/libwinpthread-1.dll qjs/quickjs/Lib/Win64DLL/ 280 | - uses: actions/upload-artifact@v3 281 | with: 282 | name: qjs_v8_bin 283 | path: qjs/**/* 284 | 285 | build_window_dll32: 286 | name: Windows32 287 | runs-on: windows-2019 288 | steps: 289 | - uses: actions/checkout@v3 290 | - uses: msys2/setup-msys2@v2 291 | with: 292 | msystem: MINGW32 293 | update: true 294 | install: 'cmake make mingw-w64-i686-gcc mingw-w64-i686-dlfcn' 295 | - shell: msys2 {0} 296 | run: | 297 | sh ./make_win.sh 298 | - name: Build 299 | run: | 300 | cd win 301 | .\make_win32.bat 302 | - uses: ilammy/msvc-dev-cmd@v1 303 | - name: Merge Libs 304 | run: | 305 | cd win 306 | LIB.EXE /OUT:quickjs.dll.lib ..\build\libquickjs.dll.a build\Release\v8qjs.lib 307 | - name: Prepare 308 | shell: msys2 {0} 309 | run: | 310 | mkdir -p qjs/quickjs/Lib/Win32/ 311 | cp win/quickjs.dll.lib qjs/quickjs/Lib/Win32/ 312 | cp build/msys-quickjs.dll qjs/quickjs/Lib/Win32/ 313 | cp build/libquickjs.dll.a qjs/quickjs/Lib/Win32/ 314 | cp /mingw32/bin/libgcc_s_dw2-1.dll qjs/quickjs/Lib/Win32/ 315 | cp /mingw32/bin/libwinpthread-1.dll qjs/quickjs/Lib/Win32/ 316 | - uses: actions/upload-artifact@v3 317 | with: 318 | name: qjs_v8_bin 319 | path: qjs/**/* 320 | 321 | publish: 322 | runs-on: ubuntu-latest 323 | if: ${{ github.event.inputs.tag_date != '' }} 324 | needs: [build_android,build_window_dll,build_window_dll32,build_window_dll_md,build_window_dll_md_dll,build_macos,build_macos_dll,build_macos_arm64,build_ios,build_linux,build_ohos,build_wasm] 325 | steps: 326 | - uses: actions/download-artifact@v3 327 | with: 328 | name: qjs_v8_bin 329 | path: qjs_v8_bin/ 330 | 331 | - name: Create Release Asset 332 | run: | 333 | cd qjs_v8_bin/ && tar cvfz ../qjs_v8_bin.tgz quickjs && cd - 334 | 335 | - name: Create Release 336 | id: create_release 337 | uses: softprops/action-gh-release@v2 338 | with: 339 | tag_name: QJS_${{ github.event.inputs.tag_date }} 340 | name: QJS_${{ github.event.inputs.tag_date }} 341 | draft: false 342 | prerelease: false 343 | make_latest: true 344 | files: ./qjs_v8_bin.tgz 345 | 346 | -------------------------------------------------------------------------------- /.github/workflows/build_quickjs_qjs_ns.yml: -------------------------------------------------------------------------------- 1 | name: build quickjs backend with v8_qjs namespace 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | inputs: 7 | tag_date: 8 | description: 'tag date' 9 | required: true 10 | is_build_for_ohos: 11 | description: 'Build for harmony platform' 12 | type: boolean 13 | default: true 14 | required: false 15 | jobs: 16 | build_macos: 17 | name: macOS 18 | runs-on: macos-13 19 | steps: 20 | - uses: actions/checkout@v3 21 | - name: Run build script 22 | run: | 23 | cd $GITHUB_WORKSPACE 24 | chmod +x make_osx.sh 25 | sh ./make_osx.sh 1 26 | cp -r include $GITHUB_WORKSPACE/qjs/quickjs/Inc 27 | cp -r puer-build.json $GITHUB_WORKSPACE/qjs/quickjs/ 28 | cp -r $GITHUB_WORKSPACE/qjs ~/ 29 | - uses: actions/upload-artifact@v3 30 | with: 31 | name: qjs_v8_bin 32 | path: ~/qjs/**/* 33 | 34 | build_macos_dll: 35 | name: macOS 36 | runs-on: macos-13 37 | steps: 38 | - uses: actions/checkout@v3 39 | - name: Run build script 40 | run: | 41 | cd $GITHUB_WORKSPACE 42 | chmod +x make_osx_dylib.sh 43 | sh ./make_osx_dylib.sh 1 44 | cp -r $GITHUB_WORKSPACE/qjs ~/ 45 | - uses: actions/upload-artifact@v3 46 | with: 47 | name: qjs_v8_bin 48 | path: ~/qjs/**/* 49 | 50 | build_macos_arm64: 51 | name: macOS_arm64 52 | runs-on: macos-13 53 | steps: 54 | - uses: actions/checkout@v3 55 | - name: Run build script 56 | run: | 57 | cd $GITHUB_WORKSPACE 58 | chmod +x make_osx_arm64.sh 59 | sh ./make_osx_arm64.sh 1 60 | cp -r include $GITHUB_WORKSPACE/qjs/quickjs/Inc 61 | cp -r $GITHUB_WORKSPACE/qjs ~/ 62 | - uses: actions/upload-artifact@v3 63 | with: 64 | name: qjs_v8_bin 65 | path: ~/qjs/**/* 66 | 67 | build_ios: 68 | name: iOS 69 | runs-on: macos-13 70 | steps: 71 | - uses: actions/checkout@v3 72 | - name: Run build script 73 | run: | 74 | cd $GITHUB_WORKSPACE 75 | chmod +x make_ios.sh 76 | sh ./make_ios.sh 1 77 | cp -r $GITHUB_WORKSPACE/qjs ~/ 78 | - uses: actions/upload-artifact@v3 79 | with: 80 | name: qjs_v8_bin 81 | path: ~/qjs/**/* 82 | 83 | build_android: 84 | name: Android 85 | runs-on: ubuntu-20.04 86 | steps: 87 | - uses: actions/checkout@v3 88 | - name: Install NDK 89 | run: | 90 | cd ~ 91 | wget -O NDK -q https://dl.google.com/android/repository/android-ndk-r21b-linux-x86_64.zip 92 | sudo apt install unzip -y 93 | unzip -q NDK 94 | - name: Run build script 95 | run: | 96 | cd $GITHUB_WORKSPACE 97 | chmod +x make_android.sh 98 | ANDROID_NDK=~/android-ndk-r21b ./make_android.sh 1 99 | cp -r $GITHUB_WORKSPACE/qjs ~/ 100 | - uses: actions/upload-artifact@v3 101 | with: 102 | name: qjs_v8_bin 103 | path: ~/qjs/**/* 104 | 105 | build_ohos: 106 | if: github.event.inputs.is_build_for_ohos == 'true' 107 | name: OHOS 108 | runs-on: ubuntu-20.04 109 | steps: 110 | - uses: actions/checkout@v3 111 | - name: Install NDK 112 | run: | 113 | cd ~ 114 | curl -O https://repo.huaweicloud.com/harmonyos/os/4.1-Release/ohos-sdk-windows_linux-public.tar.gz 115 | tar xvfz ohos-sdk-windows_linux-public.tar.gz 116 | cd ohos-sdk/linux 117 | unzip -o -d ./ native-linux-x64-4.1.7.5-Release.zip 118 | - name: Run build script 119 | run: | 120 | cd $GITHUB_WORKSPACE 121 | chmod +x make_ohos.sh 122 | OHOS_NDK_HOME=~/ohos-sdk/linux/native ./make_ohos.sh 1 123 | cp -r $GITHUB_WORKSPACE/qjs ~/ 124 | - uses: actions/upload-artifact@v3 125 | with: 126 | name: qjs_v8_bin 127 | path: ~/qjs/**/* 128 | 129 | build_linux: 130 | name: Linux 131 | runs-on: ubuntu-20.04 132 | steps: 133 | - uses: actions/checkout@v3 134 | - name: Install LibC++ 135 | run: | 136 | sudo apt-get update 137 | sudo apt-get install clang 138 | sudo apt-get install build-essential 139 | sudo apt-get install libc++-dev 140 | sudo apt-get install libc++abi-dev 141 | - name: Run build script 142 | run: | 143 | cd $GITHUB_WORKSPACE 144 | chmod +x make_linux64.sh 145 | ./make_linux64.sh 1 146 | cp -r $GITHUB_WORKSPACE/qjs ~/ 147 | - uses: actions/upload-artifact@v3 148 | with: 149 | name: qjs_v8_bin 150 | path: ~/qjs/**/* 151 | 152 | build_wasm: 153 | name: wasm 154 | runs-on: ubuntu-20.04 155 | steps: 156 | - uses: actions/checkout@v3 157 | - name: Install LibC++ 158 | run: | 159 | sudo apt-get update 160 | sudo apt-get install clang 161 | sudo apt-get install build-essential 162 | sudo apt-get install libc++-dev 163 | sudo apt-get install libc++abi-dev 164 | - name: Run build script 165 | run: | 166 | cd $GITHUB_WORKSPACE 167 | chmod +x make_wasm.sh 168 | ./make_wasm.sh 1 169 | cp -r $GITHUB_WORKSPACE/qjs ~/ 170 | - uses: actions/upload-artifact@v3 171 | with: 172 | name: qjs_v8_bin 173 | path: ~/qjs/**/* 174 | 175 | build_window_dll: 176 | name: Windows 177 | runs-on: windows-2019 178 | steps: 179 | - uses: actions/checkout@v3 180 | - uses: msys2/setup-msys2@v2 181 | with: 182 | update: true 183 | install: 'cmake make mingw-w64-x86_64-gcc mingw-w64-x86_64-dlfcn' 184 | - shell: msys2 {0} 185 | run: | 186 | sh ./make_win.sh 187 | - name: Build 188 | run: | 189 | cd win 190 | .\make_win64.bat 1 191 | - uses: ilammy/msvc-dev-cmd@v1 192 | - name: Merge Libs 193 | run: | 194 | cd win 195 | LIB.EXE /OUT:quickjs.dll.lib ..\build\libquickjs.dll.a build\Release\v8qjs.lib 196 | - name: Prepare 197 | shell: msys2 {0} 198 | run: | 199 | mkdir -p qjs/quickjs/Lib/Win64/ 200 | cp win/quickjs.dll.lib qjs/quickjs/Lib/Win64/ 201 | cp build/msys-quickjs.dll qjs/quickjs/Lib/Win64/ 202 | cp build/libquickjs.dll.a qjs/quickjs/Lib/Win64/ 203 | cp /mingw64/bin/libgcc_s_seh-1.dll qjs/quickjs/Lib/Win64/ 204 | cp /mingw64/bin/libwinpthread-1.dll qjs/quickjs/Lib/Win64/ 205 | - uses: actions/upload-artifact@v3 206 | with: 207 | name: qjs_v8_bin 208 | path: qjs/**/* 209 | 210 | build_window_dll_md: 211 | name: Windows MD 212 | runs-on: windows-2019 213 | steps: 214 | - uses: actions/checkout@v3 215 | - name: Insatll MSVC 216 | uses: microsoft/setup-msbuild@v1.1 217 | - uses: msys2/setup-msys2@v2 218 | with: 219 | update: true 220 | install: 'cmake make mingw-w64-x86_64-gcc mingw-w64-x86_64-dlfcn' 221 | - shell: msys2 {0} 222 | run: | 223 | sh ./make_win.sh 224 | - name: Build 225 | run: | 226 | cd win 227 | .\make_win64md.bat 1 228 | - uses: ilammy/msvc-dev-cmd@v1 229 | - name: Merge Libs 230 | run: | 231 | cd win 232 | LIB.EXE /OUT:quickjs.dll.lib ..\build\libquickjs.dll.a build\Release\v8qjs.lib 233 | - name: Prepare 234 | shell: msys2 {0} 235 | run: | 236 | mkdir -p qjs/quickjs/Lib/Win64MD/ 237 | cp win/quickjs.dll.lib qjs/quickjs/Lib/Win64MD/ 238 | cp build/msys-quickjs.dll qjs/quickjs/Lib/Win64MD/ 239 | cp build/libquickjs.dll.a qjs/quickjs/Lib/Win64MD/ 240 | cp /mingw64/bin/libgcc_s_seh-1.dll qjs/quickjs/Lib/Win64MD/ 241 | cp /mingw64/bin/libwinpthread-1.dll qjs/quickjs/Lib/Win64MD/ 242 | - uses: actions/upload-artifact@v3 243 | with: 244 | name: qjs_v8_bin 245 | path: qjs/**/* 246 | 247 | build_window_dll_md_dll: 248 | name: Windows MD_dll 249 | runs-on: windows-2019 250 | steps: 251 | - uses: actions/checkout@v3 252 | - name: Insatll MSVC 253 | uses: microsoft/setup-msbuild@v1.1 254 | - uses: msys2/setup-msys2@v2 255 | with: 256 | update: true 257 | install: 'cmake make mingw-w64-x86_64-gcc mingw-w64-x86_64-dlfcn' 258 | - shell: msys2 {0} 259 | run: | 260 | sh ./make_win.sh 261 | - name: Build 262 | run: | 263 | cd win 264 | .\make_win64md_dll.bat 1 265 | - uses: ilammy/msvc-dev-cmd@v1 266 | - name: Merge Libs 267 | run: | 268 | cd win 269 | LIB.EXE /OUT:quickjs.dll.lib ..\build\libquickjs.dll.a build\Release\v8qjs.lib 270 | - name: Prepare 271 | shell: msys2 {0} 272 | run: | 273 | mkdir -p qjs/quickjs/Lib/Win64DLL/ 274 | cp win/quickjs.dll.lib qjs/quickjs/Lib/Win64DLL/ 275 | cp win/build/Release/v8qjs.dll qjs/quickjs/Lib/Win64DLL/ 276 | cp build/msys-quickjs.dll qjs/quickjs/Lib/Win64DLL/ 277 | cp build/libquickjs.dll.a qjs/quickjs/Lib/Win64DLL/ 278 | cp /mingw64/bin/libgcc_s_seh-1.dll qjs/quickjs/Lib/Win64DLL/ 279 | cp /mingw64/bin/libwinpthread-1.dll qjs/quickjs/Lib/Win64DLL/ 280 | - uses: actions/upload-artifact@v3 281 | with: 282 | name: qjs_v8_bin 283 | path: qjs/**/* 284 | 285 | build_window_dll32: 286 | name: Windows32 287 | runs-on: windows-2019 288 | steps: 289 | - uses: actions/checkout@v3 290 | - uses: msys2/setup-msys2@v2 291 | with: 292 | msystem: MINGW32 293 | update: true 294 | install: 'cmake make mingw-w64-i686-gcc mingw-w64-i686-dlfcn' 295 | - shell: msys2 {0} 296 | run: | 297 | sh ./make_win.sh 298 | - name: Build 299 | run: | 300 | cd win 301 | .\make_win32.bat 1 302 | - uses: ilammy/msvc-dev-cmd@v1 303 | - name: Merge Libs 304 | run: | 305 | cd win 306 | LIB.EXE /OUT:quickjs.dll.lib ..\build\libquickjs.dll.a build\Release\v8qjs.lib 307 | - name: Prepare 308 | shell: msys2 {0} 309 | run: | 310 | mkdir -p qjs/quickjs/Lib/Win32/ 311 | cp win/quickjs.dll.lib qjs/quickjs/Lib/Win32/ 312 | cp build/msys-quickjs.dll qjs/quickjs/Lib/Win32/ 313 | cp build/libquickjs.dll.a qjs/quickjs/Lib/Win32/ 314 | cp /mingw32/bin/libgcc_s_dw2-1.dll qjs/quickjs/Lib/Win32/ 315 | cp /mingw32/bin/libwinpthread-1.dll qjs/quickjs/Lib/Win32/ 316 | - uses: actions/upload-artifact@v3 317 | with: 318 | name: qjs_v8_bin 319 | path: qjs/**/* 320 | 321 | publish: 322 | runs-on: ubuntu-latest 323 | if: ${{ github.event.inputs.tag_date != '' }} 324 | needs: [build_android,build_window_dll,build_window_dll32,build_window_dll_md,build_window_dll_md_dll,build_macos,build_macos_dll,build_macos_arm64,build_ios,build_linux,build_ohos,build_wasm] 325 | steps: 326 | - uses: actions/download-artifact@v3 327 | with: 328 | name: qjs_v8_bin 329 | path: qjs_v8_bin/ 330 | 331 | - name: Create Release Asset 332 | run: | 333 | cd qjs_v8_bin/ && mv quickjs quickjs_ns && tar cvfz ../qjs_v8_bin.tgz quickjs_ns && cd - 334 | 335 | - name: Create Release 336 | id: create_release 337 | uses: softprops/action-gh-release@v2 338 | with: 339 | tag_name: QJS_CN_${{ github.event.inputs.tag_date }} 340 | name: QJS_CN_${{ github.event.inputs.tag_date }} 341 | draft: false 342 | prerelease: false 343 | make_latest: true 344 | files: ./qjs_v8_bin.tgz 345 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | buildPS5 2 | buildnx64 -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | project(quickjs) 4 | 5 | if (APPLE AND NOT IOS) 6 | set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version") 7 | 8 | if ( NOT DEFINED FOR_SILICON ) 9 | set(CMAKE_OSX_ARCHITECTURES x86_64) 10 | else () 11 | set(CMAKE_OSX_ARCHITECTURES arm64) 12 | endif () 13 | endif() 14 | 15 | # From https://github.com/Tencent/puerts/issues/1796 Author:NiceTry12138 16 | if (SWITCH_PLATFORM) 17 | message("using v8_qjs SWITCH_PLATFORM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") 18 | 19 | set(NINTENDO_SDK_ROOT $ENV{NINTENDO_SDK_ROOT}) 20 | set(NS_INCLUDE "${NINTENDO_SDK_ROOT}/Include") 21 | set(NS_SPECIFIC_INCLUDE "${NINTENDO_SDK_ROOT}/TargetSpecificInclude/NX-Win32-v142") 22 | set(NS_AARCH64 "${NINTENDO_SDK_ROOT}/Compilers/NX/nx/aarch64") 23 | 24 | set(NS_INCLUDE_LIST ${NS_INCLUDE}) # 定义搜索路径 25 | list(APPEND NS_INCLUDE_LIST ${NS_SPECIFIC_INCLUDE}) # 添加特殊文件搜索路径 26 | list(APPEND NS_INCLUDE_LIST "${NS_AARCH64}/include") # 添加 AARCH64 头文件 27 | list(APPEND NS_INCLUDE_LIST "${NINTENDO_SDK_ROOT}/Include/nn/socket") # 网络库相关 28 | 29 | set(NS_LIB_LIST "$${NS_AARCH64}/lib") # 添加 AARCH64 静态库 30 | 31 | if(NS_US_ELF) 32 | list(APPEND NS_INCLUDE_LIST "${NS_AARCH64}/include/aarch64-nintendo-nx-elf") 33 | list(APPEND NS_LIB_LIST "${NS_AARCH64}/lib/aarch64-nintendo-nx-elf") 34 | else () 35 | list(APPEND NS_INCLUDE_LIST "${NS_AARCH64}/include/aarch64-nintendo-nx-nncfi") 36 | list(APPEND NS_LIB_LIST "${NS_AARCH64}/lib/aarch64-nintendo-nx-nncfi") 37 | endif() 38 | 39 | add_compile_options(-fdeclspec) 40 | add_definitions(-DNN_SDK_BUILD_RELEASE) 41 | add_definitions(-D__SWITCH__) 42 | 43 | include_directories(${NS_INCLUDE_LIST}) 44 | link_directories(${NS_LIB_LIST}) 45 | endif() 46 | 47 | if (PS_PLATFORM) 48 | message("using v8_qjs PS_PLATFORM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") 49 | 50 | set(PS_SDK_ROOT $ENV{SCE_PROSPERO_SDK_DIR}) 51 | set(PS_INCLUDE_LIST "${PS_SDK_ROOT}/target/include") 52 | list(APPEND PS_INCLUDE_LIST "${PS_SDK_ROOT}/target/include_common") 53 | 54 | set(PS_LIB_LIST "${PS_SDK_ROOT}/target/lib") 55 | add_definitions(-D__PS__) 56 | 57 | include_directories(${PS_INCLUDE_LIST}) 58 | link_directories(${PS_LIB_LIST}) 59 | 60 | endif() 61 | 62 | set(qjs_cflags -Wall) 63 | if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang") 64 | list(APPEND qjs_cflags 65 | -Wextra 66 | -Wno-sign-compare 67 | -Wno-missing-field-initializers 68 | -Wno-unused-parameter 69 | -Wno-unused-variable 70 | -funsigned-char 71 | -fPIC) 72 | else() 73 | list(APPEND qjs_cflags 74 | -Wno-array-bounds 75 | -Wno-unused-variable 76 | -Wno-unused-but-set-variable 77 | -fPIC) 78 | endif() 79 | 80 | set(SRC_FILES 81 | quickjs/cutils.c 82 | quickjs/libbf.c 83 | quickjs/libregexp.c 84 | quickjs/libunicode.c 85 | quickjs/quickjs.c 86 | ) 87 | if ( NOT MSYS OR NOT WIN_DLL ) 88 | list(APPEND SRC_FILES src/v8-impl.cc) 89 | endif() 90 | 91 | file(STRINGS "quickjs/_VERSION" QJS_VERSION_STR) 92 | 93 | set (CMAKE_CXX_STANDARD 14) 94 | 95 | include_directories( 96 | include 97 | quickjs 98 | ) 99 | 100 | if ( MSYS ) 101 | if ( WIN_DLL ) 102 | add_library(quickjs SHARED ${SRC_FILES}) 103 | else () 104 | add_library(quickjs STATIC ${SRC_FILES}) 105 | endif() 106 | target_compile_definitions(quickjs PRIVATE 107 | _GNU_SOURCE 108 | CONFIG_BIGNUM 109 | CONFIG_VERSION="\\\"${QJS_VERSION_STR}\\\"" 110 | ) 111 | else() 112 | if ( BUILD_SHARED ) 113 | add_library(quickjs SHARED ${SRC_FILES}) 114 | else () 115 | add_library(quickjs STATIC ${SRC_FILES}) 116 | endif() 117 | target_compile_definitions(quickjs PRIVATE 118 | _GNU_SOURCE 119 | CONFIG_BIGNUM 120 | CONFIG_VERSION="${QJS_VERSION_STR}" 121 | ) 122 | endif() 123 | 124 | if (UNIX AND NOT OHOS AND NOT (CMAKE_SYSTEM_NAME MATCHES "Emscripten")) 125 | set(CMAKE_CXX_COMPILER "clang++") 126 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") 127 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi") 128 | endif () 129 | 130 | if (BIYE_CODE) 131 | set(CMAKE_C_COMPILER clang) 132 | set(CMAKE_CXX_COMPILER clang++) 133 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") 134 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto") 135 | endif () 136 | 137 | #set_target_properties(quickjs PROPERTIES 138 | # C_STANDARD 99 139 | # C_STANDARD_REQUIRED ON 140 | # ) 141 | target_compile_options(quickjs PRIVATE ${qjs_cflags}) 142 | if (CMAKE_BUILD_TYPE MATCHES Debug) 143 | target_compile_definitions(quickjs PRIVATE 144 | DUMP_LEAKS 145 | ) 146 | endif() 147 | 148 | if (QJS_NS) 149 | message("using v8_qjs namespace >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") 150 | target_compile_definitions(quickjs PRIVATE CUSTOMV8NAMESPACE=v8_qjs) 151 | else () 152 | message("using v8 namespace >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") 153 | endif() 154 | 155 | target_include_directories(quickjs PUBLIC ${CMAKE_SOURCE_DIR}) 156 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 157 | target_link_libraries(quickjs atomic) 158 | endif() 159 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022, chexiongsheng 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /cmake/ios.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of the ios-cmake project. It was retrieved from 2 | # https://github.com/cristeab/ios-cmake.git, which is a fork of 3 | # https://code.google.com/p/ios-cmake/. Which in turn is based off of 4 | # the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which 5 | # are included with CMake 2.8.4 6 | # 7 | # The ios-cmake project is licensed under the new BSD license. 8 | # 9 | # Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software, 10 | # Kitware, Inc., Insight Software Consortium. All rights reserved. 11 | # Redistribution and use in source and binary forms, with or without 12 | # modification, are permitted provided that the following conditions 13 | # are met: 14 | # 1. Redistributions of source code must retain the above copyright 15 | # notice, this list of conditions and the following disclaimer. 16 | # 17 | # 2. Redistributions in binary form must reproduce the above copyright 18 | # notice, this list of conditions and the following disclaimer in the 19 | # documentation and/or other materials provided with the distribution. 20 | # 21 | # 3. Neither the name of the copyright holder nor the names of its 22 | # contributors may be used to endorse or promote products derived from 23 | # this software without specific prior written permission. 24 | # 25 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 | # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 | # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | # POSSIBILITY OF SUCH DAMAGE. 37 | # 38 | # This file is based off of the Platform/Darwin.cmake and 39 | # Platform/UnixPaths.cmake files which are included with CMake 2.8.4 40 | # It has been altered for iOS development. 41 | # 42 | # Updated by Alex Stewart (alexs.mac@gmail.com) 43 | # 44 | # ***************************************************************************** 45 | # Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com) 46 | # under the BSD-3-Clause license 47 | # https://github.com/leetal/ios-cmake 48 | # ***************************************************************************** 49 | # 50 | # INFORMATION / HELP 51 | # 52 | # The following arguments control the behaviour of this toolchain: 53 | # 54 | # PLATFORM: (default "OS") 55 | # OS = Build for iPhoneOS. 56 | # OS64 = Build for arm64 iphoneOS. 57 | # OS64COMBINED = Build for arm64 x86_64 iphoneOS. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith "-G Xcode" argument ONLY) 58 | # SIMULATOR = Build for x86 i386 iphoneOS Simulator. 59 | # SIMULATOR64 = Build for x86_64 iphoneOS Simulator. 60 | # TVOS = Build for arm64 tvOS. 61 | # TVOSCOMBINED = Build for arm64 x86_64 tvOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY) 62 | # SIMULATOR_TVOS = Build for x86_64 tvOS Simulator. 63 | # WATCHOS = Build for armv7k arm64_32 for watchOS. 64 | # 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) 65 | # SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator. 66 | # 67 | # CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is 68 | # automatically determined from PLATFORM and xcodebuild, but 69 | # can also be manually specified (although this should not be required). 70 | # 71 | # CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform 72 | # being compiled for. By default this is automatically determined from 73 | # CMAKE_OSX_SYSROOT, but can also be manually specified (although this should 74 | # not be required). 75 | # 76 | # DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS 77 | # 78 | # ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true) 79 | # 80 | # ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default) 81 | # 82 | # ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default) 83 | # 84 | # ENABLE_STRICT_TRY_COMPILE: (1|0) Enables or disables strict try_compile() on all Check* directives (will run linker 85 | # to actually check if linking is possible). Default 0 (false, will set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY) 86 | # 87 | # ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM 88 | # OS = armv7 armv7s arm64 (if applicable) 89 | # OS64 = arm64 (if applicable) 90 | # SIMULATOR = i386 91 | # SIMULATOR64 = x86_64 92 | # TVOS = arm64 93 | # SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated) 94 | # WATCHOS = armv7k arm64_32 (if applicable) 95 | # SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated) 96 | # 97 | # This toolchain defines the following variables for use externally: 98 | # 99 | # XCODE_VERSION: Version number (not including Build version) of Xcode detected. 100 | # SDK_VERSION: Version of SDK being used. 101 | # CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM). 102 | # 103 | # This toolchain defines the following macros for use externally: 104 | # 105 | # set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT) 106 | # A convenience macro for setting xcode specific properties on targets. 107 | # Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel 108 | # example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all"). 109 | # 110 | # find_host_package (PROGRAM ARGS) 111 | # A macro used to find executable programs on the host system, not within the 112 | # environment. Thanks to the android-cmake project for providing the 113 | # command. 114 | # 115 | # ******************************** DEPRECATIONS ******************************* 116 | # 117 | # IOS_DEPLOYMENT_TARGET: (Deprecated) Alias to DEPLOYMENT_TARGET 118 | # CMAKE_IOS_DEVELOPER_ROOT: (Deprecated) Alias to CMAKE_DEVELOPER_ROOT 119 | # IOS_PLATFORM: (Deprecated) Alias to PLATFORM 120 | # IOS_ARCH: (Deprecated) Alias to ARCHS 121 | # 122 | # ***************************************************************************** 123 | # 124 | 125 | # Fix for PThread library not in path 126 | set(CMAKE_THREAD_LIBS_INIT "-lpthread") 127 | set(CMAKE_HAVE_THREADS_LIBRARY 1) 128 | set(CMAKE_USE_WIN32_THREADS_INIT 0) 129 | set(CMAKE_USE_PTHREADS_INIT 1) 130 | 131 | # Cache what generator is used 132 | set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE) 133 | 134 | if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14") 135 | set(MODERN_CMAKE YES) 136 | message(STATUS "Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!") 137 | endif() 138 | 139 | # Get the Xcode version being used. 140 | execute_process(COMMAND xcodebuild -version 141 | OUTPUT_VARIABLE XCODE_VERSION 142 | ERROR_QUIET 143 | OUTPUT_STRIP_TRAILING_WHITESPACE) 144 | string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}") 145 | string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}") 146 | message(STATUS "Building with Xcode version: ${XCODE_VERSION}") 147 | 148 | ######## ALIASES (DEPRECATION WARNINGS) 149 | 150 | if(DEFINED IOS_PLATFORM) 151 | set(PLATFORM ${IOS_PLATFORM}) 152 | message(DEPRECATION "IOS_PLATFORM argument is DEPRECATED. Consider using the new PLATFORM argument instead.") 153 | endif() 154 | 155 | if(DEFINED IOS_DEPLOYMENT_TARGET) 156 | set(DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET}) 157 | message(DEPRECATION "IOS_DEPLOYMENT_TARGET argument is DEPRECATED. Consider using the new DEPLOYMENT_TARGET argument instead.") 158 | endif() 159 | 160 | if(DEFINED CMAKE_IOS_DEVELOPER_ROOT) 161 | set(CMAKE_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT}) 162 | message(DEPRECATION "CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.") 163 | endif() 164 | 165 | if(DEFINED IOS_ARCH) 166 | set(ARCHS ${IOS_ARCH}) 167 | message(DEPRECATION "IOS_ARCH argument is DEPRECATED. Consider using the new ARCHS argument instead.") 168 | endif() 169 | 170 | ######## END ALIASES 171 | 172 | # Unset the FORCE on cache variables if in try_compile() 173 | set(FORCE_CACHE FORCE) 174 | get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) 175 | if(_CMAKE_IN_TRY_COMPILE) 176 | unset(FORCE_CACHE) 177 | endif() 178 | 179 | # Default to building for iPhoneOS if not specified otherwise, and we cannot 180 | # determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use 181 | # of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly 182 | # determine the value of PLATFORM from the root project, as 183 | # CMAKE_OSX_ARCHITECTURES is propagated to them by CMake. 184 | if(NOT DEFINED PLATFORM) 185 | if (CMAKE_OSX_ARCHITECTURES) 186 | if(CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*") 187 | set(PLATFORM "OS") 188 | elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*") 189 | set(PLATFORM "SIMULATOR") 190 | elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*") 191 | set(PLATFORM "SIMULATOR64") 192 | elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvos.*") 193 | set(PLATFORM "TVOS") 194 | elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvsimulator.*") 195 | set(PLATFORM "SIMULATOR_TVOS") 196 | elseif(CMAKE_OSX_ARCHITECTURES MATCHES ".*armv7k.*" AND CMAKE_OSX_SYSROOT MATCHES ".*watchos.*") 197 | set(PLATFORM "WATCHOS") 198 | elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*watchsimulator.*") 199 | set(PLATFORM "SIMULATOR_WATCHOS") 200 | endif() 201 | endif() 202 | if (NOT PLATFORM) 203 | set(PLATFORM "OS") 204 | endif() 205 | endif() 206 | 207 | set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.") 208 | 209 | # Handle the case where we are targeting iOS and a version above 10.3.4 (32-bit support dropped officially) 210 | if(PLATFORM_INT STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) 211 | set(PLATFORM_INT "OS64") 212 | message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") 213 | elseif(PLATFORM_INT STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) 214 | set(PLATFORM_INT "SIMULATOR64") 215 | message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") 216 | endif() 217 | 218 | # Determine the platform name and architectures for use in xcodebuild commands 219 | # from the specified PLATFORM name. 220 | if(PLATFORM_INT STREQUAL "OS") 221 | set(SDK_NAME iphoneos) 222 | if(NOT ARCHS) 223 | set(ARCHS armv7 armv7s arm64) 224 | endif() 225 | elseif(PLATFORM_INT STREQUAL "OS64") 226 | set(SDK_NAME iphoneos) 227 | if(NOT ARCHS) 228 | if (XCODE_VERSION VERSION_GREATER 10.0) 229 | set(ARCHS arm64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example 230 | else() 231 | set(ARCHS arm64) 232 | endif() 233 | endif() 234 | elseif(PLATFORM_INT STREQUAL "OS64COMBINED") 235 | set(SDK_NAME iphoneos) 236 | if(MODERN_CMAKE) 237 | if(NOT ARCHS) 238 | if (XCODE_VERSION VERSION_GREATER 10.0) 239 | 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 240 | else() 241 | set(ARCHS arm64 x86_64) 242 | endif() 243 | endif() 244 | else() 245 | message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work") 246 | endif() 247 | elseif(PLATFORM_INT STREQUAL "SIMULATOR") 248 | set(SDK_NAME iphonesimulator) 249 | if(NOT ARCHS) 250 | set(ARCHS i386) 251 | endif() 252 | message(DEPRECATION "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.") 253 | elseif(PLATFORM_INT STREQUAL "SIMULATOR64") 254 | set(SDK_NAME iphonesimulator) 255 | if(NOT ARCHS) 256 | set(ARCHS x86_64) 257 | endif() 258 | elseif(PLATFORM_INT STREQUAL "TVOS") 259 | set(SDK_NAME appletvos) 260 | if(NOT ARCHS) 261 | set(ARCHS arm64) 262 | endif() 263 | elseif (PLATFORM_INT STREQUAL "TVOSCOMBINED") 264 | set(SDK_NAME appletvos) 265 | if(MODERN_CMAKE) 266 | if(NOT ARCHS) 267 | set(ARCHS arm64 x86_64) 268 | endif() 269 | else() 270 | message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work") 271 | endif() 272 | elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") 273 | set(SDK_NAME appletvsimulator) 274 | if(NOT ARCHS) 275 | set(ARCHS x86_64) 276 | endif() 277 | elseif(PLATFORM_INT STREQUAL "WATCHOS") 278 | set(SDK_NAME watchos) 279 | if(NOT ARCHS) 280 | if (XCODE_VERSION VERSION_GREATER 10.0) 281 | set(ARCHS armv7k arm64_32) 282 | else() 283 | set(ARCHS armv7k) 284 | endif() 285 | endif() 286 | elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED") 287 | set(SDK_NAME watchos) 288 | if(MODERN_CMAKE) 289 | if(NOT ARCHS) 290 | if (XCODE_VERSION VERSION_GREATER 10.0) 291 | set(ARCHS armv7k arm64_32 i386) 292 | else() 293 | set(ARCHS armv7k i386) 294 | endif() 295 | endif() 296 | else() 297 | message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work") 298 | endif() 299 | elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") 300 | set(SDK_NAME watchsimulator) 301 | if(NOT ARCHS) 302 | set(ARCHS i386) 303 | endif() 304 | else() 305 | message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}") 306 | endif() 307 | message(STATUS "Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}") 308 | 309 | if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") 310 | message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode") 311 | endif() 312 | 313 | # If user did not specify the SDK root to use, then query xcodebuild for it. 314 | execute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path 315 | OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT 316 | ERROR_QUIET 317 | OUTPUT_STRIP_TRAILING_WHITESPACE) 318 | if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT) 319 | message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain" 320 | "is pointing to the correct path. Please run:" 321 | "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" 322 | "and see if that fixes the problem for you.") 323 | message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} " 324 | "does not exist.") 325 | elseif(DEFINED CMAKE_OSX_SYSROOT) 326 | message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT} for platform: ${PLATFORM_INT} when checking compatibility") 327 | elseif(DEFINED CMAKE_OSX_SYSROOT_INT) 328 | message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT} for platform: ${PLATFORM_INT}") 329 | set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "") 330 | endif() 331 | 332 | # Set Xcode property for SDKROOT as well if Xcode generator is used 333 | if(USED_CMAKE_GENERATOR MATCHES "Xcode") 334 | set(CMAKE_OSX_SYSROOT "${SDK_NAME}" CACHE INTERNAL "") 335 | if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM) 336 | set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM 123456789A CACHE INTERNAL "") 337 | endif() 338 | endif() 339 | 340 | # Specify minimum version of deployment target. 341 | if(NOT DEFINED DEPLOYMENT_TARGET) 342 | if (PLATFORM_INT STREQUAL "WATCHOS" OR PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") 343 | # Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS). 344 | set(DEPLOYMENT_TARGET "2.0" 345 | CACHE STRING "Minimum SDK version to build for." ) 346 | else() 347 | # Unless specified, SDK version 9.0 is used by default as minimum target version (iOS, tvOS). 348 | set(DEPLOYMENT_TARGET "9.0" 349 | CACHE STRING "Minimum SDK version to build for." ) 350 | endif() 351 | message(STATUS "Using the default min-version since DEPLOYMENT_TARGET not provided!") 352 | endif() 353 | # Use bitcode or not 354 | if(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES "((^|;|, )(i386|x86_64))+") 355 | # Unless specified, enable bitcode support by default 356 | message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!") 357 | set(ENABLE_BITCODE TRUE) 358 | elseif(NOT DEFINED ENABLE_BITCODE) 359 | message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!") 360 | set(ENABLE_BITCODE FALSE) 361 | endif() 362 | set(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" ${FORCE_CACHE}) 363 | # Use ARC or not 364 | if(NOT DEFINED ENABLE_ARC) 365 | # Unless specified, enable ARC support by default 366 | set(ENABLE_ARC TRUE) 367 | message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!") 368 | endif() 369 | set(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" ${FORCE_CACHE}) 370 | # Use hidden visibility or not 371 | if(NOT DEFINED ENABLE_VISIBILITY) 372 | # Unless specified, disable symbols visibility by default 373 | set(ENABLE_VISIBILITY FALSE) 374 | message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!") 375 | endif() 376 | set(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" ${FORCE_CACHE}) 377 | # Set strict compiler checks or not 378 | if(NOT DEFINED ENABLE_STRICT_TRY_COMPILE) 379 | # Unless specified, disable strict try_compile() 380 | set(ENABLE_STRICT_TRY_COMPILE FALSE) 381 | message(STATUS "Using NON-strict compiler checks by default. ENABLE_STRICT_TRY_COMPILE not provided!") 382 | endif() 383 | set(ENABLE_STRICT_TRY_COMPILE_INT ${ENABLE_STRICT_TRY_COMPILE} CACHE BOOL "Whether or not to use strict compiler checks" ${FORCE_CACHE}) 384 | # Get the SDK version information. 385 | execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion 386 | OUTPUT_VARIABLE SDK_VERSION 387 | ERROR_QUIET 388 | OUTPUT_STRIP_TRAILING_WHITESPACE) 389 | 390 | # Find the Developer root for the specific iOS platform being compiled for 391 | # from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in 392 | # CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain 393 | # this information from xcrun or xcodebuild. 394 | if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") 395 | get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH) 396 | get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH) 397 | 398 | if (NOT DEFINED CMAKE_DEVELOPER_ROOT) 399 | message(FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: " 400 | "${CMAKE_DEVELOPER_ROOT} does not exist.") 401 | endif() 402 | endif() 403 | # Find the C & C++ compilers for the specified SDK. 404 | if(NOT CMAKE_C_COMPILER) 405 | execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang 406 | OUTPUT_VARIABLE CMAKE_C_COMPILER 407 | ERROR_QUIET 408 | OUTPUT_STRIP_TRAILING_WHITESPACE) 409 | message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}") 410 | endif() 411 | if(NOT CMAKE_CXX_COMPILER) 412 | execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++ 413 | OUTPUT_VARIABLE CMAKE_CXX_COMPILER 414 | ERROR_QUIET 415 | OUTPUT_STRIP_TRAILING_WHITESPACE) 416 | message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}") 417 | endif() 418 | # Find (Apple's) libtool. 419 | execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool 420 | OUTPUT_VARIABLE BUILD_LIBTOOL 421 | ERROR_QUIET 422 | OUTPUT_STRIP_TRAILING_WHITESPACE) 423 | message(STATUS "Using libtool: ${BUILD_LIBTOOL}") 424 | # Configure libtool to be used instead of ar + ranlib to build static libraries. 425 | # This is required on Xcode 7+, but should also work on previous versions of 426 | # Xcode. 427 | set(CMAKE_C_CREATE_STATIC_LIBRARY 428 | "${BUILD_LIBTOOL} -static -o ") 429 | set(CMAKE_CXX_CREATE_STATIC_LIBRARY 430 | "${BUILD_LIBTOOL} -static -o ") 431 | # Find the toolchain's provided install_name_tool if none is found on the host 432 | if(NOT CMAKE_INSTALL_NAME_TOOL) 433 | execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find install_name_tool 434 | OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL_INT 435 | ERROR_QUIET 436 | OUTPUT_STRIP_TRAILING_WHITESPACE) 437 | set(CMAKE_INSTALL_NAME_TOOL ${CMAKE_INSTALL_NAME_TOOL_INT} CACHE STRING "" ${FORCE_CACHE}) 438 | message(STATUS "Using install_name_tool: ${CMAKE_INSTALL_NAME_TOOL}") 439 | endif() 440 | # Get the version of Darwin (OS X) of the host. 441 | execute_process(COMMAND uname -r 442 | OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION 443 | ERROR_QUIET 444 | OUTPUT_STRIP_TRAILING_WHITESPACE) 445 | # CMake 3.14+ support building for iOS, watchOS and tvOS out of the box. 446 | if(MODERN_CMAKE) 447 | if(SDK_NAME MATCHES "iphone") 448 | set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE}) 449 | elseif(SDK_NAME MATCHES "appletv") 450 | set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE}) 451 | elseif(SDK_NAME MATCHES "watch") 452 | set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE}) 453 | endif() 454 | 455 | # Provide flags for a combined FAT library build on newer CMake versions 456 | if(PLATFORM_INT MATCHES ".*COMBINED") 457 | set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO CACHE INTERNAL "" ${FORCE_CACHE}) 458 | set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL "" ${FORCE_CACHE}) 459 | message(STATUS "Will combine built (static) artifacts into FAT lib...") 460 | endif() 461 | else() 462 | # Legacy code path prior to CMake 3.14 463 | set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" ${FORCE_CACHE}) 464 | endif() 465 | # Standard settings. 466 | set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "") 467 | set(UNIX TRUE CACHE BOOL "") 468 | set(APPLE TRUE CACHE BOOL "") 469 | set(IOS TRUE CACHE BOOL "") 470 | set(CMAKE_AR ar CACHE FILEPATH "" FORCE) 471 | set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) 472 | set(CMAKE_STRIP strip CACHE FILEPATH "" FORCE) 473 | # Set the architectures for which to build. 474 | set(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING "Build architecture for iOS") 475 | # Change the type of target generated for try_compile() so it'll work when cross-compiling, weak compiler checks 476 | if(ENABLE_STRICT_TRY_COMPILE_INT) 477 | message(STATUS "Using strict compiler checks (default in CMake).") 478 | else() 479 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 480 | endif() 481 | # All iOS/Darwin specific settings - some may be redundant. 482 | set(CMAKE_SHARED_LIBRARY_PREFIX "lib") 483 | set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") 484 | set(CMAKE_SHARED_MODULE_PREFIX "lib") 485 | set(CMAKE_SHARED_MODULE_SUFFIX ".so") 486 | set(CMAKE_C_COMPILER_ABI ELF) 487 | set(CMAKE_CXX_COMPILER_ABI ELF) 488 | set(CMAKE_C_HAS_ISYSROOT 1) 489 | set(CMAKE_CXX_HAS_ISYSROOT 1) 490 | set(CMAKE_MODULE_EXISTS 1) 491 | set(CMAKE_DL_LIBS "") 492 | set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ") 493 | set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") 494 | set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") 495 | set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") 496 | 497 | if(ARCHS MATCHES "((^|;|, )(arm64|arm64e|x86_64))+") 498 | set(CMAKE_C_SIZEOF_DATA_PTR 8) 499 | set(CMAKE_CXX_SIZEOF_DATA_PTR 8) 500 | if(ARCHS MATCHES "((^|;|, )(arm64|arm64e))+") 501 | set(CMAKE_SYSTEM_PROCESSOR "aarch64") 502 | else() 503 | set(CMAKE_SYSTEM_PROCESSOR "x86_64") 504 | endif() 505 | message(STATUS "Using a data_ptr size of 8") 506 | else() 507 | set(CMAKE_C_SIZEOF_DATA_PTR 4) 508 | set(CMAKE_CXX_SIZEOF_DATA_PTR 4) 509 | set(CMAKE_SYSTEM_PROCESSOR "arm") 510 | message(STATUS "Using a data_ptr size of 4") 511 | endif() 512 | 513 | message(STATUS "Building for minimum ${SDK_NAME} version: ${DEPLOYMENT_TARGET}" 514 | " (SDK version: ${SDK_VERSION})") 515 | # Note that only Xcode 7+ supports the newer more specific: 516 | # -m${SDK_NAME}-version-min flags, older versions of Xcode use: 517 | # -m(ios/ios-simulator)-version-min instead. 518 | if(PLATFORM_INT STREQUAL "OS" OR PLATFORM_INT STREQUAL "OS64") 519 | if(XCODE_VERSION VERSION_LESS 7.0) 520 | set(SDK_NAME_VERSION_FLAGS 521 | "-mios-version-min=${DEPLOYMENT_TARGET}") 522 | else() 523 | # Xcode 7.0+ uses flags we can build directly from SDK_NAME. 524 | set(SDK_NAME_VERSION_FLAGS 525 | "-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}") 526 | endif() 527 | elseif(PLATFORM_INT STREQUAL "TVOS") 528 | set(SDK_NAME_VERSION_FLAGS 529 | "-mtvos-version-min=${DEPLOYMENT_TARGET}") 530 | elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") 531 | set(SDK_NAME_VERSION_FLAGS 532 | "-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}") 533 | elseif(PLATFORM_INT STREQUAL "WATCHOS") 534 | set(SDK_NAME_VERSION_FLAGS 535 | "-mwatchos-version-min=${DEPLOYMENT_TARGET}") 536 | elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") 537 | set(SDK_NAME_VERSION_FLAGS 538 | "-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}") 539 | else() 540 | # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min. 541 | set(SDK_NAME_VERSION_FLAGS 542 | "-mios-simulator-version-min=${DEPLOYMENT_TARGET}") 543 | endif() 544 | message(STATUS "Version flags set to: ${SDK_NAME_VERSION_FLAGS}") 545 | set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING 546 | "Set CMake deployment target" ${FORCE_CACHE}) 547 | 548 | if(ENABLE_BITCODE_INT) 549 | set(BITCODE "-fembed-bitcode") 550 | set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode CACHE INTERNAL "") 551 | message(STATUS "Enabling bitcode support.") 552 | else() 553 | set(BITCODE "") 554 | set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO CACHE INTERNAL "") 555 | message(STATUS "Disabling bitcode support.") 556 | endif() 557 | 558 | if(ENABLE_ARC_INT) 559 | set(FOBJC_ARC "-fobjc-arc") 560 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES CACHE INTERNAL "") 561 | message(STATUS "Enabling ARC support.") 562 | else() 563 | set(FOBJC_ARC "-fno-objc-arc") 564 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO CACHE INTERNAL "") 565 | message(STATUS "Disabling ARC support.") 566 | endif() 567 | 568 | if(NOT ENABLE_VISIBILITY_INT) 569 | set(VISIBILITY "-fvisibility=hidden") 570 | set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES CACHE INTERNAL "") 571 | message(STATUS "Hiding symbols (-fvisibility=hidden).") 572 | else() 573 | set(VISIBILITY "") 574 | set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN NO CACHE INTERNAL "") 575 | endif() 576 | 577 | #Check if Xcode generator is used, since that will handle these flags automagically 578 | if(USED_CMAKE_GENERATOR MATCHES "Xcode") 579 | message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator.") 580 | else() 581 | set(CMAKE_C_FLAGS 582 | "${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}") 583 | # Hidden visibilty is required for C++ on iOS. 584 | set(CMAKE_CXX_FLAGS 585 | "${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}") 586 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}") 587 | set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${CMAKE_CXX_FLAGS_MINSIZEREL}") 588 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") 589 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${CMAKE_CXX_FLAGS_RELEASE}") 590 | set(CMAKE_C_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") 591 | set(CMAKE_CXX_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") 592 | 593 | # In order to ensure that the updated compiler flags are used in try_compile() 594 | # tests, we have to forcibly set them in the CMake cache, not merely set them 595 | # in the local scope. 596 | list(APPEND VARS_TO_FORCE_IN_CACHE 597 | CMAKE_C_FLAGS 598 | CMAKE_CXX_FLAGS 599 | CMAKE_CXX_FLAGS_DEBUG 600 | CMAKE_CXX_FLAGS_RELWITHDEBINFO 601 | CMAKE_CXX_FLAGS_MINSIZEREL 602 | CMAKE_CXX_FLAGS_RELEASE 603 | CMAKE_C_LINK_FLAGS 604 | CMAKE_CXX_LINK_FLAGS) 605 | foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE}) 606 | set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "") 607 | endforeach() 608 | endif() 609 | 610 | set(CMAKE_PLATFORM_HAS_INSTALLNAME 1) 611 | set(CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks") 612 | set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names") 613 | set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-headerpad_max_install_names") 614 | set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") 615 | set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") 616 | set(CMAKE_FIND_LIBRARY_SUFFIXES ".tbd" ".dylib" ".so" ".a") 617 | set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name") 618 | 619 | # Set the find root to the iOS developer roots and to user defined paths. 620 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT_INT} ${CMAKE_PREFIX_PATH} CACHE STRING "Root path that will be prepended 621 | to all search paths") 622 | # Default to searching for frameworks first. 623 | set(CMAKE_FIND_FRAMEWORK FIRST) 624 | # Set up the default search directories for frameworks. 625 | set(CMAKE_FRAMEWORK_PATH 626 | ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks 627 | ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks 628 | ${CMAKE_FRAMEWORK_PATH} CACHE STRING "Frameworks search paths" ${FORCE_CACHE}) 629 | 630 | # By default, search both the specified iOS SDK and the remainder of the host filesystem. 631 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 632 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE STRING "" ${FORCE_CACHE}) 633 | endif() 634 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 635 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE STRING "" ${FORCE_CACHE}) 636 | endif() 637 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 638 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE STRING "" ${FORCE_CACHE}) 639 | endif() 640 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 641 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY CACHE STRING "" ${FORCE_CACHE}) 642 | endif() 643 | 644 | # 645 | # Some helper-macros below to simplify and beautify the CMakeFile 646 | # 647 | 648 | # This little macro lets you set any Xcode specific property. 649 | macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION) 650 | set(XCODE_RELVERSION_I "${XCODE_RELVERSION}") 651 | if(XCODE_RELVERSION_I STREQUAL "All") 652 | set_property(TARGET ${TARGET} PROPERTY 653 | XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}") 654 | else() 655 | set_property(TARGET ${TARGET} PROPERTY 656 | XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}") 657 | endif() 658 | endmacro(set_xcode_property) 659 | # This macro lets you find executable programs on the host system. 660 | macro(find_host_package) 661 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 662 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) 663 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) 664 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) 665 | set(IOS FALSE) 666 | find_package(${ARGN}) 667 | set(IOS TRUE) 668 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) 669 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) 670 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) 671 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) 672 | endmacro(find_host_package) 673 | -------------------------------------------------------------------------------- /include/Blob/Android/arm64/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //android arm64 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = { 7 | }; 8 | -------------------------------------------------------------------------------- /include/Blob/Android/armv7a/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //android armv7 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = { 7 | }; 8 | -------------------------------------------------------------------------------- /include/Blob/Android/x64/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //android x64 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = { 7 | }; 8 | -------------------------------------------------------------------------------- /include/Blob/Linux/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //osx 64 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = { 7 | }; 8 | -------------------------------------------------------------------------------- /include/Blob/Win32/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //window x86 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = {0}; 7 | -------------------------------------------------------------------------------- /include/Blob/Win64/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //window x64 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = {0}; 7 | -------------------------------------------------------------------------------- /include/Blob/Win64MD/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //window x64 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = {0}; 7 | -------------------------------------------------------------------------------- /include/Blob/iOS/arm64/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //ios arm64 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = { 7 | }; 8 | -------------------------------------------------------------------------------- /include/Blob/iOS/bitcode/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //ios arm64(bitcode) 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = { 7 | }; 8 | -------------------------------------------------------------------------------- /include/Blob/macOS/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //osx 64 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = { 7 | }; 8 | -------------------------------------------------------------------------------- /include/Blob/macOS_arm64/SnapshotBlob.h: -------------------------------------------------------------------------------- 1 | //osx 64 2 | #pragma once 3 | 4 | #include 5 | 6 | static const uint8_t SnapshotBlobCode[] = { 7 | }; 8 | -------------------------------------------------------------------------------- /include/libplatform/libplatform-export.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 the V8 project authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_ 6 | #define V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_ 7 | 8 | #if defined(_WIN32) 9 | 10 | #ifdef BUILDING_V8_PLATFORM_SHARED 11 | #define V8_PLATFORM_EXPORT __declspec(dllexport) 12 | #elif USING_V8_PLATFORM_SHARED 13 | #define V8_PLATFORM_EXPORT __declspec(dllimport) 14 | #else 15 | #define V8_PLATFORM_EXPORT 16 | #endif // BUILDING_V8_PLATFORM_SHARED 17 | 18 | #else // defined(_WIN32) 19 | 20 | // Setup for Linux shared library export. 21 | #ifdef BUILDING_V8_PLATFORM_SHARED 22 | #define V8_PLATFORM_EXPORT __attribute__((visibility("default"))) 23 | #else 24 | #define V8_PLATFORM_EXPORT 25 | #endif 26 | 27 | #endif // defined(_WIN32) 28 | 29 | #endif // V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_ 30 | -------------------------------------------------------------------------------- /include/libplatform/libplatform.h: -------------------------------------------------------------------------------- 1 | #ifndef V8_LIBPLATFORM_LIBPLATFORM_H_ 2 | #define V8_LIBPLATFORM_LIBPLATFORM_H_ 3 | 4 | #include 5 | 6 | #include "v8config.h" 7 | #include "libplatform/libplatform-export.h" 8 | #include "v8-platform.h" 9 | 10 | namespace CUSTOMV8NAMESPACE { 11 | namespace platform { 12 | 13 | V8_PLATFORM_EXPORT std::unique_ptr NewDefaultPlatform(); 14 | 15 | } // namespace platform 16 | } // namespace CUSTOMV8NAMESPACE 17 | 18 | #endif // V8_LIBPLATFORM_LIBPLATFORM_H_ 19 | -------------------------------------------------------------------------------- /include/v8-platform.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 the V8 project authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef V8_V8_PLATFORM_H_ 6 | #define V8_V8_PLATFORM_H_ 7 | 8 | #include 9 | #include 10 | #include // For abort. 11 | #include 12 | #include 13 | 14 | 15 | namespace CUSTOMV8NAMESPACE { 16 | 17 | class Platform { 18 | 19 | }; 20 | 21 | } // namespace CUSTOMV8NAMESPACE 22 | 23 | #endif // V8_V8_PLATFORM_H_ 24 | -------------------------------------------------------------------------------- /include/v8config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 the V8 project authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef V8CONFIG_H_ 6 | #define V8CONFIG_H_ 7 | 8 | #if !defined(CUSTOMV8NAMESPACE) 9 | #define CUSTOMV8NAMESPACE v8 10 | #endif 11 | 12 | // clang-format off 13 | 14 | // Platform headers for feature detection below. 15 | #if defined(__ANDROID__) 16 | # include 17 | #elif defined(__APPLE__) 18 | # include 19 | #elif defined(__linux__) 20 | # include 21 | #endif 22 | 23 | 24 | // This macro allows to test for the version of the GNU C library (or 25 | // a compatible C library that masquerades as glibc). It evaluates to 26 | // 0 if libc is not GNU libc or compatible. 27 | // Use like: 28 | // #if V8_GLIBC_PREREQ(2, 3) 29 | // ... 30 | // #endif 31 | #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) 32 | # define V8_GLIBC_PREREQ(major, minor) \ 33 | ((__GLIBC__ * 100 + __GLIBC_MINOR__) >= ((major) * 100 + (minor))) 34 | #else 35 | # define V8_GLIBC_PREREQ(major, minor) 0 36 | #endif 37 | 38 | 39 | // This macro allows to test for the version of the GNU C++ compiler. 40 | // Note that this also applies to compilers that masquerade as GCC, 41 | // for example clang and the Intel C++ compiler for Linux. 42 | // Use like: 43 | // #if V8_GNUC_PREREQ(4, 3, 1) 44 | // ... 45 | // #endif 46 | #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) 47 | # define V8_GNUC_PREREQ(major, minor, patchlevel) \ 48 | ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \ 49 | ((major) * 10000 + (minor) * 100 + (patchlevel))) 50 | #elif defined(__GNUC__) && defined(__GNUC_MINOR__) 51 | # define V8_GNUC_PREREQ(major, minor, patchlevel) \ 52 | ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= \ 53 | ((major) * 10000 + (minor) * 100 + (patchlevel))) 54 | #else 55 | # define V8_GNUC_PREREQ(major, minor, patchlevel) 0 56 | #endif 57 | 58 | 59 | 60 | // ----------------------------------------------------------------------------- 61 | // Operating system detection (host) 62 | // 63 | // V8_OS_ANDROID - Android 64 | // V8_OS_BSD - BSDish (Mac OS X, Net/Free/Open/DragonFlyBSD) 65 | // V8_OS_CYGWIN - Cygwin 66 | // V8_OS_DRAGONFLYBSD - DragonFlyBSD 67 | // V8_OS_FREEBSD - FreeBSD 68 | // V8_OS_FUCHSIA - Fuchsia 69 | // V8_OS_LINUX - Linux 70 | // V8_OS_MACOSX - Mac OS X 71 | // V8_OS_IOS - iOS 72 | // V8_OS_NETBSD - NetBSD 73 | // V8_OS_OPENBSD - OpenBSD 74 | // V8_OS_POSIX - POSIX compatible (mostly everything except Windows) 75 | // V8_OS_QNX - QNX Neutrino 76 | // V8_OS_SOLARIS - Sun Solaris and OpenSolaris 77 | // V8_OS_AIX - AIX 78 | // V8_OS_WIN - Microsoft Windows 79 | 80 | #if defined(__ANDROID__) 81 | # define V8_OS_ANDROID 1 82 | # define V8_OS_LINUX 1 83 | # define V8_OS_POSIX 1 84 | #elif defined(__APPLE__) 85 | # define V8_OS_BSD 1 86 | # define V8_OS_MACOSX 1 87 | # define V8_OS_POSIX 1 88 | # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE 89 | # define V8_OS_IOS 1 90 | # endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE 91 | #elif defined(__CYGWIN__) 92 | # define V8_OS_CYGWIN 1 93 | # define V8_OS_POSIX 1 94 | #elif defined(__linux__) 95 | # define V8_OS_LINUX 1 96 | # define V8_OS_POSIX 1 97 | #elif defined(__sun) 98 | # define V8_OS_POSIX 1 99 | # define V8_OS_SOLARIS 1 100 | #elif defined(_AIX) 101 | #define V8_OS_POSIX 1 102 | #define V8_OS_AIX 1 103 | #elif defined(__FreeBSD__) 104 | # define V8_OS_BSD 1 105 | # define V8_OS_FREEBSD 1 106 | # define V8_OS_POSIX 1 107 | #elif defined(__Fuchsia__) 108 | # define V8_OS_FUCHSIA 1 109 | # define V8_OS_POSIX 1 110 | #elif defined(__DragonFly__) 111 | # define V8_OS_BSD 1 112 | # define V8_OS_DRAGONFLYBSD 1 113 | # define V8_OS_POSIX 1 114 | #elif defined(__NetBSD__) 115 | # define V8_OS_BSD 1 116 | # define V8_OS_NETBSD 1 117 | # define V8_OS_POSIX 1 118 | #elif defined(__OpenBSD__) 119 | # define V8_OS_BSD 1 120 | # define V8_OS_OPENBSD 1 121 | # define V8_OS_POSIX 1 122 | #elif defined(__QNXNTO__) 123 | # define V8_OS_POSIX 1 124 | # define V8_OS_QNX 1 125 | #elif defined(_WIN32) 126 | # define V8_OS_WIN 1 127 | #endif 128 | 129 | // ----------------------------------------------------------------------------- 130 | // Operating system detection (target) 131 | // 132 | // V8_TARGET_OS_ANDROID 133 | // V8_TARGET_OS_FUCHSIA 134 | // V8_TARGET_OS_IOS 135 | // V8_TARGET_OS_LINUX 136 | // V8_TARGET_OS_MACOSX 137 | // V8_TARGET_OS_WIN 138 | // 139 | // If not set explicitly, these fall back to corresponding V8_OS_ values. 140 | 141 | #ifdef V8_HAVE_TARGET_OS 142 | 143 | // The target OS is provided, just check that at least one known value is set. 144 | # if !defined(V8_TARGET_OS_ANDROID) \ 145 | && !defined(V8_TARGET_OS_FUCHSIA) \ 146 | && !defined(V8_TARGET_OS_IOS) \ 147 | && !defined(V8_TARGET_OS_LINUX) \ 148 | && !defined(V8_TARGET_OS_MACOSX) \ 149 | && !defined(V8_TARGET_OS_WIN) 150 | # error No known target OS defined. 151 | # endif 152 | 153 | #else // V8_HAVE_TARGET_OS 154 | 155 | # if defined(V8_TARGET_OS_ANDROID) \ 156 | || defined(V8_TARGET_OS_FUCHSIA) \ 157 | || defined(V8_TARGET_OS_IOS) \ 158 | || defined(V8_TARGET_OS_LINUX) \ 159 | || defined(V8_TARGET_OS_MACOSX) \ 160 | || defined(V8_TARGET_OS_WIN) 161 | # error A target OS is defined but V8_HAVE_TARGET_OS is unset. 162 | # endif 163 | 164 | // Fall back to the detected host OS. 165 | #ifdef V8_OS_ANDROID 166 | # define V8_TARGET_OS_ANDROID 167 | #endif 168 | 169 | #ifdef V8_OS_FUCHSIA 170 | # define V8_TARGET_OS_FUCHSIA 171 | #endif 172 | 173 | #ifdef V8_OS_IOS 174 | # define V8_TARGET_OS_IOS 175 | #endif 176 | 177 | #ifdef V8_OS_LINUX 178 | # define V8_TARGET_OS_LINUX 179 | #endif 180 | 181 | #ifdef V8_OS_MACOSX 182 | # define V8_TARGET_OS_MACOSX 183 | #endif 184 | 185 | #ifdef V8_OS_WIN 186 | # define V8_TARGET_OS_WIN 187 | #endif 188 | 189 | #endif // V8_HAVE_TARGET_OS 190 | 191 | // ----------------------------------------------------------------------------- 192 | // C library detection 193 | // 194 | // V8_LIBC_MSVCRT - MSVC libc 195 | // V8_LIBC_BIONIC - Bionic libc 196 | // V8_LIBC_BSD - BSD libc derivate 197 | // V8_LIBC_GLIBC - GNU C library 198 | // V8_LIBC_UCLIBC - uClibc 199 | // 200 | // Note that testing for libc must be done using #if not #ifdef. For example, 201 | // to test for the GNU C library, use: 202 | // #if V8_LIBC_GLIBC 203 | // ... 204 | // #endif 205 | 206 | #if defined (_MSC_VER) 207 | # define V8_LIBC_MSVCRT 1 208 | #elif defined(__BIONIC__) 209 | # define V8_LIBC_BIONIC 1 210 | # define V8_LIBC_BSD 1 211 | #elif defined(__UCLIBC__) 212 | // Must test for UCLIBC before GLIBC, as UCLIBC pretends to be GLIBC. 213 | # define V8_LIBC_UCLIBC 1 214 | #elif defined(__GLIBC__) || defined(__GNU_LIBRARY__) 215 | # define V8_LIBC_GLIBC 1 216 | #else 217 | # define V8_LIBC_BSD V8_OS_BSD 218 | #endif 219 | 220 | 221 | // ----------------------------------------------------------------------------- 222 | // Compiler detection 223 | // 224 | // V8_CC_GNU - GCC, or clang in gcc mode 225 | // V8_CC_INTEL - Intel C++ 226 | // V8_CC_MINGW - Minimalist GNU for Windows 227 | // V8_CC_MINGW32 - Minimalist GNU for Windows (mingw32) 228 | // V8_CC_MINGW64 - Minimalist GNU for Windows (mingw-w64) 229 | // V8_CC_MSVC - Microsoft Visual C/C++, or clang in cl.exe mode 230 | // 231 | // C++11 feature detection 232 | // 233 | // Compiler-specific feature detection 234 | // 235 | // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) 236 | // supported 237 | // V8_HAS_ATTRIBUTE_NONNULL - __attribute__((nonnull)) supported 238 | // V8_HAS_ATTRIBUTE_NOINLINE - __attribute__((noinline)) supported 239 | // V8_HAS_ATTRIBUTE_UNUSED - __attribute__((unused)) supported 240 | // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported 241 | // V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT - __attribute__((warn_unused_result)) 242 | // supported 243 | // V8_HAS_BUILTIN_BSWAP16 - __builtin_bswap16() supported 244 | // V8_HAS_BUILTIN_BSWAP32 - __builtin_bswap32() supported 245 | // V8_HAS_BUILTIN_BSWAP64 - __builtin_bswap64() supported 246 | // V8_HAS_BUILTIN_CLZ - __builtin_clz() supported 247 | // V8_HAS_BUILTIN_CTZ - __builtin_ctz() supported 248 | // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported 249 | // V8_HAS_BUILTIN_FRAME_ADDRESS - __builtin_frame_address() supported 250 | // V8_HAS_BUILTIN_POPCOUNT - __builtin_popcount() supported 251 | // V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported 252 | // V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported 253 | // V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported 254 | // V8_HAS_COMPUTED_GOTO - computed goto/labels as values 255 | // supported 256 | // V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported 257 | // V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported 258 | // V8_HAS___FORCEINLINE - __forceinline supported 259 | // 260 | // Note that testing for compilers and/or features must be done using #if 261 | // not #ifdef. For example, to test for Intel C++ Compiler, use: 262 | // #if V8_CC_INTEL 263 | // ... 264 | // #endif 265 | 266 | #if defined(__clang__) 267 | 268 | #if defined(__GNUC__) // Clang in gcc mode. 269 | # define V8_CC_GNU 1 270 | #endif 271 | 272 | # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) 273 | # define V8_HAS_ATTRIBUTE_NONNULL (__has_attribute(nonnull)) 274 | # define V8_HAS_ATTRIBUTE_NOINLINE (__has_attribute(noinline)) 275 | # define V8_HAS_ATTRIBUTE_UNUSED (__has_attribute(unused)) 276 | # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) 277 | # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT \ 278 | (__has_attribute(warn_unused_result)) 279 | 280 | # define V8_HAS_BUILTIN_ASSUME_ALIGNED (__has_builtin(__builtin_assume_aligned)) 281 | # define V8_HAS_BUILTIN_BSWAP16 (__has_builtin(__builtin_bswap16)) 282 | # define V8_HAS_BUILTIN_BSWAP32 (__has_builtin(__builtin_bswap32)) 283 | # define V8_HAS_BUILTIN_BSWAP64 (__has_builtin(__builtin_bswap64)) 284 | # define V8_HAS_BUILTIN_CLZ (__has_builtin(__builtin_clz)) 285 | # define V8_HAS_BUILTIN_CTZ (__has_builtin(__builtin_ctz)) 286 | # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) 287 | # define V8_HAS_BUILTIN_FRAME_ADDRESS (__has_builtin(__builtin_frame_address)) 288 | # define V8_HAS_BUILTIN_POPCOUNT (__has_builtin(__builtin_popcount)) 289 | # define V8_HAS_BUILTIN_SADD_OVERFLOW (__has_builtin(__builtin_sadd_overflow)) 290 | # define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow)) 291 | # define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow)) 292 | 293 | // Clang has no __has_feature for computed gotos. 294 | // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html 295 | # define V8_HAS_COMPUTED_GOTO 1 296 | 297 | // Whether constexpr has full C++14 semantics, in particular that non-constexpr 298 | // code is allowed as long as it's not executed for any constexpr instantiation. 299 | # define V8_HAS_CXX14_CONSTEXPR 1 300 | 301 | #elif defined(__GNUC__) 302 | 303 | # define V8_CC_GNU 1 304 | # if defined(__INTEL_COMPILER) // Intel C++ also masquerades as GCC 3.2.0 305 | # define V8_CC_INTEL 1 306 | # endif 307 | # if defined(__MINGW32__) 308 | # define V8_CC_MINGW32 1 309 | # endif 310 | # if defined(__MINGW64__) 311 | # define V8_CC_MINGW64 1 312 | # endif 313 | # define V8_CC_MINGW (V8_CC_MINGW32 || V8_CC_MINGW64) 314 | 315 | // always_inline is available in gcc 4.0 but not very reliable until 4.4. 316 | // Works around "sorry, unimplemented: inlining failed" build errors with 317 | // older compilers. 318 | # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE 1 319 | # define V8_HAS_ATTRIBUTE_NOINLINE 1 320 | # define V8_HAS_ATTRIBUTE_UNUSED 1 321 | # define V8_HAS_ATTRIBUTE_VISIBILITY 1 322 | # define V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT (!V8_CC_INTEL) 323 | 324 | # define V8_HAS_BUILTIN_ASSUME_ALIGNED 1 325 | # define V8_HAS_BUILTIN_CLZ 1 326 | # define V8_HAS_BUILTIN_CTZ 1 327 | # define V8_HAS_BUILTIN_EXPECT 1 328 | # define V8_HAS_BUILTIN_FRAME_ADDRESS 1 329 | # define V8_HAS_BUILTIN_POPCOUNT 1 330 | 331 | // GCC doc: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html 332 | #define V8_HAS_COMPUTED_GOTO 1 333 | 334 | // Whether constexpr has full C++14 semantics, in particular that non-constexpr 335 | // code is allowed as long as it's not executed for any constexpr instantiation. 336 | // GCC only supports this since version 6. 337 | # define V8_HAS_CXX14_CONSTEXPR (V8_GNUC_PREREQ(6, 0, 0)) 338 | 339 | #endif 340 | 341 | #if defined(_MSC_VER) 342 | # define V8_CC_MSVC 1 343 | 344 | # define V8_HAS_DECLSPEC_NOINLINE 1 345 | # define V8_HAS_DECLSPEC_SELECTANY 1 346 | 347 | # define V8_HAS___FORCEINLINE 1 348 | 349 | #endif 350 | 351 | 352 | // ----------------------------------------------------------------------------- 353 | // Helper macros 354 | 355 | // A macro used to make better inlining. Don't bother for debug builds. 356 | // Use like: 357 | // V8_INLINE int GetZero() { return 0; } 358 | #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE 359 | # define V8_INLINE inline __attribute__((always_inline)) 360 | #elif !defined(DEBUG) && V8_HAS___FORCEINLINE 361 | # define V8_INLINE __forceinline 362 | #else 363 | # define V8_INLINE inline 364 | #endif 365 | 366 | #if V8_HAS_BUILTIN_ASSUME_ALIGNED 367 | # define V8_ASSUME_ALIGNED(ptr, alignment) \ 368 | __builtin_assume_aligned((ptr), (alignment)) 369 | #else 370 | # define V8_ASSUME_ALIGNED(ptr, alignment) (ptr) 371 | #endif 372 | 373 | 374 | // A macro to mark specific arguments as non-null. 375 | // Use like: 376 | // int add(int* x, int y, int* z) V8_NONNULL(1, 3) { return *x + y + *z; } 377 | #if V8_HAS_ATTRIBUTE_NONNULL 378 | # define V8_NONNULL(...) __attribute__((nonnull(__VA_ARGS__))) 379 | #else 380 | # define V8_NONNULL(...) /* NOT SUPPORTED */ 381 | #endif 382 | 383 | 384 | // A macro used to tell the compiler to never inline a particular function. 385 | // Use like: 386 | // V8_NOINLINE int GetMinusOne() { return -1; } 387 | #if V8_HAS_ATTRIBUTE_NOINLINE 388 | # define V8_NOINLINE __attribute__((noinline)) 389 | #elif V8_HAS_DECLSPEC_NOINLINE 390 | # define V8_NOINLINE __declspec(noinline) 391 | #else 392 | # define V8_NOINLINE /* NOT SUPPORTED */ 393 | #endif 394 | 395 | 396 | // A macro (V8_DEPRECATED) to mark classes or functions as deprecated. 397 | #if defined(V8_DEPRECATION_WARNINGS) 398 | # define V8_DEPRECATED(message) [[deprecated(message)]] 399 | #else 400 | # define V8_DEPRECATED(message) 401 | #endif 402 | 403 | 404 | // A macro (V8_DEPRECATE_SOON) to make it easier to see what will be deprecated. 405 | #if defined(V8_IMMINENT_DEPRECATION_WARNINGS) 406 | # define V8_DEPRECATE_SOON(message) [[deprecated(message)]] 407 | #else 408 | # define V8_DEPRECATE_SOON(message) 409 | #endif 410 | 411 | 412 | #if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 6) 413 | # define V8_ENUM_DEPRECATED(message) 414 | # define V8_ENUM_DEPRECATE_SOON(message) 415 | #else 416 | # define V8_ENUM_DEPRECATED(message) V8_DEPRECATED(message) 417 | # define V8_ENUM_DEPRECATE_SOON(message) V8_DEPRECATE_SOON(message) 418 | #endif 419 | 420 | 421 | // A macro to provide the compiler with branch prediction information. 422 | #if V8_HAS_BUILTIN_EXPECT 423 | # define V8_UNLIKELY(condition) (__builtin_expect(!!(condition), 0)) 424 | # define V8_LIKELY(condition) (__builtin_expect(!!(condition), 1)) 425 | #else 426 | # define V8_UNLIKELY(condition) (condition) 427 | # define V8_LIKELY(condition) (condition) 428 | #endif 429 | 430 | 431 | // Annotate a function indicating the caller must examine the return value. 432 | // Use like: 433 | // int foo() V8_WARN_UNUSED_RESULT; 434 | #if V8_HAS_ATTRIBUTE_WARN_UNUSED_RESULT 435 | #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 436 | #else 437 | #define V8_WARN_UNUSED_RESULT /* NOT SUPPORTED */ 438 | #endif 439 | 440 | #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) 441 | #error Inconsistent build configuration: To build the V8 shared library \ 442 | set BUILDING_V8_SHARED, to include its headers for linking against the \ 443 | V8 shared library set USING_V8_SHARED. 444 | #endif 445 | 446 | #ifdef V8_OS_WIN 447 | 448 | // Setup for Windows DLL export/import. When building the V8 DLL the 449 | // BUILDING_V8_SHARED needs to be defined. When building a program which uses 450 | // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 451 | // static library or building a program which uses the V8 static library neither 452 | // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. 453 | #ifdef BUILDING_V8_SHARED 454 | # define V8_EXPORT __declspec(dllexport) 455 | #elif USING_V8_SHARED 456 | # define V8_EXPORT __declspec(dllimport) 457 | #else 458 | # define V8_EXPORT 459 | #endif // BUILDING_V8_SHARED 460 | 461 | #else // V8_OS_WIN 462 | 463 | // Setup for Linux shared library export. 464 | #if V8_HAS_ATTRIBUTE_VISIBILITY 465 | # ifdef BUILDING_V8_SHARED 466 | # define V8_EXPORT __attribute__ ((visibility("default"))) 467 | # else 468 | # define V8_EXPORT 469 | # endif 470 | #else 471 | # define V8_EXPORT 472 | #endif 473 | 474 | #endif // V8_OS_WIN 475 | 476 | // clang-format on 477 | 478 | #endif // V8CONFIG_H_ 479 | -------------------------------------------------------------------------------- /make_android.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | if [ -n "$ANDROID_NDK" ]; then 8 | export NDK=${ANDROID_NDK} 9 | elif [ -n "$ANDROID_NDK_HOME" ]; then 10 | export NDK=${ANDROID_NDK_HOME} 11 | else 12 | export NDK=~/android-ndk-r21b 13 | fi 14 | 15 | if [ ! -d "$NDK" ]; then 16 | echo "Please set ANDROID_NDK environment to the root of NDK." 17 | exit 1 18 | fi 19 | 20 | function build() { 21 | API=$1 22 | ABI=$2 23 | TOOLCHAIN_ANME=$3 24 | BUILD_PATH=build.Android.${ABI} 25 | cmake -H. -B${BUILD_PATH} -DANDROID_ABI=${ABI} -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=${API} -DANDROID_TOOLCHAIN=clang -DANDROID_TOOLCHAIN_NAME=${TOOLCHAIN_ANME} -DQJS_NS=${QJSNS} 26 | cmake --build ${BUILD_PATH} --config Release 27 | mkdir -p ./qjs/quickjs/Lib/Android/${ABI}/ 28 | cp ${BUILD_PATH}/libquickjs.a ./qjs/quickjs/Lib/Android/${ABI}/libquickjs.a 29 | } 30 | 31 | build android-18 armeabi-v7a arm-linux-androideabi-4.9 32 | build android-18 arm64-v8a arm-linux-androideabi-clang 33 | build android-18 x86_64 x86_64-4.9 34 | 35 | -------------------------------------------------------------------------------- /make_bc.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | 8 | mkdir -p build_bc && cd build_bc 9 | cmake -DQJS_NS=${QJSNS} -DBIYE_CODE=1 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ../ 10 | make 11 | cd .. 12 | mkdir -p ./qjs/quickjs/Lib/wasm/bc 13 | find build_bc -type f -name "*.o" -exec bash -c 'cp "$0" "qjs/quickjs/Lib/wasm/bc/$(basename "$0" .o).bc"' {} \; 14 | -------------------------------------------------------------------------------- /make_ios.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | mkdir -p build_ios && cd build_ios 8 | cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DPLATFORM=OS64 -DQJS_NS=${QJSNS} -GXcode ../ 9 | cd .. 10 | cmake --build build_ios --config Release 11 | mkdir -p ./qjs/quickjs/Lib/iOS/arm64/ 12 | cp build_ios/Release-iphoneos/libquickjs.a ./qjs/quickjs/Lib/iOS/arm64/ 13 | 14 | -------------------------------------------------------------------------------- /make_linux64.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | mkdir -p build_linux64 && cd build_linux64 8 | cmake -DQJS_NS=${QJSNS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ../ 9 | cd .. 10 | cmake --build build_linux64 --config Release 11 | mkdir -p ./qjs/quickjs/Lib/Linux/ 12 | cp build_linux64/libquickjs.a ./qjs/quickjs/Lib/Linux/ -------------------------------------------------------------------------------- /make_ns.bat: -------------------------------------------------------------------------------- 1 | ::# From https://github.com/Tencent/puerts/issues/1796 Author:NiceTry12138 2 | set CUR_DIR=%~dp0 3 | cd %CUR_DIR% 4 | 5 | del /s/q buildnx64 6 | mkdir buildnx64 & pushd buildnx64 7 | 8 | set "NINTENDO_SDK_ROOT_CMAKE=%NINTENDO_SDK_ROOT:\=/%" 9 | cmake -DCMAKE_C_COMPILER="%NINTENDO_SDK_ROOT_CMAKE%/Compilers/NX/nx/aarch64/bin/clang.exe" ^ 10 | -DCMAKE_CXX_COMPILER="%NINTENDO_SDK_ROOT_CMAKE%/Compilers/NX/nx/aarch64/bin/clang++.exe" ^ 11 | -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Switch ^ 12 | -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ^ 13 | -DSWITCH_PLATFORM=1 ^ 14 | -DNS_US_ELF=1 ^ 15 | -DCMAKE_C_FLAGS="-I%CUR_DIR%buildnx64" ^ 16 | .. 17 | popd 18 | cmake --build buildnx64 --config Release -------------------------------------------------------------------------------- /make_ohos.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | if [ -n "$OHOS_NDK" ]; then 8 | export NDK=${OHOS_NDK} 9 | elif [ -n "$OHOS_NDK_HOME" ]; then 10 | export NDK=${OHOS_NDK_HOME} 11 | else 12 | export NDK=~/ohos-sdk/linux/native 13 | fi 14 | 15 | export PATH=${NDK}/build-tools/cmake/bin:$PATH 16 | 17 | function build() { 18 | ABI=$1 19 | BUILD_PATH=build.OHOS.${ABI} 20 | cmake -H. -DOHOS_STL=c++_shared -B${BUILD_PATH} -DOHOS_ARCH=${ABI} -DOHOS_PLATFORM=OHOS -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/ohos.toolchain.cmake -DQJS_NS=${QJSNS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON 21 | cmake --build ${BUILD_PATH} --config Release 22 | mkdir -p ./qjs/quickjs/Lib/OHOS/${ABI}/ 23 | cp ${BUILD_PATH}/libquickjs.a ./qjs/quickjs/Lib/OHOS/${ABI}/libquickjs.a 24 | } 25 | 26 | build armeabi-v7a 27 | build arm64-v8a 28 | -------------------------------------------------------------------------------- /make_osx.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | mkdir -p build && cd build 8 | cmake -GXcode -DQJS_NS=${QJSNS} ../ 9 | cd .. 10 | cmake --build build --config Release 11 | mkdir -p ./qjs/quickjs/Lib/macOS/ 12 | cp build/Release/libquickjs.a ./qjs/quickjs/Lib/macOS/ -------------------------------------------------------------------------------- /make_osx_arm64.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | mkdir -p build && cd build 8 | cmake -DFOR_SILICON=ON -GXcode -DQJS_NS=${QJSNS} ../ 9 | cd .. 10 | cmake --build build --config Release 11 | mkdir -p ./qjs/quickjs/Lib/macOS_arm64/ 12 | cp build/Release/libquickjs.a ./qjs/quickjs/Lib/macOS_arm64/ -------------------------------------------------------------------------------- /make_osx_dylib.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | mkdir -p build && cd build 8 | cmake -DBUILD_SHARED=1 -GXcode -DQJS_NS=${QJSNS} ../ 9 | cd .. 10 | cmake --build build --config Release 11 | mkdir -p ./qjs/quickjs/Lib/macOSdylib/ 12 | cp build/Release/libquickjs.dylib ./qjs/quickjs/Lib/macOSdylib/ 13 | -------------------------------------------------------------------------------- /make_ps.bat: -------------------------------------------------------------------------------- 1 | ::# From https://github.com/Tencent/puerts/issues/1796 Author:NiceTry12138 2 | set CUR_DIR=%~dp0 3 | cd %CUR_DIR% 4 | 5 | del /s/q buildPS5 6 | mkdir buildPS5 & pushd buildPS5 7 | 8 | cmake -DCMAKE_C_COMPILER="%SCE_PROSPERO_SDK_DIR%/host_tools/bin/prospero-clang.exe" ^ 9 | -DCMAKE_CXX_COMPILER="%SCE_PROSPERO_SDK_DIR%/host_tools/bin/prospero-clang.exe" ^ 10 | -DCMAKE_AS="%SCE_PROSPERO_SDK_DIR%/host_tools/bin/prospero-clang.exe" ^ 11 | -DCMAKE_AR="%SCE_PROSPERO_SDK_DIR%/host_tools/bin/prospero-llvm-ar.exe" ^ 12 | -DCMAKE_LINKER="%SCE_PROSPERO_SDK_DIR%/host_tools/bin/prospero-lld.exe" ^ 13 | -DCMAKE_NM="%SCE_PROSPERO_SDK_DIR%/host_tools/bin/prospero-llvm-nm.exe" ^ 14 | -DCMAKE_OBJCOPY="%SCE_PROSPERO_SDK_DIR%/host_tools/bin/prospero-llvm-objcopy.exe" ^ 15 | -DCMAKE_OBJDUMP="%SCE_PROSPERO_SDK_DIR%/host_tools/bin/prospero-llvm-objdump.exe" ^ 16 | -G "Unix Makefiles" ^ 17 | -DCMAKE_SYSTEM_NAME=Playstation ^ 18 | -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ^ 19 | -DPS_PLATFORM=1 ^ 20 | .. 21 | 22 | popd 23 | cmake --build buildPS5 --config Release 24 | 25 | pause -------------------------------------------------------------------------------- /make_wasm.sh: -------------------------------------------------------------------------------- 1 | if [ -n "$1" ]; then 2 | export QJSNS=1 3 | else 4 | export QJSNS=0 5 | fi 6 | 7 | git clone https://github.com/emscripten-core/emsdk.git 8 | cd emsdk 9 | git pull 10 | ./emsdk install 3.1.8 11 | ./emsdk activate 3.1.8 12 | source ./emsdk_env.sh 13 | cd .. 14 | 15 | mkdir -p build_wasm && cd build_wasm 16 | emcmake cmake -DQJS_NS=${QJSNS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ../ 17 | emmake make 18 | cd .. 19 | mkdir -p ./qjs/quickjs/Lib/wasm/wasm32 20 | cp build_wasm/libquickjs.a ./qjs/quickjs/Lib/wasm/wasm32/ -------------------------------------------------------------------------------- /make_win.sh: -------------------------------------------------------------------------------- 1 | mkdir build 2 | cd build 3 | cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_SYSTEM_NAME=MSYS -DWIN_DLL=1 .. 4 | cd .. 5 | cmake --build build --config Release 6 | -------------------------------------------------------------------------------- /puer-build.json: -------------------------------------------------------------------------------- 1 | { 2 | "definition": ["WITH_QUICKJS", "WITHOUT_INSPECTOR"], 3 | "include": ["/Inc"], 4 | "link-libraries": { 5 | "win": { 6 | "ia32": ["/Lib/Win32/quickjs.dll.lib"], 7 | "x64": ["/Lib/Win64/quickjs.dll.lib"] 8 | }, 9 | "android": { 10 | "armv7": ["/Lib/Android/armeabi-v7a/libquickjs.a"], 11 | "arm64": ["/Lib/Android/arm64-v8a/libquickjs.a"], 12 | "x64": ["/Lib/Android/x86_64/libquickjs.a"] 13 | }, 14 | "osx": { 15 | "x64": ["/Lib/macOS/libquickjs.a"], 16 | "arm64": ["/Lib/macOS_arm64/libquickjs.a"] 17 | }, 18 | "linux": { 19 | "x64": ["/Lib/Linux/libquickjs.a"] 20 | } 21 | }, 22 | "copy-libraries": { 23 | "win": { 24 | "ia32": ["/Lib/Win32/*.dll"], 25 | "x64": ["/Lib/Win64/*.dll"] 26 | }, 27 | "ios": { 28 | "arm64": ["/Lib/iOS/arm64/libquickjs.a"] 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /quickjs/_VERSION: -------------------------------------------------------------------------------- 1 | 2020-11-08 2 | -------------------------------------------------------------------------------- /quickjs/cutils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * C utilities 3 | * 4 | * Copyright (c) 2017 Fabrice Bellard 5 | * Copyright (c) 2018 Charlie Gordon 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "cutils.h" 31 | 32 | void pstrcpy(char *buf, int buf_size, const char *str) 33 | { 34 | int c; 35 | char *q = buf; 36 | 37 | if (buf_size <= 0) 38 | return; 39 | 40 | for(;;) { 41 | c = *str++; 42 | if (c == 0 || q >= buf + buf_size - 1) 43 | break; 44 | *q++ = c; 45 | } 46 | *q = '\0'; 47 | } 48 | 49 | /* strcat and truncate. */ 50 | char *pstrcat(char *buf, int buf_size, const char *s) 51 | { 52 | int len; 53 | len = strlen(buf); 54 | if (len < buf_size) 55 | pstrcpy(buf + len, buf_size - len, s); 56 | return buf; 57 | } 58 | 59 | int strstart(const char *str, const char *val, const char **ptr) 60 | { 61 | const char *p, *q; 62 | p = str; 63 | q = val; 64 | while (*q != '\0') { 65 | if (*p != *q) 66 | return 0; 67 | p++; 68 | q++; 69 | } 70 | if (ptr) 71 | *ptr = p; 72 | return 1; 73 | } 74 | 75 | int has_suffix(const char *str, const char *suffix) 76 | { 77 | size_t len = strlen(str); 78 | size_t slen = strlen(suffix); 79 | return (len >= slen && !memcmp(str + len - slen, suffix, slen)); 80 | } 81 | 82 | /* Dynamic buffer package */ 83 | 84 | static void *dbuf_default_realloc(void *opaque, void *ptr, size_t size) 85 | { 86 | return realloc(ptr, size); 87 | } 88 | 89 | void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func) 90 | { 91 | memset(s, 0, sizeof(*s)); 92 | if (!realloc_func) 93 | realloc_func = dbuf_default_realloc; 94 | s->opaque = opaque; 95 | s->realloc_func = realloc_func; 96 | } 97 | 98 | void dbuf_init(DynBuf *s) 99 | { 100 | dbuf_init2(s, NULL, NULL); 101 | } 102 | 103 | /* return < 0 if error */ 104 | int dbuf_realloc(DynBuf *s, size_t new_size) 105 | { 106 | size_t size; 107 | uint8_t *new_buf; 108 | if (new_size > s->allocated_size) { 109 | if (s->error) 110 | return -1; 111 | size = s->allocated_size * 3 / 2; 112 | if (size > new_size) 113 | new_size = size; 114 | new_buf = s->realloc_func(s->opaque, s->buf, new_size); 115 | if (!new_buf) { 116 | s->error = TRUE; 117 | return -1; 118 | } 119 | s->buf = new_buf; 120 | s->allocated_size = new_size; 121 | } 122 | return 0; 123 | } 124 | 125 | int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len) 126 | { 127 | size_t end; 128 | end = offset + len; 129 | if (dbuf_realloc(s, end)) 130 | return -1; 131 | memcpy(s->buf + offset, data, len); 132 | if (end > s->size) 133 | s->size = end; 134 | return 0; 135 | } 136 | 137 | int dbuf_put(DynBuf *s, const uint8_t *data, size_t len) 138 | { 139 | if (unlikely((s->size + len) > s->allocated_size)) { 140 | if (dbuf_realloc(s, s->size + len)) 141 | return -1; 142 | } 143 | memcpy_no_ub(s->buf + s->size, data, len); 144 | s->size += len; 145 | return 0; 146 | } 147 | 148 | int dbuf_put_self(DynBuf *s, size_t offset, size_t len) 149 | { 150 | if (unlikely((s->size + len) > s->allocated_size)) { 151 | if (dbuf_realloc(s, s->size + len)) 152 | return -1; 153 | } 154 | memcpy(s->buf + s->size, s->buf + offset, len); 155 | s->size += len; 156 | return 0; 157 | } 158 | 159 | int dbuf_putc(DynBuf *s, uint8_t c) 160 | { 161 | return dbuf_put(s, &c, 1); 162 | } 163 | 164 | int dbuf_putstr(DynBuf *s, const char *str) 165 | { 166 | return dbuf_put(s, (const uint8_t *)str, strlen(str)); 167 | } 168 | 169 | int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s, 170 | const char *fmt, ...) 171 | { 172 | va_list ap; 173 | char buf[128]; 174 | int len; 175 | 176 | va_start(ap, fmt); 177 | len = vsnprintf(buf, sizeof(buf), fmt, ap); 178 | va_end(ap); 179 | if (len < sizeof(buf)) { 180 | /* fast case */ 181 | return dbuf_put(s, (uint8_t *)buf, len); 182 | } else { 183 | if (dbuf_realloc(s, s->size + len + 1)) 184 | return -1; 185 | va_start(ap, fmt); 186 | vsnprintf((char *)(s->buf + s->size), s->allocated_size - s->size, 187 | fmt, ap); 188 | va_end(ap); 189 | s->size += len; 190 | } 191 | return 0; 192 | } 193 | 194 | void dbuf_free(DynBuf *s) 195 | { 196 | /* we test s->buf as a fail safe to avoid crashing if dbuf_free() 197 | is called twice */ 198 | if (s->buf) { 199 | s->realloc_func(s->opaque, s->buf, 0); 200 | } 201 | memset(s, 0, sizeof(*s)); 202 | } 203 | 204 | /* Note: at most 31 bits are encoded. At most UTF8_CHAR_LEN_MAX bytes 205 | are output. */ 206 | int unicode_to_utf8(uint8_t *buf, unsigned int c) 207 | { 208 | uint8_t *q = buf; 209 | 210 | if (c < 0x80) { 211 | *q++ = c; 212 | } else { 213 | if (c < 0x800) { 214 | *q++ = (c >> 6) | 0xc0; 215 | } else { 216 | if (c < 0x10000) { 217 | *q++ = (c >> 12) | 0xe0; 218 | } else { 219 | if (c < 0x00200000) { 220 | *q++ = (c >> 18) | 0xf0; 221 | } else { 222 | if (c < 0x04000000) { 223 | *q++ = (c >> 24) | 0xf8; 224 | } else if (c < 0x80000000) { 225 | *q++ = (c >> 30) | 0xfc; 226 | *q++ = ((c >> 24) & 0x3f) | 0x80; 227 | } else { 228 | return 0; 229 | } 230 | *q++ = ((c >> 18) & 0x3f) | 0x80; 231 | } 232 | *q++ = ((c >> 12) & 0x3f) | 0x80; 233 | } 234 | *q++ = ((c >> 6) & 0x3f) | 0x80; 235 | } 236 | *q++ = (c & 0x3f) | 0x80; 237 | } 238 | return q - buf; 239 | } 240 | 241 | static const unsigned int utf8_min_code[5] = { 242 | 0x80, 0x800, 0x10000, 0x00200000, 0x04000000, 243 | }; 244 | 245 | static const unsigned char utf8_first_code_mask[5] = { 246 | 0x1f, 0xf, 0x7, 0x3, 0x1, 247 | }; 248 | 249 | /* return -1 if error. *pp is not updated in this case. max_len must 250 | be >= 1. The maximum length for a UTF8 byte sequence is 6 bytes. */ 251 | int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp) 252 | { 253 | int l, c, b, i; 254 | 255 | c = *p++; 256 | if (c < 0x80) { 257 | *pp = p; 258 | return c; 259 | } 260 | switch(c) { 261 | case 0xc0: case 0xc1: case 0xc2: case 0xc3: 262 | case 0xc4: case 0xc5: case 0xc6: case 0xc7: 263 | case 0xc8: case 0xc9: case 0xca: case 0xcb: 264 | case 0xcc: case 0xcd: case 0xce: case 0xcf: 265 | case 0xd0: case 0xd1: case 0xd2: case 0xd3: 266 | case 0xd4: case 0xd5: case 0xd6: case 0xd7: 267 | case 0xd8: case 0xd9: case 0xda: case 0xdb: 268 | case 0xdc: case 0xdd: case 0xde: case 0xdf: 269 | l = 1; 270 | break; 271 | case 0xe0: case 0xe1: case 0xe2: case 0xe3: 272 | case 0xe4: case 0xe5: case 0xe6: case 0xe7: 273 | case 0xe8: case 0xe9: case 0xea: case 0xeb: 274 | case 0xec: case 0xed: case 0xee: case 0xef: 275 | l = 2; 276 | break; 277 | case 0xf0: case 0xf1: case 0xf2: case 0xf3: 278 | case 0xf4: case 0xf5: case 0xf6: case 0xf7: 279 | l = 3; 280 | break; 281 | case 0xf8: case 0xf9: case 0xfa: case 0xfb: 282 | l = 4; 283 | break; 284 | case 0xfc: case 0xfd: 285 | l = 5; 286 | break; 287 | default: 288 | return -1; 289 | } 290 | /* check that we have enough characters */ 291 | if (l > (max_len - 1)) 292 | return -1; 293 | c &= utf8_first_code_mask[l - 1]; 294 | for(i = 0; i < l; i++) { 295 | b = *p++; 296 | if (b < 0x80 || b >= 0xc0) 297 | return -1; 298 | c = (c << 6) | (b & 0x3f); 299 | } 300 | if (c < utf8_min_code[l - 1]) 301 | return -1; 302 | *pp = p; 303 | return c; 304 | } 305 | 306 | #if 0 307 | 308 | #if defined(EMSCRIPTEN) || defined(__ANDROID__) 309 | 310 | static void *rqsort_arg; 311 | static int (*rqsort_cmp)(const void *, const void *, void *); 312 | 313 | static int rqsort_cmp2(const void *p1, const void *p2) 314 | { 315 | return rqsort_cmp(p1, p2, rqsort_arg); 316 | } 317 | 318 | /* not reentrant, but not needed with emscripten */ 319 | void rqsort(void *base, size_t nmemb, size_t size, 320 | int (*cmp)(const void *, const void *, void *), 321 | void *arg) 322 | { 323 | rqsort_arg = arg; 324 | rqsort_cmp = cmp; 325 | qsort(base, nmemb, size, rqsort_cmp2); 326 | } 327 | 328 | #endif 329 | 330 | #else 331 | 332 | typedef void (*exchange_f)(void *a, void *b, size_t size); 333 | typedef int (*cmp_f)(const void *, const void *, void *opaque); 334 | 335 | static void exchange_bytes(void *a, void *b, size_t size) { 336 | uint8_t *ap = (uint8_t *)a; 337 | uint8_t *bp = (uint8_t *)b; 338 | 339 | while (size-- != 0) { 340 | uint8_t t = *ap; 341 | *ap++ = *bp; 342 | *bp++ = t; 343 | } 344 | } 345 | 346 | static void exchange_one_byte(void *a, void *b, size_t size) { 347 | uint8_t *ap = (uint8_t *)a; 348 | uint8_t *bp = (uint8_t *)b; 349 | uint8_t t = *ap; 350 | *ap = *bp; 351 | *bp = t; 352 | } 353 | 354 | static void exchange_int16s(void *a, void *b, size_t size) { 355 | uint16_t *ap = (uint16_t *)a; 356 | uint16_t *bp = (uint16_t *)b; 357 | 358 | for (size /= sizeof(uint16_t); size-- != 0;) { 359 | uint16_t t = *ap; 360 | *ap++ = *bp; 361 | *bp++ = t; 362 | } 363 | } 364 | 365 | static void exchange_one_int16(void *a, void *b, size_t size) { 366 | uint16_t *ap = (uint16_t *)a; 367 | uint16_t *bp = (uint16_t *)b; 368 | uint16_t t = *ap; 369 | *ap = *bp; 370 | *bp = t; 371 | } 372 | 373 | static void exchange_int32s(void *a, void *b, size_t size) { 374 | uint32_t *ap = (uint32_t *)a; 375 | uint32_t *bp = (uint32_t *)b; 376 | 377 | for (size /= sizeof(uint32_t); size-- != 0;) { 378 | uint32_t t = *ap; 379 | *ap++ = *bp; 380 | *bp++ = t; 381 | } 382 | } 383 | 384 | static void exchange_one_int32(void *a, void *b, size_t size) { 385 | uint32_t *ap = (uint32_t *)a; 386 | uint32_t *bp = (uint32_t *)b; 387 | uint32_t t = *ap; 388 | *ap = *bp; 389 | *bp = t; 390 | } 391 | 392 | static void exchange_int64s(void *a, void *b, size_t size) { 393 | uint64_t *ap = (uint64_t *)a; 394 | uint64_t *bp = (uint64_t *)b; 395 | 396 | for (size /= sizeof(uint64_t); size-- != 0;) { 397 | uint64_t t = *ap; 398 | *ap++ = *bp; 399 | *bp++ = t; 400 | } 401 | } 402 | 403 | static void exchange_one_int64(void *a, void *b, size_t size) { 404 | uint64_t *ap = (uint64_t *)a; 405 | uint64_t *bp = (uint64_t *)b; 406 | uint64_t t = *ap; 407 | *ap = *bp; 408 | *bp = t; 409 | } 410 | 411 | static void exchange_int128s(void *a, void *b, size_t size) { 412 | uint64_t *ap = (uint64_t *)a; 413 | uint64_t *bp = (uint64_t *)b; 414 | 415 | for (size /= sizeof(uint64_t) * 2; size-- != 0; ap += 2, bp += 2) { 416 | uint64_t t = ap[0]; 417 | uint64_t u = ap[1]; 418 | ap[0] = bp[0]; 419 | ap[1] = bp[1]; 420 | bp[0] = t; 421 | bp[1] = u; 422 | } 423 | } 424 | 425 | static void exchange_one_int128(void *a, void *b, size_t size) { 426 | uint64_t *ap = (uint64_t *)a; 427 | uint64_t *bp = (uint64_t *)b; 428 | uint64_t t = ap[0]; 429 | uint64_t u = ap[1]; 430 | ap[0] = bp[0]; 431 | ap[1] = bp[1]; 432 | bp[0] = t; 433 | bp[1] = u; 434 | } 435 | 436 | static inline exchange_f exchange_func(const void *base, size_t size) { 437 | switch (((uintptr_t)base | (uintptr_t)size) & 15) { 438 | case 0: 439 | if (size == sizeof(uint64_t) * 2) 440 | return exchange_one_int128; 441 | else 442 | return exchange_int128s; 443 | case 8: 444 | if (size == sizeof(uint64_t)) 445 | return exchange_one_int64; 446 | else 447 | return exchange_int64s; 448 | case 4: 449 | case 12: 450 | if (size == sizeof(uint32_t)) 451 | return exchange_one_int32; 452 | else 453 | return exchange_int32s; 454 | case 2: 455 | case 6: 456 | case 10: 457 | case 14: 458 | if (size == sizeof(uint16_t)) 459 | return exchange_one_int16; 460 | else 461 | return exchange_int16s; 462 | default: 463 | if (size == 1) 464 | return exchange_one_byte; 465 | else 466 | return exchange_bytes; 467 | } 468 | } 469 | 470 | static void heapsortx(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque) 471 | { 472 | uint8_t *basep = (uint8_t *)base; 473 | size_t i, n, c, r; 474 | exchange_f swap = exchange_func(base, size); 475 | 476 | if (nmemb > 1) { 477 | i = (nmemb / 2) * size; 478 | n = nmemb * size; 479 | 480 | while (i > 0) { 481 | i -= size; 482 | for (r = i; (c = r * 2 + size) < n; r = c) { 483 | if (c < n - size && cmp(basep + c, basep + c + size, opaque) <= 0) 484 | c += size; 485 | if (cmp(basep + r, basep + c, opaque) > 0) 486 | break; 487 | swap(basep + r, basep + c, size); 488 | } 489 | } 490 | for (i = n - size; i > 0; i -= size) { 491 | swap(basep, basep + i, size); 492 | 493 | for (r = 0; (c = r * 2 + size) < i; r = c) { 494 | if (c < i - size && cmp(basep + c, basep + c + size, opaque) <= 0) 495 | c += size; 496 | if (cmp(basep + r, basep + c, opaque) > 0) 497 | break; 498 | swap(basep + r, basep + c, size); 499 | } 500 | } 501 | } 502 | } 503 | 504 | static inline void *med3(void *a, void *b, void *c, cmp_f cmp, void *opaque) 505 | { 506 | return cmp(a, b, opaque) < 0 ? 507 | (cmp(b, c, opaque) < 0 ? b : (cmp(a, c, opaque) < 0 ? c : a )) : 508 | (cmp(b, c, opaque) > 0 ? b : (cmp(a, c, opaque) < 0 ? a : c )); 509 | } 510 | 511 | /* pointer based version with local stack and insertion sort threshhold */ 512 | void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque) 513 | { 514 | struct { uint8_t *base; size_t count; int depth; } stack[50], *sp = stack; 515 | uint8_t *ptr, *pi, *pj, *plt, *pgt, *top, *m; 516 | size_t m4, i, lt, gt, span, span2; 517 | int c, depth; 518 | exchange_f swap = exchange_func(base, size); 519 | exchange_f swap_block = exchange_func(base, size | 128); 520 | 521 | if (nmemb < 2 || size <= 0) 522 | return; 523 | 524 | sp->base = (uint8_t *)base; 525 | sp->count = nmemb; 526 | sp->depth = 0; 527 | sp++; 528 | 529 | while (sp > stack) { 530 | sp--; 531 | ptr = sp->base; 532 | nmemb = sp->count; 533 | depth = sp->depth; 534 | 535 | while (nmemb > 6) { 536 | if (++depth > 50) { 537 | /* depth check to ensure worst case logarithmic time */ 538 | heapsortx(ptr, nmemb, size, cmp, opaque); 539 | nmemb = 0; 540 | break; 541 | } 542 | /* select median of 3 from 1/4, 1/2, 3/4 positions */ 543 | /* should use median of 5 or 9? */ 544 | m4 = (nmemb >> 2) * size; 545 | m = med3(ptr + m4, ptr + 2 * m4, ptr + 3 * m4, cmp, opaque); 546 | swap(ptr, m, size); /* move the pivot to the start or the array */ 547 | i = lt = 1; 548 | pi = plt = ptr + size; 549 | gt = nmemb; 550 | pj = pgt = top = ptr + nmemb * size; 551 | for (;;) { 552 | while (pi < pj && (c = cmp(ptr, pi, opaque)) >= 0) { 553 | if (c == 0) { 554 | swap(plt, pi, size); 555 | lt++; 556 | plt += size; 557 | } 558 | i++; 559 | pi += size; 560 | } 561 | while (pi < (pj -= size) && (c = cmp(ptr, pj, opaque)) <= 0) { 562 | if (c == 0) { 563 | gt--; 564 | pgt -= size; 565 | swap(pgt, pj, size); 566 | } 567 | } 568 | if (pi >= pj) 569 | break; 570 | swap(pi, pj, size); 571 | i++; 572 | pi += size; 573 | } 574 | /* array has 4 parts: 575 | * from 0 to lt excluded: elements identical to pivot 576 | * from lt to pi excluded: elements smaller than pivot 577 | * from pi to gt excluded: elements greater than pivot 578 | * from gt to n excluded: elements identical to pivot 579 | */ 580 | /* move elements identical to pivot in the middle of the array: */ 581 | /* swap values in ranges [0..lt[ and [i-lt..i[ 582 | swapping the smallest span between lt and i-lt is sufficient 583 | */ 584 | span = plt - ptr; 585 | span2 = pi - plt; 586 | lt = i - lt; 587 | if (span > span2) 588 | span = span2; 589 | swap_block(ptr, pi - span, span); 590 | /* swap values in ranges [gt..top[ and [i..top-(top-gt)[ 591 | swapping the smallest span between top-gt and gt-i is sufficient 592 | */ 593 | span = top - pgt; 594 | span2 = pgt - pi; 595 | pgt = top - span2; 596 | gt = nmemb - (gt - i); 597 | if (span > span2) 598 | span = span2; 599 | swap_block(pi, top - span, span); 600 | 601 | /* now array has 3 parts: 602 | * from 0 to lt excluded: elements smaller than pivot 603 | * from lt to gt excluded: elements identical to pivot 604 | * from gt to n excluded: elements greater than pivot 605 | */ 606 | /* stack the larger segment and keep processing the smaller one 607 | to minimize stack use for pathological distributions */ 608 | if (lt > nmemb - gt) { 609 | sp->base = ptr; 610 | sp->count = lt; 611 | sp->depth = depth; 612 | sp++; 613 | ptr = pgt; 614 | nmemb -= gt; 615 | } else { 616 | sp->base = pgt; 617 | sp->count = nmemb - gt; 618 | sp->depth = depth; 619 | sp++; 620 | nmemb = lt; 621 | } 622 | } 623 | /* Use insertion sort for small fragments */ 624 | for (pi = ptr + size, top = ptr + nmemb * size; pi < top; pi += size) { 625 | for (pj = pi; pj > ptr && cmp(pj - size, pj, opaque) > 0; pj -= size) 626 | swap(pj, pj - size, size); 627 | } 628 | } 629 | } 630 | 631 | #endif 632 | -------------------------------------------------------------------------------- /quickjs/cutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * C utilities 3 | * 4 | * Copyright (c) 2017 Fabrice Bellard 5 | * Copyright (c) 2018 Charlie Gordon 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | #ifndef CUTILS_H 26 | #define CUTILS_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #define likely(x) __builtin_expect(!!(x), 1) 33 | #define unlikely(x) __builtin_expect(!!(x), 0) 34 | #define force_inline inline __attribute__((always_inline)) 35 | #define no_inline __attribute__((noinline)) 36 | #define __maybe_unused __attribute__((unused)) 37 | 38 | #define xglue(x, y) x ## y 39 | #define glue(x, y) xglue(x, y) 40 | #define stringify(s) tostring(s) 41 | #define tostring(s) #s 42 | 43 | #ifndef offsetof 44 | #define offsetof(type, field) ((size_t) &((type *)0)->field) 45 | #endif 46 | #ifndef countof 47 | #define countof(x) (sizeof(x) / sizeof((x)[0])) 48 | #endif 49 | #ifndef container_of 50 | /* return the pointer of type 'type *' containing 'ptr' as field 'member' */ 51 | #define container_of(ptr, type, member) ((type *)((uint8_t *)(ptr) - offsetof(type, member))) 52 | #endif 53 | 54 | #if !defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 55 | #define minimum_length(n) static n 56 | #else 57 | #define minimum_length(n) n 58 | #endif 59 | 60 | typedef int BOOL; 61 | 62 | #ifndef FALSE 63 | enum { 64 | FALSE = 0, 65 | TRUE = 1, 66 | }; 67 | #endif 68 | 69 | void pstrcpy(char *buf, int buf_size, const char *str); 70 | char *pstrcat(char *buf, int buf_size, const char *s); 71 | int strstart(const char *str, const char *val, const char **ptr); 72 | int has_suffix(const char *str, const char *suffix); 73 | 74 | /* Prevent UB when n == 0 and (src == NULL or dest == NULL) */ 75 | static inline void memcpy_no_ub(void *dest, const void *src, size_t n) { 76 | if (n) 77 | memcpy(dest, src, n); 78 | } 79 | 80 | static inline int max_int(int a, int b) 81 | { 82 | if (a > b) 83 | return a; 84 | else 85 | return b; 86 | } 87 | 88 | static inline int min_int(int a, int b) 89 | { 90 | if (a < b) 91 | return a; 92 | else 93 | return b; 94 | } 95 | 96 | static inline uint32_t max_uint32(uint32_t a, uint32_t b) 97 | { 98 | if (a > b) 99 | return a; 100 | else 101 | return b; 102 | } 103 | 104 | static inline uint32_t min_uint32(uint32_t a, uint32_t b) 105 | { 106 | if (a < b) 107 | return a; 108 | else 109 | return b; 110 | } 111 | 112 | static inline int64_t max_int64(int64_t a, int64_t b) 113 | { 114 | if (a > b) 115 | return a; 116 | else 117 | return b; 118 | } 119 | 120 | static inline int64_t min_int64(int64_t a, int64_t b) 121 | { 122 | if (a < b) 123 | return a; 124 | else 125 | return b; 126 | } 127 | 128 | /* WARNING: undefined if a = 0 */ 129 | static inline int clz32(unsigned int a) 130 | { 131 | return __builtin_clz(a); 132 | } 133 | 134 | /* WARNING: undefined if a = 0 */ 135 | static inline int clz64(uint64_t a) 136 | { 137 | return __builtin_clzll(a); 138 | } 139 | 140 | /* WARNING: undefined if a = 0 */ 141 | static inline int ctz32(unsigned int a) 142 | { 143 | return __builtin_ctz(a); 144 | } 145 | 146 | /* WARNING: undefined if a = 0 */ 147 | static inline int ctz64(uint64_t a) 148 | { 149 | return __builtin_ctzll(a); 150 | } 151 | 152 | struct __attribute__((packed)) packed_u64 { 153 | uint64_t v; 154 | }; 155 | 156 | struct __attribute__((packed)) packed_u32 { 157 | uint32_t v; 158 | }; 159 | 160 | struct __attribute__((packed)) packed_u16 { 161 | uint16_t v; 162 | }; 163 | 164 | static inline uint64_t get_u64(const uint8_t *tab) 165 | { 166 | return ((const struct packed_u64 *)tab)->v; 167 | } 168 | 169 | static inline int64_t get_i64(const uint8_t *tab) 170 | { 171 | return (int64_t)((const struct packed_u64 *)tab)->v; 172 | } 173 | 174 | static inline void put_u64(uint8_t *tab, uint64_t val) 175 | { 176 | ((struct packed_u64 *)tab)->v = val; 177 | } 178 | 179 | static inline uint32_t get_u32(const uint8_t *tab) 180 | { 181 | return ((const struct packed_u32 *)tab)->v; 182 | } 183 | 184 | static inline int32_t get_i32(const uint8_t *tab) 185 | { 186 | return (int32_t)((const struct packed_u32 *)tab)->v; 187 | } 188 | 189 | static inline void put_u32(uint8_t *tab, uint32_t val) 190 | { 191 | ((struct packed_u32 *)tab)->v = val; 192 | } 193 | 194 | static inline uint32_t get_u16(const uint8_t *tab) 195 | { 196 | return ((const struct packed_u16 *)tab)->v; 197 | } 198 | 199 | static inline int32_t get_i16(const uint8_t *tab) 200 | { 201 | return (int16_t)((const struct packed_u16 *)tab)->v; 202 | } 203 | 204 | static inline void put_u16(uint8_t *tab, uint16_t val) 205 | { 206 | ((struct packed_u16 *)tab)->v = val; 207 | } 208 | 209 | static inline uint32_t get_u8(const uint8_t *tab) 210 | { 211 | return *tab; 212 | } 213 | 214 | static inline int32_t get_i8(const uint8_t *tab) 215 | { 216 | return (int8_t)*tab; 217 | } 218 | 219 | static inline void put_u8(uint8_t *tab, uint8_t val) 220 | { 221 | *tab = val; 222 | } 223 | 224 | #ifndef bswap16 225 | static inline uint16_t bswap16(uint16_t x) 226 | { 227 | return (x >> 8) | (x << 8); 228 | } 229 | #endif 230 | 231 | #ifndef bswap32 232 | static inline uint32_t bswap32(uint32_t v) 233 | { 234 | return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) | 235 | ((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24); 236 | } 237 | #endif 238 | 239 | #ifndef bswap64 240 | static inline uint64_t bswap64(uint64_t v) 241 | { 242 | return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) | 243 | ((v & ((uint64_t)0xff << (6 * 8))) >> (5 * 8)) | 244 | ((v & ((uint64_t)0xff << (5 * 8))) >> (3 * 8)) | 245 | ((v & ((uint64_t)0xff << (4 * 8))) >> (1 * 8)) | 246 | ((v & ((uint64_t)0xff << (3 * 8))) << (1 * 8)) | 247 | ((v & ((uint64_t)0xff << (2 * 8))) << (3 * 8)) | 248 | ((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) | 249 | ((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8)); 250 | } 251 | #endif 252 | 253 | /* XXX: should take an extra argument to pass slack information to the caller */ 254 | typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size); 255 | 256 | typedef struct DynBuf { 257 | uint8_t *buf; 258 | size_t size; 259 | size_t allocated_size; 260 | BOOL error; /* true if a memory allocation error occurred */ 261 | DynBufReallocFunc *realloc_func; 262 | void *opaque; /* for realloc_func */ 263 | } DynBuf; 264 | 265 | void dbuf_init(DynBuf *s); 266 | void dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func); 267 | int dbuf_realloc(DynBuf *s, size_t new_size); 268 | int dbuf_write(DynBuf *s, size_t offset, const uint8_t *data, size_t len); 269 | int dbuf_put(DynBuf *s, const uint8_t *data, size_t len); 270 | int dbuf_put_self(DynBuf *s, size_t offset, size_t len); 271 | int dbuf_putc(DynBuf *s, uint8_t c); 272 | int dbuf_putstr(DynBuf *s, const char *str); 273 | static inline int dbuf_put_u16(DynBuf *s, uint16_t val) 274 | { 275 | return dbuf_put(s, (uint8_t *)&val, 2); 276 | } 277 | static inline int dbuf_put_u32(DynBuf *s, uint32_t val) 278 | { 279 | return dbuf_put(s, (uint8_t *)&val, 4); 280 | } 281 | static inline int dbuf_put_u64(DynBuf *s, uint64_t val) 282 | { 283 | return dbuf_put(s, (uint8_t *)&val, 8); 284 | } 285 | int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s, 286 | const char *fmt, ...); 287 | void dbuf_free(DynBuf *s); 288 | static inline BOOL dbuf_error(DynBuf *s) { 289 | return s->error; 290 | } 291 | static inline void dbuf_set_error(DynBuf *s) 292 | { 293 | s->error = TRUE; 294 | } 295 | 296 | #define UTF8_CHAR_LEN_MAX 6 297 | 298 | int unicode_to_utf8(uint8_t *buf, unsigned int c); 299 | int unicode_from_utf8(const uint8_t *p, int max_len, const uint8_t **pp); 300 | 301 | static inline BOOL is_surrogate(uint32_t c) 302 | { 303 | return (c >> 11) == (0xD800 >> 11); // 0xD800-0xDFFF 304 | } 305 | 306 | static inline BOOL is_hi_surrogate(uint32_t c) 307 | { 308 | return (c >> 10) == (0xD800 >> 10); // 0xD800-0xDBFF 309 | } 310 | 311 | static inline BOOL is_lo_surrogate(uint32_t c) 312 | { 313 | return (c >> 10) == (0xDC00 >> 10); // 0xDC00-0xDFFF 314 | } 315 | 316 | static inline uint32_t get_hi_surrogate(uint32_t c) 317 | { 318 | return (c >> 10) - (0x10000 >> 10) + 0xD800; 319 | } 320 | 321 | static inline uint32_t get_lo_surrogate(uint32_t c) 322 | { 323 | return (c & 0x3FF) | 0xDC00; 324 | } 325 | 326 | static inline uint32_t from_surrogate(uint32_t hi, uint32_t lo) 327 | { 328 | return 0x10000 + 0x400 * (hi - 0xD800) + (lo - 0xDC00); 329 | } 330 | 331 | static inline int from_hex(int c) 332 | { 333 | if (c >= '0' && c <= '9') 334 | return c - '0'; 335 | else if (c >= 'A' && c <= 'F') 336 | return c - 'A' + 10; 337 | else if (c >= 'a' && c <= 'f') 338 | return c - 'a' + 10; 339 | else 340 | return -1; 341 | } 342 | 343 | void rqsort(void *base, size_t nmemb, size_t size, 344 | int (*cmp)(const void *, const void *, void *), 345 | void *arg); 346 | 347 | #endif /* CUTILS_H */ 348 | -------------------------------------------------------------------------------- /quickjs/libbf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Tiny arbitrary precision floating point library 3 | * 4 | * Copyright (c) 2017-2021 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIBBF_H 25 | #define LIBBF_H 26 | 27 | #include 28 | #include 29 | 30 | #if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX) 31 | #define LIMB_LOG2_BITS 6 32 | #else 33 | #define LIMB_LOG2_BITS 5 34 | #endif 35 | 36 | #define LIMB_BITS (1 << LIMB_LOG2_BITS) 37 | 38 | #if LIMB_BITS == 64 39 | typedef __int128 int128_t; 40 | typedef unsigned __int128 uint128_t; 41 | typedef int64_t slimb_t; 42 | typedef uint64_t limb_t; 43 | typedef uint128_t dlimb_t; 44 | #define BF_RAW_EXP_MIN INT64_MIN 45 | #define BF_RAW_EXP_MAX INT64_MAX 46 | 47 | #define LIMB_DIGITS 19 48 | #define BF_DEC_BASE UINT64_C(10000000000000000000) 49 | 50 | #else 51 | 52 | typedef int32_t slimb_t; 53 | typedef uint32_t limb_t; 54 | typedef uint64_t dlimb_t; 55 | #define BF_RAW_EXP_MIN INT32_MIN 56 | #define BF_RAW_EXP_MAX INT32_MAX 57 | 58 | #define LIMB_DIGITS 9 59 | #define BF_DEC_BASE 1000000000U 60 | 61 | #endif 62 | 63 | /* in bits */ 64 | /* minimum number of bits for the exponent */ 65 | #define BF_EXP_BITS_MIN 3 66 | /* maximum number of bits for the exponent */ 67 | #define BF_EXP_BITS_MAX (LIMB_BITS - 3) 68 | /* extended range for exponent, used internally */ 69 | #define BF_EXT_EXP_BITS_MAX (BF_EXP_BITS_MAX + 1) 70 | /* minimum possible precision */ 71 | #define BF_PREC_MIN 2 72 | /* minimum possible precision */ 73 | #define BF_PREC_MAX (((limb_t)1 << (LIMB_BITS - 2)) - 2) 74 | /* some operations support infinite precision */ 75 | #define BF_PREC_INF (BF_PREC_MAX + 1) /* infinite precision */ 76 | 77 | #if LIMB_BITS == 64 78 | #define BF_CHKSUM_MOD (UINT64_C(975620677) * UINT64_C(9795002197)) 79 | #else 80 | #define BF_CHKSUM_MOD 975620677U 81 | #endif 82 | 83 | #define BF_EXP_ZERO BF_RAW_EXP_MIN 84 | #define BF_EXP_INF (BF_RAW_EXP_MAX - 1) 85 | #define BF_EXP_NAN BF_RAW_EXP_MAX 86 | 87 | /* +/-zero is represented with expn = BF_EXP_ZERO and len = 0, 88 | +/-infinity is represented with expn = BF_EXP_INF and len = 0, 89 | NaN is represented with expn = BF_EXP_NAN and len = 0 (sign is ignored) 90 | */ 91 | typedef struct { 92 | struct bf_context_t *ctx; 93 | int sign; 94 | slimb_t expn; 95 | limb_t len; 96 | limb_t *tab; 97 | } bf_t; 98 | 99 | typedef struct { 100 | /* must be kept identical to bf_t */ 101 | struct bf_context_t *ctx; 102 | int sign; 103 | slimb_t expn; 104 | limb_t len; 105 | limb_t *tab; 106 | } bfdec_t; 107 | 108 | typedef enum { 109 | BF_RNDN, /* round to nearest, ties to even */ 110 | BF_RNDZ, /* round to zero */ 111 | BF_RNDD, /* round to -inf (the code relies on (BF_RNDD xor BF_RNDU) = 1) */ 112 | BF_RNDU, /* round to +inf */ 113 | BF_RNDNA, /* round to nearest, ties away from zero */ 114 | BF_RNDA, /* round away from zero */ 115 | BF_RNDF, /* faithful rounding (nondeterministic, either RNDD or RNDU, 116 | inexact flag is always set) */ 117 | } bf_rnd_t; 118 | 119 | /* allow subnormal numbers. Only available if the number of exponent 120 | bits is <= BF_EXP_BITS_USER_MAX and prec != BF_PREC_INF. */ 121 | #define BF_FLAG_SUBNORMAL (1 << 3) 122 | /* 'prec' is the precision after the radix point instead of the whole 123 | mantissa. Can only be used with bf_round() and 124 | bfdec_[add|sub|mul|div|sqrt|round](). */ 125 | #define BF_FLAG_RADPNT_PREC (1 << 4) 126 | 127 | #define BF_RND_MASK 0x7 128 | #define BF_EXP_BITS_SHIFT 5 129 | #define BF_EXP_BITS_MASK 0x3f 130 | 131 | /* shortcut for bf_set_exp_bits(BF_EXT_EXP_BITS_MAX) */ 132 | #define BF_FLAG_EXT_EXP (BF_EXP_BITS_MASK << BF_EXP_BITS_SHIFT) 133 | 134 | /* contains the rounding mode and number of exponents bits */ 135 | typedef uint32_t bf_flags_t; 136 | 137 | typedef void *bf_realloc_func_t(void *opaque, void *ptr, size_t size); 138 | 139 | typedef struct { 140 | bf_t val; 141 | limb_t prec; 142 | } BFConstCache; 143 | 144 | typedef struct bf_context_t { 145 | void *realloc_opaque; 146 | bf_realloc_func_t *realloc_func; 147 | BFConstCache log2_cache; 148 | BFConstCache pi_cache; 149 | struct BFNTTState *ntt_state; 150 | } bf_context_t; 151 | 152 | static inline int bf_get_exp_bits(bf_flags_t flags) 153 | { 154 | int e; 155 | e = (flags >> BF_EXP_BITS_SHIFT) & BF_EXP_BITS_MASK; 156 | if (e == BF_EXP_BITS_MASK) 157 | return BF_EXP_BITS_MAX + 1; 158 | else 159 | return BF_EXP_BITS_MAX - e; 160 | } 161 | 162 | static inline bf_flags_t bf_set_exp_bits(int n) 163 | { 164 | return ((BF_EXP_BITS_MAX - n) & BF_EXP_BITS_MASK) << BF_EXP_BITS_SHIFT; 165 | } 166 | 167 | /* returned status */ 168 | #define BF_ST_INVALID_OP (1 << 0) 169 | #define BF_ST_DIVIDE_ZERO (1 << 1) 170 | #define BF_ST_OVERFLOW (1 << 2) 171 | #define BF_ST_UNDERFLOW (1 << 3) 172 | #define BF_ST_INEXACT (1 << 4) 173 | /* indicate that a memory allocation error occured. NaN is returned */ 174 | #define BF_ST_MEM_ERROR (1 << 5) 175 | 176 | #define BF_RADIX_MAX 36 /* maximum radix for bf_atof() and bf_ftoa() */ 177 | 178 | static inline slimb_t bf_max(slimb_t a, slimb_t b) 179 | { 180 | if (a > b) 181 | return a; 182 | else 183 | return b; 184 | } 185 | 186 | static inline slimb_t bf_min(slimb_t a, slimb_t b) 187 | { 188 | if (a < b) 189 | return a; 190 | else 191 | return b; 192 | } 193 | 194 | void bf_context_init(bf_context_t *s, bf_realloc_func_t *realloc_func, 195 | void *realloc_opaque); 196 | void bf_context_end(bf_context_t *s); 197 | /* free memory allocated for the bf cache data */ 198 | void bf_clear_cache(bf_context_t *s); 199 | 200 | static inline void *bf_realloc(bf_context_t *s, void *ptr, size_t size) 201 | { 202 | return s->realloc_func(s->realloc_opaque, ptr, size); 203 | } 204 | 205 | /* 'size' must be != 0 */ 206 | static inline void *bf_malloc(bf_context_t *s, size_t size) 207 | { 208 | return bf_realloc(s, NULL, size); 209 | } 210 | 211 | static inline void bf_free(bf_context_t *s, void *ptr) 212 | { 213 | /* must test ptr otherwise equivalent to malloc(0) */ 214 | if (ptr) 215 | bf_realloc(s, ptr, 0); 216 | } 217 | 218 | void bf_init(bf_context_t *s, bf_t *r); 219 | 220 | static inline void bf_delete(bf_t *r) 221 | { 222 | bf_context_t *s = r->ctx; 223 | /* we accept to delete a zeroed bf_t structure */ 224 | if (s && r->tab) { 225 | bf_realloc(s, r->tab, 0); 226 | } 227 | } 228 | 229 | static inline void bf_neg(bf_t *r) 230 | { 231 | r->sign ^= 1; 232 | } 233 | 234 | static inline int bf_is_finite(const bf_t *a) 235 | { 236 | return (a->expn < BF_EXP_INF); 237 | } 238 | 239 | static inline int bf_is_nan(const bf_t *a) 240 | { 241 | return (a->expn == BF_EXP_NAN); 242 | } 243 | 244 | static inline int bf_is_zero(const bf_t *a) 245 | { 246 | return (a->expn == BF_EXP_ZERO); 247 | } 248 | 249 | static inline void bf_memcpy(bf_t *r, const bf_t *a) 250 | { 251 | *r = *a; 252 | } 253 | 254 | int bf_set_ui(bf_t *r, uint64_t a); 255 | int bf_set_si(bf_t *r, int64_t a); 256 | void bf_set_nan(bf_t *r); 257 | void bf_set_zero(bf_t *r, int is_neg); 258 | void bf_set_inf(bf_t *r, int is_neg); 259 | int bf_set(bf_t *r, const bf_t *a); 260 | void bf_move(bf_t *r, bf_t *a); 261 | int bf_get_float64(const bf_t *a, double *pres, bf_rnd_t rnd_mode); 262 | int bf_set_float64(bf_t *a, double d); 263 | 264 | int bf_cmpu(const bf_t *a, const bf_t *b); 265 | int bf_cmp_full(const bf_t *a, const bf_t *b); 266 | int bf_cmp(const bf_t *a, const bf_t *b); 267 | static inline int bf_cmp_eq(const bf_t *a, const bf_t *b) 268 | { 269 | return bf_cmp(a, b) == 0; 270 | } 271 | 272 | static inline int bf_cmp_le(const bf_t *a, const bf_t *b) 273 | { 274 | return bf_cmp(a, b) <= 0; 275 | } 276 | 277 | static inline int bf_cmp_lt(const bf_t *a, const bf_t *b) 278 | { 279 | return bf_cmp(a, b) < 0; 280 | } 281 | 282 | int bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags); 283 | int bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags); 284 | int bf_add_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec, bf_flags_t flags); 285 | int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags); 286 | int bf_mul_ui(bf_t *r, const bf_t *a, uint64_t b1, limb_t prec, bf_flags_t flags); 287 | int bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec, 288 | bf_flags_t flags); 289 | int bf_mul_2exp(bf_t *r, slimb_t e, limb_t prec, bf_flags_t flags); 290 | int bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags); 291 | #define BF_DIVREM_EUCLIDIAN BF_RNDF 292 | int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b, 293 | limb_t prec, bf_flags_t flags, int rnd_mode); 294 | int bf_rem(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, 295 | bf_flags_t flags, int rnd_mode); 296 | int bf_remquo(slimb_t *pq, bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, 297 | bf_flags_t flags, int rnd_mode); 298 | /* round to integer with infinite precision */ 299 | int bf_rint(bf_t *r, int rnd_mode); 300 | int bf_round(bf_t *r, limb_t prec, bf_flags_t flags); 301 | int bf_sqrtrem(bf_t *r, bf_t *rem1, const bf_t *a); 302 | int bf_sqrt(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 303 | slimb_t bf_get_exp_min(const bf_t *a); 304 | int bf_logic_or(bf_t *r, const bf_t *a, const bf_t *b); 305 | int bf_logic_xor(bf_t *r, const bf_t *a, const bf_t *b); 306 | int bf_logic_and(bf_t *r, const bf_t *a, const bf_t *b); 307 | 308 | /* additional flags for bf_atof */ 309 | /* do not accept hex radix prefix (0x or 0X) if radix = 0 or radix = 16 */ 310 | #define BF_ATOF_NO_HEX (1 << 16) 311 | /* accept binary (0b or 0B) or octal (0o or 0O) radix prefix if radix = 0 */ 312 | #define BF_ATOF_BIN_OCT (1 << 17) 313 | /* Do not parse NaN or Inf */ 314 | #define BF_ATOF_NO_NAN_INF (1 << 18) 315 | /* return the exponent separately */ 316 | #define BF_ATOF_EXPONENT (1 << 19) 317 | 318 | int bf_atof(bf_t *a, const char *str, const char **pnext, int radix, 319 | limb_t prec, bf_flags_t flags); 320 | /* this version accepts prec = BF_PREC_INF and returns the radix 321 | exponent */ 322 | int bf_atof2(bf_t *r, slimb_t *pexponent, 323 | const char *str, const char **pnext, int radix, 324 | limb_t prec, bf_flags_t flags); 325 | int bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix, 326 | slimb_t expn, limb_t prec, bf_flags_t flags); 327 | 328 | 329 | /* Conversion of floating point number to string. Return a null 330 | terminated string or NULL if memory error. *plen contains its 331 | length if plen != NULL. The exponent letter is "e" for base 10, 332 | "p" for bases 2, 8, 16 with a binary exponent and "@" for the other 333 | bases. */ 334 | 335 | #define BF_FTOA_FORMAT_MASK (3 << 16) 336 | 337 | /* fixed format: prec significant digits rounded with (flags & 338 | BF_RND_MASK). Exponential notation is used if too many zeros are 339 | needed.*/ 340 | #define BF_FTOA_FORMAT_FIXED (0 << 16) 341 | /* fractional format: prec digits after the decimal point rounded with 342 | (flags & BF_RND_MASK) */ 343 | #define BF_FTOA_FORMAT_FRAC (1 << 16) 344 | /* free format: 345 | 346 | For binary radices with bf_ftoa() and for bfdec_ftoa(): use the minimum 347 | number of digits to represent 'a'. The precision and the rounding 348 | mode are ignored. 349 | 350 | For the non binary radices with bf_ftoa(): use as many digits as 351 | necessary so that bf_atof() return the same number when using 352 | precision 'prec', rounding to nearest and the subnormal 353 | configuration of 'flags'. The result is meaningful only if 'a' is 354 | already rounded to 'prec' bits. If the subnormal flag is set, the 355 | exponent in 'flags' must also be set to the desired exponent range. 356 | */ 357 | #define BF_FTOA_FORMAT_FREE (2 << 16) 358 | /* same as BF_FTOA_FORMAT_FREE but uses the minimum number of digits 359 | (takes more computation time). Identical to BF_FTOA_FORMAT_FREE for 360 | binary radices with bf_ftoa() and for bfdec_ftoa(). */ 361 | #define BF_FTOA_FORMAT_FREE_MIN (3 << 16) 362 | 363 | /* force exponential notation for fixed or free format */ 364 | #define BF_FTOA_FORCE_EXP (1 << 20) 365 | /* add 0x prefix for base 16, 0o prefix for base 8 or 0b prefix for 366 | base 2 if non zero value */ 367 | #define BF_FTOA_ADD_PREFIX (1 << 21) 368 | /* return "Infinity" instead of "Inf" and add a "+" for positive 369 | exponents */ 370 | #define BF_FTOA_JS_QUIRKS (1 << 22) 371 | 372 | char *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec, 373 | bf_flags_t flags); 374 | 375 | /* modulo 2^n instead of saturation. NaN and infinity return 0 */ 376 | #define BF_GET_INT_MOD (1 << 0) 377 | int bf_get_int32(int *pres, const bf_t *a, int flags); 378 | int bf_get_int64(int64_t *pres, const bf_t *a, int flags); 379 | int bf_get_uint64(uint64_t *pres, const bf_t *a); 380 | 381 | /* the following functions are exported for testing only. */ 382 | void mp_print_str(const char *str, const limb_t *tab, limb_t n); 383 | void bf_print_str(const char *str, const bf_t *a); 384 | int bf_resize(bf_t *r, limb_t len); 385 | int bf_get_fft_size(int *pdpl, int *pnb_mods, limb_t len); 386 | int bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags); 387 | int bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k); 388 | slimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv, 389 | int is_ceil1); 390 | int mp_mul(bf_context_t *s, limb_t *result, 391 | const limb_t *op1, limb_t op1_size, 392 | const limb_t *op2, limb_t op2_size); 393 | limb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2, 394 | limb_t n, limb_t carry); 395 | limb_t mp_add_ui(limb_t *tab, limb_t b, size_t n); 396 | int mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n); 397 | int mp_recip(bf_context_t *s, limb_t *tabr, const limb_t *taba, limb_t n); 398 | limb_t bf_isqrt(limb_t a); 399 | 400 | /* transcendental functions */ 401 | int bf_const_log2(bf_t *T, limb_t prec, bf_flags_t flags); 402 | int bf_const_pi(bf_t *T, limb_t prec, bf_flags_t flags); 403 | int bf_exp(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 404 | int bf_log(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 405 | #define BF_POW_JS_QUIRKS (1 << 16) /* (+/-1)^(+/-Inf) = NaN, 1^NaN = NaN */ 406 | int bf_pow(bf_t *r, const bf_t *x, const bf_t *y, limb_t prec, bf_flags_t flags); 407 | int bf_cos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 408 | int bf_sin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 409 | int bf_tan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 410 | int bf_atan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 411 | int bf_atan2(bf_t *r, const bf_t *y, const bf_t *x, 412 | limb_t prec, bf_flags_t flags); 413 | int bf_asin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 414 | int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); 415 | 416 | /* decimal floating point */ 417 | 418 | static inline void bfdec_init(bf_context_t *s, bfdec_t *r) 419 | { 420 | bf_init(s, (bf_t *)r); 421 | } 422 | static inline void bfdec_delete(bfdec_t *r) 423 | { 424 | bf_delete((bf_t *)r); 425 | } 426 | 427 | static inline void bfdec_neg(bfdec_t *r) 428 | { 429 | r->sign ^= 1; 430 | } 431 | 432 | static inline int bfdec_is_finite(const bfdec_t *a) 433 | { 434 | return (a->expn < BF_EXP_INF); 435 | } 436 | 437 | static inline int bfdec_is_nan(const bfdec_t *a) 438 | { 439 | return (a->expn == BF_EXP_NAN); 440 | } 441 | 442 | static inline int bfdec_is_zero(const bfdec_t *a) 443 | { 444 | return (a->expn == BF_EXP_ZERO); 445 | } 446 | 447 | static inline void bfdec_memcpy(bfdec_t *r, const bfdec_t *a) 448 | { 449 | bf_memcpy((bf_t *)r, (const bf_t *)a); 450 | } 451 | 452 | int bfdec_set_ui(bfdec_t *r, uint64_t a); 453 | int bfdec_set_si(bfdec_t *r, int64_t a); 454 | 455 | static inline void bfdec_set_nan(bfdec_t *r) 456 | { 457 | bf_set_nan((bf_t *)r); 458 | } 459 | static inline void bfdec_set_zero(bfdec_t *r, int is_neg) 460 | { 461 | bf_set_zero((bf_t *)r, is_neg); 462 | } 463 | static inline void bfdec_set_inf(bfdec_t *r, int is_neg) 464 | { 465 | bf_set_inf((bf_t *)r, is_neg); 466 | } 467 | static inline int bfdec_set(bfdec_t *r, const bfdec_t *a) 468 | { 469 | return bf_set((bf_t *)r, (bf_t *)a); 470 | } 471 | static inline void bfdec_move(bfdec_t *r, bfdec_t *a) 472 | { 473 | bf_move((bf_t *)r, (bf_t *)a); 474 | } 475 | static inline int bfdec_cmpu(const bfdec_t *a, const bfdec_t *b) 476 | { 477 | return bf_cmpu((const bf_t *)a, (const bf_t *)b); 478 | } 479 | static inline int bfdec_cmp_full(const bfdec_t *a, const bfdec_t *b) 480 | { 481 | return bf_cmp_full((const bf_t *)a, (const bf_t *)b); 482 | } 483 | static inline int bfdec_cmp(const bfdec_t *a, const bfdec_t *b) 484 | { 485 | return bf_cmp((const bf_t *)a, (const bf_t *)b); 486 | } 487 | static inline int bfdec_cmp_eq(const bfdec_t *a, const bfdec_t *b) 488 | { 489 | return bfdec_cmp(a, b) == 0; 490 | } 491 | static inline int bfdec_cmp_le(const bfdec_t *a, const bfdec_t *b) 492 | { 493 | return bfdec_cmp(a, b) <= 0; 494 | } 495 | static inline int bfdec_cmp_lt(const bfdec_t *a, const bfdec_t *b) 496 | { 497 | return bfdec_cmp(a, b) < 0; 498 | } 499 | 500 | int bfdec_add(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, 501 | bf_flags_t flags); 502 | int bfdec_sub(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, 503 | bf_flags_t flags); 504 | int bfdec_add_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec, 505 | bf_flags_t flags); 506 | int bfdec_mul(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, 507 | bf_flags_t flags); 508 | int bfdec_mul_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec, 509 | bf_flags_t flags); 510 | int bfdec_div(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, 511 | bf_flags_t flags); 512 | int bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t *b, 513 | limb_t prec, bf_flags_t flags, int rnd_mode); 514 | int bfdec_rem(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, 515 | bf_flags_t flags, int rnd_mode); 516 | int bfdec_rint(bfdec_t *r, int rnd_mode); 517 | int bfdec_sqrt(bfdec_t *r, const bfdec_t *a, limb_t prec, bf_flags_t flags); 518 | int bfdec_round(bfdec_t *r, limb_t prec, bf_flags_t flags); 519 | int bfdec_get_int32(int *pres, const bfdec_t *a); 520 | int bfdec_pow_ui(bfdec_t *r, const bfdec_t *a, limb_t b); 521 | 522 | char *bfdec_ftoa(size_t *plen, const bfdec_t *a, limb_t prec, bf_flags_t flags); 523 | int bfdec_atof(bfdec_t *r, const char *str, const char **pnext, 524 | limb_t prec, bf_flags_t flags); 525 | 526 | /* the following functions are exported for testing only. */ 527 | extern const limb_t mp_pow_dec[LIMB_DIGITS + 1]; 528 | void bfdec_print_str(const char *str, const bfdec_t *a); 529 | static inline int bfdec_resize(bfdec_t *r, limb_t len) 530 | { 531 | return bf_resize((bf_t *)r, len); 532 | } 533 | int bfdec_normalize_and_round(bfdec_t *r, limb_t prec1, bf_flags_t flags); 534 | 535 | #endif /* LIBBF_H */ 536 | -------------------------------------------------------------------------------- /quickjs/libregexp-opcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Regular Expression Engine 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | #ifdef DEF 26 | 27 | DEF(invalid, 1) /* never used */ 28 | DEF(char, 3) 29 | DEF(char32, 5) 30 | DEF(dot, 1) 31 | DEF(any, 1) /* same as dot but match any character including line terminator */ 32 | DEF(line_start, 1) 33 | DEF(line_end, 1) 34 | DEF(goto, 5) 35 | DEF(split_goto_first, 5) 36 | DEF(split_next_first, 5) 37 | DEF(match, 1) 38 | DEF(save_start, 2) /* save start position */ 39 | DEF(save_end, 2) /* save end position, must come after saved_start */ 40 | DEF(save_reset, 3) /* reset save positions */ 41 | DEF(loop, 5) /* decrement the top the stack and goto if != 0 */ 42 | DEF(push_i32, 5) /* push integer on the stack */ 43 | DEF(drop, 1) 44 | DEF(word_boundary, 1) 45 | DEF(not_word_boundary, 1) 46 | DEF(back_reference, 2) 47 | DEF(backward_back_reference, 2) /* must come after back_reference */ 48 | DEF(range, 3) /* variable length */ 49 | DEF(range32, 3) /* variable length */ 50 | DEF(lookahead, 5) 51 | DEF(negative_lookahead, 5) 52 | DEF(push_char_pos, 1) /* push the character position on the stack */ 53 | DEF(check_advance, 1) /* pop one stack element and check that it is different from the character position */ 54 | DEF(prev, 1) /* go to the previous char */ 55 | DEF(simple_greedy_quant, 17) 56 | 57 | #endif /* DEF */ 58 | -------------------------------------------------------------------------------- /quickjs/libregexp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Regular Expression Engine 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIBREGEXP_H 25 | #define LIBREGEXP_H 26 | 27 | #include 28 | 29 | #include "libunicode.h" 30 | 31 | #define LRE_BOOL int /* for documentation purposes */ 32 | 33 | #define LRE_FLAG_GLOBAL (1 << 0) 34 | #define LRE_FLAG_IGNORECASE (1 << 1) 35 | #define LRE_FLAG_MULTILINE (1 << 2) 36 | #define LRE_FLAG_DOTALL (1 << 3) 37 | #define LRE_FLAG_UNICODE (1 << 4) 38 | #define LRE_FLAG_STICKY (1 << 5) 39 | #define LRE_FLAG_INDICES (1 << 6) /* Unused by libregexp, just recorded. */ 40 | #define LRE_FLAG_NAMED_GROUPS (1 << 7) /* named groups are present in the regexp */ 41 | 42 | uint8_t *lre_compile(int *plen, char *error_msg, int error_msg_size, 43 | const char *buf, size_t buf_len, int re_flags, 44 | void *opaque); 45 | int lre_get_capture_count(const uint8_t *bc_buf); 46 | int lre_get_flags(const uint8_t *bc_buf); 47 | const char *lre_get_groupnames(const uint8_t *bc_buf); 48 | int lre_exec(uint8_t **capture, 49 | const uint8_t *bc_buf, const uint8_t *cbuf, int cindex, int clen, 50 | int cbuf_type, void *opaque); 51 | 52 | int lre_parse_escape(const uint8_t **pp, int allow_utf16); 53 | LRE_BOOL lre_is_space(int c); 54 | 55 | /* must be provided by the user */ 56 | LRE_BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size); 57 | void *lre_realloc(void *opaque, void *ptr, size_t size); 58 | 59 | /* JS identifier test */ 60 | extern uint32_t const lre_id_start_table_ascii[4]; 61 | extern uint32_t const lre_id_continue_table_ascii[4]; 62 | 63 | static inline int lre_js_is_ident_first(int c) 64 | { 65 | if ((uint32_t)c < 128) { 66 | return (lre_id_start_table_ascii[c >> 5] >> (c & 31)) & 1; 67 | } else { 68 | #ifdef CONFIG_ALL_UNICODE 69 | return lre_is_id_start(c); 70 | #else 71 | return !lre_is_space(c); 72 | #endif 73 | } 74 | } 75 | 76 | static inline int lre_js_is_ident_next(int c) 77 | { 78 | if ((uint32_t)c < 128) { 79 | return (lre_id_continue_table_ascii[c >> 5] >> (c & 31)) & 1; 80 | } else { 81 | /* ZWNJ and ZWJ are accepted in identifiers */ 82 | #ifdef CONFIG_ALL_UNICODE 83 | return lre_is_id_continue(c) || c == 0x200C || c == 0x200D; 84 | #else 85 | return !lre_is_space(c) || c == 0x200C || c == 0x200D; 86 | #endif 87 | } 88 | } 89 | 90 | #undef LRE_BOOL 91 | 92 | #endif /* LIBREGEXP_H */ 93 | -------------------------------------------------------------------------------- /quickjs/libunicode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Unicode utilities 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIBUNICODE_H 25 | #define LIBUNICODE_H 26 | 27 | #include 28 | 29 | #define LRE_BOOL int /* for documentation purposes */ 30 | 31 | /* define it to include all the unicode tables (40KB larger) */ 32 | #define CONFIG_ALL_UNICODE 33 | 34 | #define LRE_CC_RES_LEN_MAX 3 35 | 36 | typedef enum { 37 | UNICODE_NFC, 38 | UNICODE_NFD, 39 | UNICODE_NFKC, 40 | UNICODE_NFKD, 41 | } UnicodeNormalizationEnum; 42 | 43 | int lre_case_conv(uint32_t *res, uint32_t c, int conv_type); 44 | int lre_canonicalize(uint32_t c, LRE_BOOL is_unicode); 45 | LRE_BOOL lre_is_cased(uint32_t c); 46 | LRE_BOOL lre_is_case_ignorable(uint32_t c); 47 | 48 | /* char ranges */ 49 | 50 | typedef struct { 51 | int len; /* in points, always even */ 52 | int size; 53 | uint32_t *points; /* points sorted by increasing value */ 54 | void *mem_opaque; 55 | void *(*realloc_func)(void *opaque, void *ptr, size_t size); 56 | } CharRange; 57 | 58 | typedef enum { 59 | CR_OP_UNION, 60 | CR_OP_INTER, 61 | CR_OP_XOR, 62 | } CharRangeOpEnum; 63 | 64 | void cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size)); 65 | void cr_free(CharRange *cr); 66 | int cr_realloc(CharRange *cr, int size); 67 | int cr_copy(CharRange *cr, const CharRange *cr1); 68 | 69 | static inline int cr_add_point(CharRange *cr, uint32_t v) 70 | { 71 | if (cr->len >= cr->size) { 72 | if (cr_realloc(cr, cr->len + 1)) 73 | return -1; 74 | } 75 | cr->points[cr->len++] = v; 76 | return 0; 77 | } 78 | 79 | static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2) 80 | { 81 | if ((cr->len + 2) > cr->size) { 82 | if (cr_realloc(cr, cr->len + 2)) 83 | return -1; 84 | } 85 | cr->points[cr->len++] = c1; 86 | cr->points[cr->len++] = c2; 87 | return 0; 88 | } 89 | 90 | int cr_union1(CharRange *cr, const uint32_t *b_pt, int b_len); 91 | 92 | static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2) 93 | { 94 | uint32_t b_pt[2]; 95 | b_pt[0] = c1; 96 | b_pt[1] = c2 + 1; 97 | return cr_union1(cr, b_pt, 2); 98 | } 99 | 100 | int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len, 101 | const uint32_t *b_pt, int b_len, int op); 102 | 103 | int cr_invert(CharRange *cr); 104 | 105 | int cr_regexp_canonicalize(CharRange *cr, LRE_BOOL is_unicode); 106 | 107 | #ifdef CONFIG_ALL_UNICODE 108 | 109 | LRE_BOOL lre_is_id_start(uint32_t c); 110 | LRE_BOOL lre_is_id_continue(uint32_t c); 111 | 112 | int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len, 113 | UnicodeNormalizationEnum n_type, 114 | void *opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size)); 115 | 116 | /* Unicode character range functions */ 117 | 118 | int unicode_script(CharRange *cr, 119 | const char *script_name, LRE_BOOL is_ext); 120 | int unicode_general_category(CharRange *cr, const char *gc_name); 121 | int unicode_prop(CharRange *cr, const char *prop_name); 122 | 123 | #endif /* CONFIG_ALL_UNICODE */ 124 | 125 | #undef LRE_BOOL 126 | 127 | #endif /* LIBUNICODE_H */ 128 | -------------------------------------------------------------------------------- /quickjs/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Linux klist like system 3 | * 4 | * Copyright (c) 2016-2017 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef LIST_H 25 | #define LIST_H 26 | 27 | #ifndef NULL 28 | #include 29 | #endif 30 | 31 | struct list_head { 32 | struct list_head *prev; 33 | struct list_head *next; 34 | }; 35 | 36 | #define LIST_HEAD_INIT(el) { &(el), &(el) } 37 | 38 | /* return the pointer of type 'type *' containing 'el' as field 'member' */ 39 | #define list_entry(el, type, member) container_of(el, type, member) 40 | 41 | static inline void init_list_head(struct list_head *head) 42 | { 43 | head->prev = head; 44 | head->next = head; 45 | } 46 | 47 | /* insert 'el' between 'prev' and 'next' */ 48 | static inline void __list_add(struct list_head *el, 49 | struct list_head *prev, struct list_head *next) 50 | { 51 | prev->next = el; 52 | el->prev = prev; 53 | el->next = next; 54 | next->prev = el; 55 | } 56 | 57 | /* add 'el' at the head of the list 'head' (= after element head) */ 58 | static inline void list_add(struct list_head *el, struct list_head *head) 59 | { 60 | __list_add(el, head, head->next); 61 | } 62 | 63 | /* add 'el' at the end of the list 'head' (= before element head) */ 64 | static inline void list_add_tail(struct list_head *el, struct list_head *head) 65 | { 66 | __list_add(el, head->prev, head); 67 | } 68 | 69 | static inline void list_del(struct list_head *el) 70 | { 71 | struct list_head *prev, *next; 72 | prev = el->prev; 73 | next = el->next; 74 | prev->next = next; 75 | next->prev = prev; 76 | el->prev = NULL; /* fail safe */ 77 | el->next = NULL; /* fail safe */ 78 | } 79 | 80 | static inline int list_empty(struct list_head *el) 81 | { 82 | return el->next == el; 83 | } 84 | 85 | #define list_for_each(el, head) \ 86 | for(el = (head)->next; el != (head); el = el->next) 87 | 88 | #define list_for_each_safe(el, el1, head) \ 89 | for(el = (head)->next, el1 = el->next; el != (head); \ 90 | el = el1, el1 = el->next) 91 | 92 | #define list_for_each_prev(el, head) \ 93 | for(el = (head)->prev; el != (head); el = el->prev) 94 | 95 | #define list_for_each_prev_safe(el, el1, head) \ 96 | for(el = (head)->prev, el1 = el->prev; el != (head); \ 97 | el = el1, el1 = el->prev) 98 | 99 | #endif /* LIST_H */ 100 | -------------------------------------------------------------------------------- /quickjs/quickjs-atom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS atom definitions 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * Copyright (c) 2017-2018 Charlie Gordon 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | #ifdef DEF 27 | 28 | /* Note: first atoms are considered as keywords in the parser */ 29 | DEF(null, "null") /* must be first */ 30 | DEF(false, "false") 31 | DEF(true, "true") 32 | DEF(if, "if") 33 | DEF(else, "else") 34 | DEF(return, "return") 35 | DEF(var, "var") 36 | DEF(this, "this") 37 | DEF(delete, "delete") 38 | DEF(void, "void") 39 | DEF(typeof, "typeof") 40 | DEF(new, "new") 41 | DEF(in, "in") 42 | DEF(instanceof, "instanceof") 43 | DEF(do, "do") 44 | DEF(while, "while") 45 | DEF(for, "for") 46 | DEF(break, "break") 47 | DEF(continue, "continue") 48 | DEF(switch, "switch") 49 | DEF(case, "case") 50 | DEF(default, "default") 51 | DEF(throw, "throw") 52 | DEF(try, "try") 53 | DEF(catch, "catch") 54 | DEF(finally, "finally") 55 | DEF(function, "function") 56 | DEF(debugger, "debugger") 57 | DEF(with, "with") 58 | /* FutureReservedWord */ 59 | DEF(class, "class") 60 | DEF(const, "const") 61 | DEF(enum, "enum") 62 | DEF(export, "export") 63 | DEF(extends, "extends") 64 | DEF(import, "import") 65 | DEF(super, "super") 66 | /* FutureReservedWords when parsing strict mode code */ 67 | DEF(implements, "implements") 68 | DEF(interface, "interface") 69 | DEF(let, "let") 70 | DEF(package, "package") 71 | DEF(private, "private") 72 | DEF(protected, "protected") 73 | DEF(public, "public") 74 | DEF(static, "static") 75 | DEF(yield, "yield") 76 | DEF(await, "await") 77 | 78 | /* empty string */ 79 | DEF(empty_string, "") 80 | /* identifiers */ 81 | DEF(length, "length") 82 | DEF(fileName, "fileName") 83 | DEF(lineNumber, "lineNumber") 84 | DEF(message, "message") 85 | DEF(cause, "cause") 86 | DEF(errors, "errors") 87 | DEF(stack, "stack") 88 | DEF(name, "name") 89 | DEF(toString, "toString") 90 | DEF(toLocaleString, "toLocaleString") 91 | DEF(valueOf, "valueOf") 92 | DEF(eval, "eval") 93 | DEF(prototype, "prototype") 94 | DEF(constructor, "constructor") 95 | DEF(configurable, "configurable") 96 | DEF(writable, "writable") 97 | DEF(enumerable, "enumerable") 98 | DEF(value, "value") 99 | DEF(get, "get") 100 | DEF(set, "set") 101 | DEF(of, "of") 102 | DEF(__proto__, "__proto__") 103 | DEF(undefined, "undefined") 104 | DEF(number, "number") 105 | DEF(boolean, "boolean") 106 | DEF(string, "string") 107 | DEF(object, "object") 108 | DEF(symbol, "symbol") 109 | DEF(integer, "integer") 110 | DEF(unknown, "unknown") 111 | DEF(arguments, "arguments") 112 | DEF(callee, "callee") 113 | DEF(caller, "caller") 114 | DEF(_eval_, "") 115 | DEF(_ret_, "") 116 | DEF(_var_, "") 117 | DEF(_arg_var_, "") 118 | DEF(_with_, "") 119 | DEF(lastIndex, "lastIndex") 120 | DEF(target, "target") 121 | DEF(index, "index") 122 | DEF(input, "input") 123 | DEF(defineProperties, "defineProperties") 124 | DEF(apply, "apply") 125 | DEF(join, "join") 126 | DEF(concat, "concat") 127 | DEF(split, "split") 128 | DEF(construct, "construct") 129 | DEF(getPrototypeOf, "getPrototypeOf") 130 | DEF(setPrototypeOf, "setPrototypeOf") 131 | DEF(isExtensible, "isExtensible") 132 | DEF(preventExtensions, "preventExtensions") 133 | DEF(has, "has") 134 | DEF(deleteProperty, "deleteProperty") 135 | DEF(defineProperty, "defineProperty") 136 | DEF(getOwnPropertyDescriptor, "getOwnPropertyDescriptor") 137 | DEF(ownKeys, "ownKeys") 138 | DEF(add, "add") 139 | DEF(done, "done") 140 | DEF(next, "next") 141 | DEF(values, "values") 142 | DEF(source, "source") 143 | DEF(flags, "flags") 144 | DEF(global, "global") 145 | DEF(unicode, "unicode") 146 | DEF(raw, "raw") 147 | DEF(new_target, "new.target") 148 | DEF(this_active_func, "this.active_func") 149 | DEF(home_object, "") 150 | DEF(computed_field, "") 151 | DEF(static_computed_field, "") /* must come after computed_fields */ 152 | DEF(class_fields_init, "") 153 | DEF(brand, "") 154 | DEF(hash_constructor, "#constructor") 155 | DEF(as, "as") 156 | DEF(from, "from") 157 | DEF(meta, "meta") 158 | DEF(_default_, "*default*") 159 | DEF(_star_, "*") 160 | DEF(Module, "Module") 161 | DEF(then, "then") 162 | DEF(resolve, "resolve") 163 | DEF(reject, "reject") 164 | DEF(promise, "promise") 165 | DEF(proxy, "proxy") 166 | DEF(revoke, "revoke") 167 | DEF(async, "async") 168 | DEF(exec, "exec") 169 | DEF(groups, "groups") 170 | DEF(indices, "indices") 171 | DEF(status, "status") 172 | DEF(reason, "reason") 173 | DEF(globalThis, "globalThis") 174 | DEF(bigint, "bigint") 175 | #ifdef CONFIG_BIGNUM 176 | DEF(bigfloat, "bigfloat") 177 | DEF(bigdecimal, "bigdecimal") 178 | DEF(roundingMode, "roundingMode") 179 | DEF(maximumSignificantDigits, "maximumSignificantDigits") 180 | DEF(maximumFractionDigits, "maximumFractionDigits") 181 | #endif 182 | /* the following 3 atoms are only used with CONFIG_ATOMICS */ 183 | DEF(not_equal, "not-equal") 184 | DEF(timed_out, "timed-out") 185 | DEF(ok, "ok") 186 | /* */ 187 | DEF(toJSON, "toJSON") 188 | /* class names */ 189 | DEF(Object, "Object") 190 | DEF(Array, "Array") 191 | DEF(Error, "Error") 192 | DEF(Number, "Number") 193 | DEF(String, "String") 194 | DEF(Boolean, "Boolean") 195 | DEF(Symbol, "Symbol") 196 | DEF(Arguments, "Arguments") 197 | DEF(Math, "Math") 198 | DEF(JSON, "JSON") 199 | DEF(Date, "Date") 200 | DEF(Function, "Function") 201 | DEF(GeneratorFunction, "GeneratorFunction") 202 | DEF(ForInIterator, "ForInIterator") 203 | DEF(RegExp, "RegExp") 204 | DEF(ArrayBuffer, "ArrayBuffer") 205 | DEF(SharedArrayBuffer, "SharedArrayBuffer") 206 | /* must keep same order as class IDs for typed arrays */ 207 | DEF(Uint8ClampedArray, "Uint8ClampedArray") 208 | DEF(Int8Array, "Int8Array") 209 | DEF(Uint8Array, "Uint8Array") 210 | DEF(Int16Array, "Int16Array") 211 | DEF(Uint16Array, "Uint16Array") 212 | DEF(Int32Array, "Int32Array") 213 | DEF(Uint32Array, "Uint32Array") 214 | DEF(BigInt64Array, "BigInt64Array") 215 | DEF(BigUint64Array, "BigUint64Array") 216 | DEF(Float32Array, "Float32Array") 217 | DEF(Float64Array, "Float64Array") 218 | DEF(DataView, "DataView") 219 | DEF(BigInt, "BigInt") 220 | #ifdef CONFIG_BIGNUM 221 | DEF(BigFloat, "BigFloat") 222 | DEF(BigFloatEnv, "BigFloatEnv") 223 | DEF(BigDecimal, "BigDecimal") 224 | DEF(OperatorSet, "OperatorSet") 225 | DEF(Operators, "Operators") 226 | #endif 227 | DEF(Map, "Map") 228 | DEF(Set, "Set") /* Map + 1 */ 229 | DEF(WeakMap, "WeakMap") /* Map + 2 */ 230 | DEF(WeakSet, "WeakSet") /* Map + 3 */ 231 | DEF(Map_Iterator, "Map Iterator") 232 | DEF(Set_Iterator, "Set Iterator") 233 | DEF(Array_Iterator, "Array Iterator") 234 | DEF(String_Iterator, "String Iterator") 235 | DEF(RegExp_String_Iterator, "RegExp String Iterator") 236 | DEF(Generator, "Generator") 237 | DEF(Proxy, "Proxy") 238 | DEF(Promise, "Promise") 239 | DEF(PromiseResolveFunction, "PromiseResolveFunction") 240 | DEF(PromiseRejectFunction, "PromiseRejectFunction") 241 | DEF(AsyncFunction, "AsyncFunction") 242 | DEF(AsyncFunctionResolve, "AsyncFunctionResolve") 243 | DEF(AsyncFunctionReject, "AsyncFunctionReject") 244 | DEF(AsyncGeneratorFunction, "AsyncGeneratorFunction") 245 | DEF(AsyncGenerator, "AsyncGenerator") 246 | DEF(EvalError, "EvalError") 247 | DEF(RangeError, "RangeError") 248 | DEF(ReferenceError, "ReferenceError") 249 | DEF(SyntaxError, "SyntaxError") 250 | DEF(TypeError, "TypeError") 251 | DEF(URIError, "URIError") 252 | DEF(InternalError, "InternalError") 253 | /* private symbols */ 254 | DEF(Private_brand, "") 255 | /* symbols */ 256 | DEF(Symbol_toPrimitive, "Symbol.toPrimitive") 257 | DEF(Symbol_iterator, "Symbol.iterator") 258 | DEF(Symbol_match, "Symbol.match") 259 | DEF(Symbol_matchAll, "Symbol.matchAll") 260 | DEF(Symbol_replace, "Symbol.replace") 261 | DEF(Symbol_search, "Symbol.search") 262 | DEF(Symbol_split, "Symbol.split") 263 | DEF(Symbol_toStringTag, "Symbol.toStringTag") 264 | DEF(Symbol_isConcatSpreadable, "Symbol.isConcatSpreadable") 265 | DEF(Symbol_hasInstance, "Symbol.hasInstance") 266 | DEF(Symbol_species, "Symbol.species") 267 | DEF(Symbol_unscopables, "Symbol.unscopables") 268 | DEF(Symbol_asyncIterator, "Symbol.asyncIterator") 269 | #ifdef CONFIG_BIGNUM 270 | DEF(Symbol_operatorSet, "Symbol.operatorSet") 271 | #endif 272 | 273 | #endif /* DEF */ 274 | -------------------------------------------------------------------------------- /quickjs/quickjs-opcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS opcode definitions 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * Copyright (c) 2017-2018 Charlie Gordon 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | #ifdef FMT 27 | FMT(none) 28 | FMT(none_int) 29 | FMT(none_loc) 30 | FMT(none_arg) 31 | FMT(none_var_ref) 32 | FMT(u8) 33 | FMT(i8) 34 | FMT(loc8) 35 | FMT(const8) 36 | FMT(label8) 37 | FMT(u16) 38 | FMT(i16) 39 | FMT(label16) 40 | FMT(npop) 41 | FMT(npopx) 42 | FMT(npop_u16) 43 | FMT(loc) 44 | FMT(arg) 45 | FMT(var_ref) 46 | FMT(u32) 47 | FMT(i32) 48 | FMT(const) 49 | FMT(label) 50 | FMT(atom) 51 | FMT(atom_u8) 52 | FMT(atom_u16) 53 | FMT(atom_label_u8) 54 | FMT(atom_label_u16) 55 | FMT(label_u16) 56 | #undef FMT 57 | #endif /* FMT */ 58 | 59 | #ifdef DEF 60 | 61 | #ifndef def 62 | #define def(id, size, n_pop, n_push, f) DEF(id, size, n_pop, n_push, f) 63 | #endif 64 | 65 | DEF(invalid, 1, 0, 0, none) /* never emitted */ 66 | 67 | /* push values */ 68 | DEF( push_i32, 5, 0, 1, i32) 69 | DEF( push_const, 5, 0, 1, const) 70 | DEF( fclosure, 5, 0, 1, const) /* must follow push_const */ 71 | DEF(push_atom_value, 5, 0, 1, atom) 72 | DEF( private_symbol, 5, 0, 1, atom) 73 | DEF( undefined, 1, 0, 1, none) 74 | DEF( null, 1, 0, 1, none) 75 | DEF( push_this, 1, 0, 1, none) /* only used at the start of a function */ 76 | DEF( push_false, 1, 0, 1, none) 77 | DEF( push_true, 1, 0, 1, none) 78 | DEF( object, 1, 0, 1, none) 79 | DEF( special_object, 2, 0, 1, u8) /* only used at the start of a function */ 80 | DEF( rest, 3, 0, 1, u16) /* only used at the start of a function */ 81 | 82 | DEF( drop, 1, 1, 0, none) /* a -> */ 83 | DEF( nip, 1, 2, 1, none) /* a b -> b */ 84 | DEF( nip1, 1, 3, 2, none) /* a b c -> b c */ 85 | DEF( dup, 1, 1, 2, none) /* a -> a a */ 86 | DEF( dup1, 1, 2, 3, none) /* a b -> a a b */ 87 | DEF( dup2, 1, 2, 4, none) /* a b -> a b a b */ 88 | DEF( dup3, 1, 3, 6, none) /* a b c -> a b c a b c */ 89 | DEF( insert2, 1, 2, 3, none) /* obj a -> a obj a (dup_x1) */ 90 | DEF( insert3, 1, 3, 4, none) /* obj prop a -> a obj prop a (dup_x2) */ 91 | DEF( insert4, 1, 4, 5, none) /* this obj prop a -> a this obj prop a */ 92 | DEF( perm3, 1, 3, 3, none) /* obj a b -> a obj b */ 93 | DEF( perm4, 1, 4, 4, none) /* obj prop a b -> a obj prop b */ 94 | DEF( perm5, 1, 5, 5, none) /* this obj prop a b -> a this obj prop b */ 95 | DEF( swap, 1, 2, 2, none) /* a b -> b a */ 96 | DEF( swap2, 1, 4, 4, none) /* a b c d -> c d a b */ 97 | DEF( rot3l, 1, 3, 3, none) /* x a b -> a b x */ 98 | DEF( rot3r, 1, 3, 3, none) /* a b x -> x a b */ 99 | DEF( rot4l, 1, 4, 4, none) /* x a b c -> a b c x */ 100 | DEF( rot5l, 1, 5, 5, none) /* x a b c d -> a b c d x */ 101 | 102 | DEF(call_constructor, 3, 2, 1, npop) /* func new.target args -> ret. arguments are not counted in n_pop */ 103 | DEF( call, 3, 1, 1, npop) /* arguments are not counted in n_pop */ 104 | DEF( tail_call, 3, 1, 0, npop) /* arguments are not counted in n_pop */ 105 | DEF( call_method, 3, 2, 1, npop) /* arguments are not counted in n_pop */ 106 | DEF(tail_call_method, 3, 2, 0, npop) /* arguments are not counted in n_pop */ 107 | DEF( array_from, 3, 0, 1, npop) /* arguments are not counted in n_pop */ 108 | DEF( apply, 3, 3, 1, u16) 109 | DEF( return, 1, 1, 0, none) 110 | DEF( return_undef, 1, 0, 0, none) 111 | DEF(check_ctor_return, 1, 1, 2, none) 112 | DEF( check_ctor, 1, 0, 0, none) 113 | DEF( check_brand, 1, 2, 2, none) /* this_obj func -> this_obj func */ 114 | DEF( add_brand, 1, 2, 0, none) /* this_obj home_obj -> */ 115 | DEF( return_async, 1, 1, 0, none) 116 | DEF( throw, 1, 1, 0, none) 117 | DEF( throw_error, 6, 0, 0, atom_u8) 118 | DEF( eval, 5, 1, 1, npop_u16) /* func args... -> ret_val */ 119 | DEF( apply_eval, 3, 2, 1, u16) /* func array -> ret_eval */ 120 | DEF( regexp, 1, 2, 1, none) /* create a RegExp object from the pattern and a 121 | bytecode string */ 122 | DEF( get_super, 1, 1, 1, none) 123 | DEF( import, 1, 1, 1, none) /* dynamic module import */ 124 | 125 | DEF( check_var, 5, 0, 1, atom) /* check if a variable exists */ 126 | DEF( get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */ 127 | DEF( get_var, 5, 0, 1, atom) /* throw an exception if the variable does not exist */ 128 | DEF( put_var, 5, 1, 0, atom) /* must come after get_var */ 129 | DEF( put_var_init, 5, 1, 0, atom) /* must come after put_var. Used to initialize a global lexical variable */ 130 | DEF( put_var_strict, 5, 2, 0, atom) /* for strict mode variable write */ 131 | 132 | DEF( get_ref_value, 1, 2, 3, none) 133 | DEF( put_ref_value, 1, 3, 0, none) 134 | 135 | DEF( define_var, 6, 0, 0, atom_u8) 136 | DEF(check_define_var, 6, 0, 0, atom_u8) 137 | DEF( define_func, 6, 1, 0, atom_u8) 138 | DEF( get_field, 5, 1, 1, atom) 139 | DEF( get_field2, 5, 1, 2, atom) 140 | DEF( put_field, 5, 2, 0, atom) 141 | DEF( get_private_field, 1, 2, 1, none) /* obj prop -> value */ 142 | DEF( put_private_field, 1, 3, 0, none) /* obj value prop -> */ 143 | DEF(define_private_field, 1, 3, 1, none) /* obj prop value -> obj */ 144 | DEF( get_array_el, 1, 2, 1, none) 145 | DEF( get_array_el2, 1, 2, 2, none) /* obj prop -> obj value */ 146 | DEF( put_array_el, 1, 3, 0, none) 147 | DEF(get_super_value, 1, 3, 1, none) /* this obj prop -> value */ 148 | DEF(put_super_value, 1, 4, 0, none) /* this obj prop value -> */ 149 | DEF( define_field, 5, 2, 1, atom) 150 | DEF( set_name, 5, 1, 1, atom) 151 | DEF(set_name_computed, 1, 2, 2, none) 152 | DEF( set_proto, 1, 2, 1, none) 153 | DEF(set_home_object, 1, 2, 2, none) 154 | DEF(define_array_el, 1, 3, 2, none) 155 | DEF( append, 1, 3, 2, none) /* append enumerated object, update length */ 156 | DEF(copy_data_properties, 2, 3, 3, u8) 157 | DEF( define_method, 6, 2, 1, atom_u8) 158 | DEF(define_method_computed, 2, 3, 1, u8) /* must come after define_method */ 159 | DEF( define_class, 6, 2, 2, atom_u8) /* parent ctor -> ctor proto */ 160 | DEF( define_class_computed, 6, 3, 3, atom_u8) /* field_name parent ctor -> field_name ctor proto (class with computed name) */ 161 | 162 | DEF( get_loc, 3, 0, 1, loc) 163 | DEF( put_loc, 3, 1, 0, loc) /* must come after get_loc */ 164 | DEF( set_loc, 3, 1, 1, loc) /* must come after put_loc */ 165 | DEF( get_arg, 3, 0, 1, arg) 166 | DEF( put_arg, 3, 1, 0, arg) /* must come after get_arg */ 167 | DEF( set_arg, 3, 1, 1, arg) /* must come after put_arg */ 168 | DEF( get_var_ref, 3, 0, 1, var_ref) 169 | DEF( put_var_ref, 3, 1, 0, var_ref) /* must come after get_var_ref */ 170 | DEF( set_var_ref, 3, 1, 1, var_ref) /* must come after put_var_ref */ 171 | DEF(set_loc_uninitialized, 3, 0, 0, loc) 172 | DEF( get_loc_check, 3, 0, 1, loc) 173 | DEF( put_loc_check, 3, 1, 0, loc) /* must come after get_loc_check */ 174 | DEF( put_loc_check_init, 3, 1, 0, loc) 175 | DEF(get_loc_checkthis, 3, 0, 1, loc) 176 | DEF(get_var_ref_check, 3, 0, 1, var_ref) 177 | DEF(put_var_ref_check, 3, 1, 0, var_ref) /* must come after get_var_ref_check */ 178 | DEF(put_var_ref_check_init, 3, 1, 0, var_ref) 179 | DEF( close_loc, 3, 0, 0, loc) 180 | DEF( if_false, 5, 1, 0, label) 181 | DEF( if_true, 5, 1, 0, label) /* must come after if_false */ 182 | DEF( goto, 5, 0, 0, label) /* must come after if_true */ 183 | DEF( catch, 5, 0, 1, label) 184 | DEF( gosub, 5, 0, 0, label) /* used to execute the finally block */ 185 | DEF( ret, 1, 1, 0, none) /* used to return from the finally block */ 186 | DEF( nip_catch, 1, 2, 1, none) /* catch ... a -> a */ 187 | 188 | DEF( to_object, 1, 1, 1, none) 189 | //DEF( to_string, 1, 1, 1, none) 190 | DEF( to_propkey, 1, 1, 1, none) 191 | DEF( to_propkey2, 1, 2, 2, none) 192 | 193 | DEF( with_get_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */ 194 | DEF( with_put_var, 10, 2, 1, atom_label_u8) /* must be in the same order as scope_xxx */ 195 | DEF(with_delete_var, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */ 196 | DEF( with_make_ref, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */ 197 | DEF( with_get_ref, 10, 1, 0, atom_label_u8) /* must be in the same order as scope_xxx */ 198 | DEF(with_get_ref_undef, 10, 1, 0, atom_label_u8) 199 | 200 | DEF( make_loc_ref, 7, 0, 2, atom_u16) 201 | DEF( make_arg_ref, 7, 0, 2, atom_u16) 202 | DEF(make_var_ref_ref, 7, 0, 2, atom_u16) 203 | DEF( make_var_ref, 5, 0, 2, atom) 204 | 205 | DEF( for_in_start, 1, 1, 1, none) 206 | DEF( for_of_start, 1, 1, 3, none) 207 | DEF(for_await_of_start, 1, 1, 3, none) 208 | DEF( for_in_next, 1, 1, 3, none) 209 | DEF( for_of_next, 2, 3, 5, u8) 210 | DEF(iterator_check_object, 1, 1, 1, none) 211 | DEF(iterator_get_value_done, 1, 1, 2, none) 212 | DEF( iterator_close, 1, 3, 0, none) 213 | DEF( iterator_next, 1, 4, 4, none) 214 | DEF( iterator_call, 2, 4, 5, u8) 215 | DEF( initial_yield, 1, 0, 0, none) 216 | DEF( yield, 1, 1, 2, none) 217 | DEF( yield_star, 1, 1, 2, none) 218 | DEF(async_yield_star, 1, 1, 2, none) 219 | DEF( await, 1, 1, 1, none) 220 | 221 | /* arithmetic/logic operations */ 222 | DEF( neg, 1, 1, 1, none) 223 | DEF( plus, 1, 1, 1, none) 224 | DEF( dec, 1, 1, 1, none) 225 | DEF( inc, 1, 1, 1, none) 226 | DEF( post_dec, 1, 1, 2, none) 227 | DEF( post_inc, 1, 1, 2, none) 228 | DEF( dec_loc, 2, 0, 0, loc8) 229 | DEF( inc_loc, 2, 0, 0, loc8) 230 | DEF( add_loc, 2, 1, 0, loc8) 231 | DEF( not, 1, 1, 1, none) 232 | DEF( lnot, 1, 1, 1, none) 233 | DEF( typeof, 1, 1, 1, none) 234 | DEF( delete, 1, 2, 1, none) 235 | DEF( delete_var, 5, 0, 1, atom) 236 | 237 | DEF( mul, 1, 2, 1, none) 238 | DEF( div, 1, 2, 1, none) 239 | DEF( mod, 1, 2, 1, none) 240 | DEF( add, 1, 2, 1, none) 241 | DEF( sub, 1, 2, 1, none) 242 | DEF( pow, 1, 2, 1, none) 243 | DEF( shl, 1, 2, 1, none) 244 | DEF( sar, 1, 2, 1, none) 245 | DEF( shr, 1, 2, 1, none) 246 | DEF( lt, 1, 2, 1, none) 247 | DEF( lte, 1, 2, 1, none) 248 | DEF( gt, 1, 2, 1, none) 249 | DEF( gte, 1, 2, 1, none) 250 | DEF( instanceof, 1, 2, 1, none) 251 | DEF( in, 1, 2, 1, none) 252 | DEF( eq, 1, 2, 1, none) 253 | DEF( neq, 1, 2, 1, none) 254 | DEF( strict_eq, 1, 2, 1, none) 255 | DEF( strict_neq, 1, 2, 1, none) 256 | DEF( and, 1, 2, 1, none) 257 | DEF( xor, 1, 2, 1, none) 258 | DEF( or, 1, 2, 1, none) 259 | DEF(is_undefined_or_null, 1, 1, 1, none) 260 | DEF( private_in, 1, 2, 1, none) 261 | #ifdef CONFIG_BIGNUM 262 | DEF( mul_pow10, 1, 2, 1, none) 263 | DEF( math_mod, 1, 2, 1, none) 264 | #endif 265 | /* must be the last non short and non temporary opcode */ 266 | DEF( nop, 1, 0, 0, none) 267 | 268 | /* temporary opcodes: never emitted in the final bytecode */ 269 | 270 | def( enter_scope, 3, 0, 0, u16) /* emitted in phase 1, removed in phase 2 */ 271 | def( leave_scope, 3, 0, 0, u16) /* emitted in phase 1, removed in phase 2 */ 272 | 273 | def( label, 5, 0, 0, label) /* emitted in phase 1, removed in phase 3 */ 274 | 275 | /* the following opcodes must be in the same order as the 'with_x' and 276 | get_var_undef, get_var and put_var opcodes */ 277 | def(scope_get_var_undef, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */ 278 | def( scope_get_var, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */ 279 | def( scope_put_var, 7, 1, 0, atom_u16) /* emitted in phase 1, removed in phase 2 */ 280 | def(scope_delete_var, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2 */ 281 | def( scope_make_ref, 11, 0, 2, atom_label_u16) /* emitted in phase 1, removed in phase 2 */ 282 | def( scope_get_ref, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */ 283 | def(scope_put_var_init, 7, 0, 2, atom_u16) /* emitted in phase 1, removed in phase 2 */ 284 | def(scope_get_var_checkthis, 7, 0, 1, atom_u16) /* emitted in phase 1, removed in phase 2, only used to return 'this' in derived class constructors */ 285 | def(scope_get_private_field, 7, 1, 1, atom_u16) /* obj -> value, emitted in phase 1, removed in phase 2 */ 286 | def(scope_get_private_field2, 7, 1, 2, atom_u16) /* obj -> obj value, emitted in phase 1, removed in phase 2 */ 287 | def(scope_put_private_field, 7, 2, 0, atom_u16) /* obj value ->, emitted in phase 1, removed in phase 2 */ 288 | def(scope_in_private_field, 7, 1, 1, atom_u16) /* obj -> res emitted in phase 1, removed in phase 2 */ 289 | def(get_field_opt_chain, 5, 1, 1, atom) /* emitted in phase 1, removed in phase 2 */ 290 | def(get_array_el_opt_chain, 1, 2, 1, none) /* emitted in phase 1, removed in phase 2 */ 291 | def( set_class_name, 5, 1, 1, u32) /* emitted in phase 1, removed in phase 2 */ 292 | 293 | def( line_num, 5, 0, 0, u32) /* emitted in phase 1, removed in phase 3 */ 294 | 295 | #if SHORT_OPCODES 296 | DEF( push_minus1, 1, 0, 1, none_int) 297 | DEF( push_0, 1, 0, 1, none_int) 298 | DEF( push_1, 1, 0, 1, none_int) 299 | DEF( push_2, 1, 0, 1, none_int) 300 | DEF( push_3, 1, 0, 1, none_int) 301 | DEF( push_4, 1, 0, 1, none_int) 302 | DEF( push_5, 1, 0, 1, none_int) 303 | DEF( push_6, 1, 0, 1, none_int) 304 | DEF( push_7, 1, 0, 1, none_int) 305 | DEF( push_i8, 2, 0, 1, i8) 306 | DEF( push_i16, 3, 0, 1, i16) 307 | DEF( push_const8, 2, 0, 1, const8) 308 | DEF( fclosure8, 2, 0, 1, const8) /* must follow push_const8 */ 309 | DEF(push_empty_string, 1, 0, 1, none) 310 | 311 | DEF( get_loc8, 2, 0, 1, loc8) 312 | DEF( put_loc8, 2, 1, 0, loc8) 313 | DEF( set_loc8, 2, 1, 1, loc8) 314 | 315 | DEF( get_loc0, 1, 0, 1, none_loc) 316 | DEF( get_loc1, 1, 0, 1, none_loc) 317 | DEF( get_loc2, 1, 0, 1, none_loc) 318 | DEF( get_loc3, 1, 0, 1, none_loc) 319 | DEF( put_loc0, 1, 1, 0, none_loc) 320 | DEF( put_loc1, 1, 1, 0, none_loc) 321 | DEF( put_loc2, 1, 1, 0, none_loc) 322 | DEF( put_loc3, 1, 1, 0, none_loc) 323 | DEF( set_loc0, 1, 1, 1, none_loc) 324 | DEF( set_loc1, 1, 1, 1, none_loc) 325 | DEF( set_loc2, 1, 1, 1, none_loc) 326 | DEF( set_loc3, 1, 1, 1, none_loc) 327 | DEF( get_arg0, 1, 0, 1, none_arg) 328 | DEF( get_arg1, 1, 0, 1, none_arg) 329 | DEF( get_arg2, 1, 0, 1, none_arg) 330 | DEF( get_arg3, 1, 0, 1, none_arg) 331 | DEF( put_arg0, 1, 1, 0, none_arg) 332 | DEF( put_arg1, 1, 1, 0, none_arg) 333 | DEF( put_arg2, 1, 1, 0, none_arg) 334 | DEF( put_arg3, 1, 1, 0, none_arg) 335 | DEF( set_arg0, 1, 1, 1, none_arg) 336 | DEF( set_arg1, 1, 1, 1, none_arg) 337 | DEF( set_arg2, 1, 1, 1, none_arg) 338 | DEF( set_arg3, 1, 1, 1, none_arg) 339 | DEF( get_var_ref0, 1, 0, 1, none_var_ref) 340 | DEF( get_var_ref1, 1, 0, 1, none_var_ref) 341 | DEF( get_var_ref2, 1, 0, 1, none_var_ref) 342 | DEF( get_var_ref3, 1, 0, 1, none_var_ref) 343 | DEF( put_var_ref0, 1, 1, 0, none_var_ref) 344 | DEF( put_var_ref1, 1, 1, 0, none_var_ref) 345 | DEF( put_var_ref2, 1, 1, 0, none_var_ref) 346 | DEF( put_var_ref3, 1, 1, 0, none_var_ref) 347 | DEF( set_var_ref0, 1, 1, 1, none_var_ref) 348 | DEF( set_var_ref1, 1, 1, 1, none_var_ref) 349 | DEF( set_var_ref2, 1, 1, 1, none_var_ref) 350 | DEF( set_var_ref3, 1, 1, 1, none_var_ref) 351 | 352 | DEF( get_length, 1, 1, 1, none) 353 | 354 | DEF( if_false8, 2, 1, 0, label8) 355 | DEF( if_true8, 2, 1, 0, label8) /* must come after if_false8 */ 356 | DEF( goto8, 2, 0, 0, label8) /* must come after if_true8 */ 357 | DEF( goto16, 3, 0, 0, label16) 358 | 359 | DEF( call0, 1, 1, 1, npopx) 360 | DEF( call1, 1, 1, 1, npopx) 361 | DEF( call2, 1, 1, 1, npopx) 362 | DEF( call3, 1, 1, 1, npopx) 363 | 364 | DEF( is_undefined, 1, 1, 1, none) 365 | DEF( is_null, 1, 1, 1, none) 366 | DEF(typeof_is_undefined, 1, 1, 1, none) 367 | DEF( typeof_is_function, 1, 1, 1, none) 368 | #endif 369 | 370 | #undef DEF 371 | #undef def 372 | #endif /* DEF */ 373 | -------------------------------------------------------------------------------- /quickjs/unicode_gen_def.h: -------------------------------------------------------------------------------- 1 | #ifdef UNICODE_GENERAL_CATEGORY 2 | DEF(Cn, "Unassigned") /* must be zero */ 3 | DEF(Lu, "Uppercase_Letter") 4 | DEF(Ll, "Lowercase_Letter") 5 | DEF(Lt, "Titlecase_Letter") 6 | DEF(Lm, "Modifier_Letter") 7 | DEF(Lo, "Other_Letter") 8 | DEF(Mn, "Nonspacing_Mark") 9 | DEF(Mc, "Spacing_Mark") 10 | DEF(Me, "Enclosing_Mark") 11 | DEF(Nd, "Decimal_Number,digit") 12 | DEF(Nl, "Letter_Number") 13 | DEF(No, "Other_Number") 14 | DEF(Sm, "Math_Symbol") 15 | DEF(Sc, "Currency_Symbol") 16 | DEF(Sk, "Modifier_Symbol") 17 | DEF(So, "Other_Symbol") 18 | DEF(Pc, "Connector_Punctuation") 19 | DEF(Pd, "Dash_Punctuation") 20 | DEF(Ps, "Open_Punctuation") 21 | DEF(Pe, "Close_Punctuation") 22 | DEF(Pi, "Initial_Punctuation") 23 | DEF(Pf, "Final_Punctuation") 24 | DEF(Po, "Other_Punctuation") 25 | DEF(Zs, "Space_Separator") 26 | DEF(Zl, "Line_Separator") 27 | DEF(Zp, "Paragraph_Separator") 28 | DEF(Cc, "Control,cntrl") 29 | DEF(Cf, "Format") 30 | DEF(Cs, "Surrogate") 31 | DEF(Co, "Private_Use") 32 | /* synthetic properties */ 33 | DEF(LC, "Cased_Letter") 34 | DEF(L, "Letter") 35 | DEF(M, "Mark,Combining_Mark") 36 | DEF(N, "Number") 37 | DEF(S, "Symbol") 38 | DEF(P, "Punctuation,punct") 39 | DEF(Z, "Separator") 40 | DEF(C, "Other") 41 | #endif 42 | 43 | #ifdef UNICODE_SCRIPT 44 | /* scripts aliases names in PropertyValueAliases.txt */ 45 | DEF(Unknown, "Zzzz") 46 | DEF(Adlam, "Adlm") 47 | DEF(Ahom, "Ahom") 48 | DEF(Anatolian_Hieroglyphs, "Hluw") 49 | DEF(Arabic, "Arab") 50 | DEF(Armenian, "Armn") 51 | DEF(Avestan, "Avst") 52 | DEF(Balinese, "Bali") 53 | DEF(Bamum, "Bamu") 54 | DEF(Bassa_Vah, "Bass") 55 | DEF(Batak, "Batk") 56 | DEF(Bengali, "Beng") 57 | DEF(Bhaiksuki, "Bhks") 58 | DEF(Bopomofo, "Bopo") 59 | DEF(Brahmi, "Brah") 60 | DEF(Braille, "Brai") 61 | DEF(Buginese, "Bugi") 62 | DEF(Buhid, "Buhd") 63 | DEF(Canadian_Aboriginal, "Cans") 64 | DEF(Carian, "Cari") 65 | DEF(Caucasian_Albanian, "Aghb") 66 | DEF(Chakma, "Cakm") 67 | DEF(Cham, "Cham") 68 | DEF(Cherokee, "Cher") 69 | DEF(Chorasmian, "Chrs") 70 | DEF(Common, "Zyyy") 71 | DEF(Coptic, "Copt,Qaac") 72 | DEF(Cuneiform, "Xsux") 73 | DEF(Cypriot, "Cprt") 74 | DEF(Cyrillic, "Cyrl") 75 | DEF(Cypro_Minoan, "Cpmn") 76 | DEF(Deseret, "Dsrt") 77 | DEF(Devanagari, "Deva") 78 | DEF(Dives_Akuru, "Diak") 79 | DEF(Dogra, "Dogr") 80 | DEF(Duployan, "Dupl") 81 | DEF(Egyptian_Hieroglyphs, "Egyp") 82 | DEF(Elbasan, "Elba") 83 | DEF(Elymaic, "Elym") 84 | DEF(Ethiopic, "Ethi") 85 | DEF(Georgian, "Geor") 86 | DEF(Glagolitic, "Glag") 87 | DEF(Gothic, "Goth") 88 | DEF(Grantha, "Gran") 89 | DEF(Greek, "Grek") 90 | DEF(Gujarati, "Gujr") 91 | DEF(Gunjala_Gondi, "Gong") 92 | DEF(Gurmukhi, "Guru") 93 | DEF(Han, "Hani") 94 | DEF(Hangul, "Hang") 95 | DEF(Hanifi_Rohingya, "Rohg") 96 | DEF(Hanunoo, "Hano") 97 | DEF(Hatran, "Hatr") 98 | DEF(Hebrew, "Hebr") 99 | DEF(Hiragana, "Hira") 100 | DEF(Imperial_Aramaic, "Armi") 101 | DEF(Inherited, "Zinh,Qaai") 102 | DEF(Inscriptional_Pahlavi, "Phli") 103 | DEF(Inscriptional_Parthian, "Prti") 104 | DEF(Javanese, "Java") 105 | DEF(Kaithi, "Kthi") 106 | DEF(Kannada, "Knda") 107 | DEF(Katakana, "Kana") 108 | DEF(Kawi, "Kawi") 109 | DEF(Kayah_Li, "Kali") 110 | DEF(Kharoshthi, "Khar") 111 | DEF(Khmer, "Khmr") 112 | DEF(Khojki, "Khoj") 113 | DEF(Khitan_Small_Script, "Kits") 114 | DEF(Khudawadi, "Sind") 115 | DEF(Lao, "Laoo") 116 | DEF(Latin, "Latn") 117 | DEF(Lepcha, "Lepc") 118 | DEF(Limbu, "Limb") 119 | DEF(Linear_A, "Lina") 120 | DEF(Linear_B, "Linb") 121 | DEF(Lisu, "Lisu") 122 | DEF(Lycian, "Lyci") 123 | DEF(Lydian, "Lydi") 124 | DEF(Makasar, "Maka") 125 | DEF(Mahajani, "Mahj") 126 | DEF(Malayalam, "Mlym") 127 | DEF(Mandaic, "Mand") 128 | DEF(Manichaean, "Mani") 129 | DEF(Marchen, "Marc") 130 | DEF(Masaram_Gondi, "Gonm") 131 | DEF(Medefaidrin, "Medf") 132 | DEF(Meetei_Mayek, "Mtei") 133 | DEF(Mende_Kikakui, "Mend") 134 | DEF(Meroitic_Cursive, "Merc") 135 | DEF(Meroitic_Hieroglyphs, "Mero") 136 | DEF(Miao, "Plrd") 137 | DEF(Modi, "Modi") 138 | DEF(Mongolian, "Mong") 139 | DEF(Mro, "Mroo") 140 | DEF(Multani, "Mult") 141 | DEF(Myanmar, "Mymr") 142 | DEF(Nabataean, "Nbat") 143 | DEF(Nag_Mundari, "Nagm") 144 | DEF(Nandinagari, "Nand") 145 | DEF(New_Tai_Lue, "Talu") 146 | DEF(Newa, "Newa") 147 | DEF(Nko, "Nkoo") 148 | DEF(Nushu, "Nshu") 149 | DEF(Nyiakeng_Puachue_Hmong, "Hmnp") 150 | DEF(Ogham, "Ogam") 151 | DEF(Ol_Chiki, "Olck") 152 | DEF(Old_Hungarian, "Hung") 153 | DEF(Old_Italic, "Ital") 154 | DEF(Old_North_Arabian, "Narb") 155 | DEF(Old_Permic, "Perm") 156 | DEF(Old_Persian, "Xpeo") 157 | DEF(Old_Sogdian, "Sogo") 158 | DEF(Old_South_Arabian, "Sarb") 159 | DEF(Old_Turkic, "Orkh") 160 | DEF(Old_Uyghur, "Ougr") 161 | DEF(Oriya, "Orya") 162 | DEF(Osage, "Osge") 163 | DEF(Osmanya, "Osma") 164 | DEF(Pahawh_Hmong, "Hmng") 165 | DEF(Palmyrene, "Palm") 166 | DEF(Pau_Cin_Hau, "Pauc") 167 | DEF(Phags_Pa, "Phag") 168 | DEF(Phoenician, "Phnx") 169 | DEF(Psalter_Pahlavi, "Phlp") 170 | DEF(Rejang, "Rjng") 171 | DEF(Runic, "Runr") 172 | DEF(Samaritan, "Samr") 173 | DEF(Saurashtra, "Saur") 174 | DEF(Sharada, "Shrd") 175 | DEF(Shavian, "Shaw") 176 | DEF(Siddham, "Sidd") 177 | DEF(SignWriting, "Sgnw") 178 | DEF(Sinhala, "Sinh") 179 | DEF(Sogdian, "Sogd") 180 | DEF(Sora_Sompeng, "Sora") 181 | DEF(Soyombo, "Soyo") 182 | DEF(Sundanese, "Sund") 183 | DEF(Syloti_Nagri, "Sylo") 184 | DEF(Syriac, "Syrc") 185 | DEF(Tagalog, "Tglg") 186 | DEF(Tagbanwa, "Tagb") 187 | DEF(Tai_Le, "Tale") 188 | DEF(Tai_Tham, "Lana") 189 | DEF(Tai_Viet, "Tavt") 190 | DEF(Takri, "Takr") 191 | DEF(Tamil, "Taml") 192 | DEF(Tangut, "Tang") 193 | DEF(Telugu, "Telu") 194 | DEF(Thaana, "Thaa") 195 | DEF(Thai, "Thai") 196 | DEF(Tibetan, "Tibt") 197 | DEF(Tifinagh, "Tfng") 198 | DEF(Tirhuta, "Tirh") 199 | DEF(Tangsa, "Tnsa") 200 | DEF(Toto, "Toto") 201 | DEF(Ugaritic, "Ugar") 202 | DEF(Vai, "Vaii") 203 | DEF(Vithkuqi, "Vith") 204 | DEF(Wancho, "Wcho") 205 | DEF(Warang_Citi, "Wara") 206 | DEF(Yezidi, "Yezi") 207 | DEF(Yi, "Yiii") 208 | DEF(Zanabazar_Square, "Zanb") 209 | #endif 210 | 211 | #ifdef UNICODE_PROP_LIST 212 | /* Prop list not exported to regexp */ 213 | DEF(Hyphen, "") 214 | DEF(Other_Math, "") 215 | DEF(Other_Alphabetic, "") 216 | DEF(Other_Lowercase, "") 217 | DEF(Other_Uppercase, "") 218 | DEF(Other_Grapheme_Extend, "") 219 | DEF(Other_Default_Ignorable_Code_Point, "") 220 | DEF(Other_ID_Start, "") 221 | DEF(Other_ID_Continue, "") 222 | DEF(Prepended_Concatenation_Mark, "") 223 | /* additional computed properties for smaller tables */ 224 | DEF(ID_Continue1, "") 225 | DEF(XID_Start1, "") 226 | DEF(XID_Continue1, "") 227 | DEF(Changes_When_Titlecased1, "") 228 | DEF(Changes_When_Casefolded1, "") 229 | DEF(Changes_When_NFKC_Casefolded1, "") 230 | 231 | /* Prop list exported to JS */ 232 | DEF(ASCII_Hex_Digit, "AHex") 233 | DEF(Bidi_Control, "Bidi_C") 234 | DEF(Dash, "") 235 | DEF(Deprecated, "Dep") 236 | DEF(Diacritic, "Dia") 237 | DEF(Extender, "Ext") 238 | DEF(Hex_Digit, "Hex") 239 | DEF(IDS_Binary_Operator, "IDSB") 240 | DEF(IDS_Trinary_Operator, "IDST") 241 | DEF(Ideographic, "Ideo") 242 | DEF(Join_Control, "Join_C") 243 | DEF(Logical_Order_Exception, "LOE") 244 | DEF(Noncharacter_Code_Point, "NChar") 245 | DEF(Pattern_Syntax, "Pat_Syn") 246 | DEF(Pattern_White_Space, "Pat_WS") 247 | DEF(Quotation_Mark, "QMark") 248 | DEF(Radical, "") 249 | DEF(Regional_Indicator, "RI") 250 | DEF(Sentence_Terminal, "STerm") 251 | DEF(Soft_Dotted, "SD") 252 | DEF(Terminal_Punctuation, "Term") 253 | DEF(Unified_Ideograph, "UIdeo") 254 | DEF(Variation_Selector, "VS") 255 | DEF(White_Space, "space") 256 | DEF(Bidi_Mirrored, "Bidi_M") 257 | DEF(Emoji, "") 258 | DEF(Emoji_Component, "EComp") 259 | DEF(Emoji_Modifier, "EMod") 260 | DEF(Emoji_Modifier_Base, "EBase") 261 | DEF(Emoji_Presentation, "EPres") 262 | DEF(Extended_Pictographic, "ExtPict") 263 | DEF(Default_Ignorable_Code_Point, "DI") 264 | DEF(ID_Start, "IDS") 265 | DEF(Case_Ignorable, "CI") 266 | 267 | /* other binary properties */ 268 | DEF(ASCII,"") 269 | DEF(Alphabetic, "Alpha") 270 | DEF(Any, "") 271 | DEF(Assigned,"") 272 | DEF(Cased, "") 273 | DEF(Changes_When_Casefolded, "CWCF") 274 | DEF(Changes_When_Casemapped, "CWCM") 275 | DEF(Changes_When_Lowercased, "CWL") 276 | DEF(Changes_When_NFKC_Casefolded, "CWKCF") 277 | DEF(Changes_When_Titlecased, "CWT") 278 | DEF(Changes_When_Uppercased, "CWU") 279 | DEF(Grapheme_Base, "Gr_Base") 280 | DEF(Grapheme_Extend, "Gr_Ext") 281 | DEF(ID_Continue, "IDC") 282 | DEF(Lowercase, "Lower") 283 | DEF(Math, "") 284 | DEF(Uppercase, "Upper") 285 | DEF(XID_Continue, "XIDC") 286 | DEF(XID_Start, "XIDS") 287 | 288 | /* internal tables with index */ 289 | DEF(Cased1, "") 290 | 291 | #endif 292 | -------------------------------------------------------------------------------- /win/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | option ( MD "MD" OFF ) 4 | 5 | if ( WIN32 AND NOT CYGWIN AND NOT ( CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" ) AND NOT ANDROID) 6 | if (MD) 7 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD" CACHE STRING "") 8 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd" CACHE STRING "") 9 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD" CACHE STRING "") 10 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd" CACHE STRING "") 11 | else () 12 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT" CACHE STRING "") 13 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd" CACHE STRING "") 14 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT" CACHE STRING "") 15 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd" CACHE STRING "") 16 | endif () 17 | endif () 18 | 19 | project(v8qjs) 20 | 21 | if (APPLE AND NOT IOS) 22 | set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version") 23 | endif() 24 | 25 | set(qjs_cflags -Wall) 26 | 27 | set (CMAKE_CXX_STANDARD 14) 28 | 29 | include_directories( 30 | ../include 31 | ../quickjs 32 | ) 33 | 34 | if (NOT WIN_DLL ) 35 | 36 | add_library(v8qjs STATIC 37 | ../src/v8-impl.cc 38 | ) 39 | 40 | else () 41 | 42 | add_library(v8qjs SHARED 43 | ../src/v8-impl.cc 44 | ) 45 | 46 | target_link_libraries(v8qjs 47 | ../../build/libquickjs.dll 48 | ) 49 | 50 | #set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) 51 | target_compile_definitions (v8qjs PRIVATE BUILDING_V8_SHARED BUILDING_V8_PLATFORM_SHARED) 52 | 53 | endif () 54 | 55 | if (QJS_NS) 56 | message("using v8_qjs namespace >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") 57 | target_compile_definitions(v8qjs PRIVATE CUSTOMV8NAMESPACE=v8_qjs) 58 | else () 59 | message("using v8 namespace >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") 60 | endif() 61 | #target_compile_definitions(v8qjs PRIVATE CUSTOMV8NAMESPACE=v8_qjs) 62 | 63 | target_compile_options(v8qjs PRIVATE ${qjs_cflags}) 64 | target_compile_definitions(v8qjs PRIVATE 65 | _GNU_SOURCE 66 | CONFIG_BIGNUM 67 | ) 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /win/make_win32.bat: -------------------------------------------------------------------------------- 1 | mkdir build & pushd build 2 | 3 | if "%1" == "1" ( 4 | cmake -S ..\CMakeLists.win.txt -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DQJS_NS=1 -G "Visual Studio 16 2019" -A Win32 .. 5 | ) else ( 6 | cmake -S ..\CMakeLists.win.txt -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -G "Visual Studio 16 2019" -A Win32 .. 7 | ) 8 | popd 9 | cmake --build build --config Release 10 | pause 11 | -------------------------------------------------------------------------------- /win/make_win64.bat: -------------------------------------------------------------------------------- 1 | mkdir build & pushd build 2 | 3 | if "%1" == "1" ( 4 | cmake -S ..\CMakeLists.win.txt -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DQJS_NS=1 -G "Visual Studio 16 2019" -A x64 .. 5 | ) else ( 6 | cmake -S ..\CMakeLists.win.txt -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -G "Visual Studio 16 2019" -A x64 .. 7 | ) 8 | 9 | popd 10 | cmake --build build --config Release 11 | pause 12 | -------------------------------------------------------------------------------- /win/make_win64md.bat: -------------------------------------------------------------------------------- 1 | mkdir build & pushd build 2 | 3 | if "%1" == "1" ( 4 | cmake -DMD=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DQJS_NS=1 -G "Visual Studio 16 2019" -A x64 .. 5 | ) else ( 6 | cmake -DMD=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -G "Visual Studio 16 2019" -A x64 .. 7 | ) 8 | popd 9 | cmake --build build --config Release 10 | pause 11 | -------------------------------------------------------------------------------- /win/make_win64md_dll.bat: -------------------------------------------------------------------------------- 1 | copy /y ..\build\libquickjs.dll.a ..\build\libquickjs.dll.lib 2 | mkdir build & pushd build 3 | if "%1" == "1" ( 4 | cmake -DMD=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DWIN_DLL=1 -DQJS_NS=1 -G "Visual Studio 16 2019" -A x64 .. 5 | ) else ( 6 | cmake -DMD=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DWIN_DLL=1 -G "Visual Studio 16 2019" -A x64 .. 7 | ) 8 | popd 9 | cmake --build build --config Release 10 | pause 11 | --------------------------------------------------------------------------------