4 files changed, 97 insertions(+), 2 deletions(-)
README.md+4-1| ... | ... | @@ -6,6 +6,10 @@ This language is a mix of features from JavaScript, Rust, and Zig. Some notable |
| 6 | 6 | - **Zig** - Execute any code at compile time, everything is an expression. |
| 7 | 7 | - **JavaScript** - Garbage collected values with a versitile type system. |
| 8 | 8 | |
| 9 | ## Developing | |
| 10 | ||
| 11 | To compile a development build, one can use the provided `./build` or `.\build.cmd` scripts to download Zig and build the compiler. These scripts are effective aliases of `zig build`. A release build can be built by passing the `--release` flag to any of these commands. | |
| 12 | ||
| 9 | 13 | ## Standard Library |
| 10 | 14 | |
| 11 | 15 | Currently, there is no standard library. One will be introduced later. |
| ... | ... | @@ -79,4 +83,3 @@ var number: float = 0; // `number` is `float` |
| 79 | 83 | ``` |
| 80 | 84 | |
| 81 | 85 | ## Functions |
| 82 |
build created+53| ... | ... | @@ -0,0 +1,53 @@ |
| 1 | #!/bin/sh | |
| 2 | # This script will build the compiler on any POSIX system. | |
| 3 | # It automatically installs a Zig compiler to ./zig-cache | |
| 4 | # if needed. The output will be in ./zig-out/bin. | |
| 5 | # | |
| 6 | # `curl` and `tar` is required in order to download and | |
| 7 | # extract Zig, respectively. The rest of the dependencies | |
| 8 | # are downloaded compiled using the Zig build system. | |
| 9 | cd -- "$(dirname -- "$0")" | |
| 10 | ||
| 11 | ZIG_VERSION=$(grep .minimum_zig_version build.zig.zon \ | |
| 12 | | cut -d '"' -f 2) | |
| 13 | ||
| 14 | ZIG="zig-cache/zig/$ZIG_VERSION/zig" | |
| 15 | if [ ! -f "$ZIG" ]; then | |
| 16 | OS=$(uname -s | tr '[:upper:]' '[:lower:]') | |
| 17 | if [ "$OS" = "darwin" ]; then | |
| 18 | OS="macos" | |
| 19 | fi | |
| 20 | ARCH=$(uname -m) | |
| 21 | if [ "$ARCH" = "arm64" ]; then | |
| 22 | ARCH="aarch64" | |
| 23 | fi | |
| 24 | ||
| 25 | URL="https://ziglang.org/builds/zig-$OS-$ARCH-$ZIG_VERSION.tar.xz" | |
| 26 | ||
| 27 | echo "Installing Zig v$ZIG_VERSION via $URL" | |
| 28 | ||
| 29 | CURL=$(command -v curl 2>/dev/null) | |
| 30 | TAR=$(command -v curl 2>/dev/null) | |
| 31 | ||
| 32 | if [ -z "$CURL" ]; then | |
| 33 | echo "This script requires 'curl' to be installed." | |
| 34 | fi | |
| 35 | if [ -z "$TAR" ]; then | |
| 36 | echo "This script requires 'tar' to be installed." | |
| 37 | fi | |
| 38 | ||
| 39 | if [ -z "$CURL" ] || [ -z "$TAR" ]; then | |
| 40 | exit 1 | |
| 41 | fi | |
| 42 | ||
| 43 | mkdir -p zig-cache/zig/$ZIG_VERSION | |
| 44 | curl -fsSL --retry 3 --retry-delay 3 $URL \ | |
| 45 | | tar -xJ --strip-components=1 -C zig-cache/zig/$ZIG_VERSION | |
| 46 | if [ "$($ZIG version)" != "$ZIG_VERSION" ]; then | |
| 47 | echo "Zig failed to install." | |
| 48 | rm -rf zig-cache/zig/$ZIG_VERSION | |
| 49 | exit 1 | |
| 50 | fi | |
| 51 | fi | |
| 52 | ||
| 53 | $ZIG build $@ |
build.cmd created+29| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | @ECHO OFF | |
| 2 | @REM This script will build the compiler on any Windows system | |
| 3 | @REM It automatically installs a Zig compiler to ./zig-cache | |
| 4 | @REM The output will be in ./zig-out/bin | |
| 5 | ||
| 6 | SET ROOT=%~dp0 | |
| 7 | FOR /F "tokens=3 delims=, " %%i IN ( | |
| 8 | 'FINDSTR /R "\.minimum_zig_version *= *""".+""",\n" ^ | |
| 9 | "%ROOT%build.zig.zon"' | |
| 10 | ) DO SET ZIG_VERSION=%%i | |
| 11 | SET ZIG_VERSION=%ZIG_VERSION:~1,-1% | |
| 12 | IF NOT EXIST "%ROOT%zig-cache\zig\%ZIG_VERSION%\zig.exe" GOTO :find_powershell | |
| 13 | :build | |
| 14 | "%ROOT%zig-cache\zig\%ZIG_VERSION%\zig.exe" build %* | |
| 15 | EXIT /b %ERRORLEVEL% | |
| 16 | :find_powershell | |
| 17 | FOR %%i IN (pwsh powershell) DO WHERE %%i /Q && SET PS=%%i && GOTO :download | |
| 18 | ECHO Powershell not found. Please install it and try again. | |
| 19 | EXIT /b 1 | |
| 20 | :download | |
| 21 | SET ZIG_ARCH=x86_64 | |
| 22 | SET URI=https://ziglang.org/builds/zig-windows-%ZIG_ARCH%-%ZIG_VERSION%.zip | |
| 23 | SET X=$null = New-Item -ItemType Directory -Force -Path zig-cache\zig | |
| 24 | SET X=%X%;Invoke-RestMethod -Uri %URI% -OutFile zig-cache/zig-%ZIG_VERSION%.zip | |
| 25 | SET X=%X%;Expand-Archive zig-cache/zig-%ZIG_VERSION%.zip -DestinationPath zig-cache/zig | |
| 26 | SET X=%X%;Remove-Item zig-cache/zig-%ZIG_VERSION%.zip | |
| 27 | %PS% -NoProfile -Command "%X%" | |
| 28 | MOVE zig-cache\zig\zig-windows-%ZIG_ARCH%-%ZIG_VERSION% zig-cache\zig\%ZIG_VERSION% >NUL | |
| 29 | GOTO :build |
build.zig+11-1| ... | ... | @@ -7,7 +7,17 @@ pub fn build(b: *std.Build) void { |
| 7 | 7 | b.reference_trace = 20; |
| 8 | 8 | |
| 9 | 9 | const target = b.standardTargetOptions(.{}); |
| 10 | const optimize = b.standardOptimizeOption(.{}); | |
| 10 | const optimize_fallback = b.standardOptimizeOption(.{}); | |
| 11 | const optimize: std.builtin.OptimizeMode = switch (b.release_mode) { | |
| 12 | .off => optimize_fallback, | |
| 13 | .safe => .ReleaseSafe, | |
| 14 | .fast => .ReleaseFast, | |
| 15 | .small => .ReleaseSmall, | |
| 16 | .any => brk: { | |
| 17 | b.release_mode = .safe; | |
| 18 | break :brk .ReleaseSafe; | |
| 19 | }, | |
| 20 | }; | |
| 11 | 21 | |
| 12 | 22 | const tracing = b.option(enum { |
| 13 | 23 | none, |