Compare commits

...

8 Commits

Author SHA1 Message Date
William Bell
f5e241aba0 forgot to add cmake and make 2025-08-16 16:08:06 +01:00
William Bell
8c3ee3fe05 fix --break-system-packages 2025-08-16 15:42:34 +01:00
William Bell
eb285b6e8f add linux arm64 to builds and reshape how execution is done. 2025-08-16 15:25:33 +01:00
William Bell
78a1edd572 add calculation to test 2025-08-16 05:40:29 +01:00
William Bell
b905026010 fix rosetta not used 2025-08-16 04:31:21 +01:00
William Bell
677afd9433 fix using Rosetta 2025-08-16 04:10:57 +01:00
William Bell
757da3f973 stupid ai 2025-08-16 03:51:05 +01:00
William Bell
5a86510c3b fix release for macos x86_64 and arm64 2025-08-16 03:48:48 +01:00
5 changed files with 136 additions and 124 deletions

View File

@@ -10,23 +10,15 @@ on:
- '*' # Any tag - '*' # Any tag
jobs: jobs:
build-linux: build-linux-x86_64:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
matrix:
arch: [x86_64, arm64]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
- name: Install build tools - name: Install build tools
run: | run: sudo apt-get update && sudo apt-get install -y flex bison
sudo apt-get update
sudo apt-get install -y flex bison make cmake build-essential
if [ "${{ matrix.arch }}" = "arm64" ]; then
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
fi
- name: Setup Python - name: Setup Python
uses: actions/setup-python@v4 uses: actions/setup-python@v4
@@ -41,28 +33,61 @@ jobs:
- name: Build - name: Build
run: | run: |
BUILD_DIR="build_${{ matrix.arch }}" conan install . --build=missing
mkdir -p "$BUILD_DIR" conan build .
cd "$BUILD_DIR"
if [ "${{ matrix.arch }}" = "arm64" ]; then
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
fi
conan install .. --build=missing
conan build ..
cd ..
- name: Package - name: Package
run: | run: |
TAG=${GITHUB_REF##refs/tags/} TAG=${GITHUB_REF##refs/tags/}
OS="linux" OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH="${{ matrix.arch }}" ARCH=$(uname -m)
FOLDER="chloride-$TAG-$OS-$ARCH" FOLDER="chloride-$TAG-$OS-$ARCH"
TAR="$FOLDER.tar.gz" TAR="$FOLDER.tar.gz"
mv build_${ARCH}/bin "$FOLDER" mv build/bin "$FOLDER"
cp LICENSE.txt "$FOLDER"
tar -czf "$TAR" "$FOLDER"
echo "TAR_NAME=$TAR" >> $GITHUB_ENV
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: linux-${{ matrix.arch }}-artifact
path: ${{ env.TAR_NAME }}
build-linux-arm64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Run build in arm64 container
run: |
docker run --rm --platform linux/arm64 \
-v $PWD:/work -w /work \
ubuntu:latest \
bash -c "
apt-get update && apt-get install -y python3-pip gcc flex bison cmake make &&
pip install --break-system-packages conan &&
conan profile detect --force &&
conan install . --build=missing &&
conan build .
"
- name: Package
run: |
TAG=${GITHUB_REF##refs/tags/}
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=arm64
FOLDER="chloride-$TAG-$OS-$ARCH"
TAR="$FOLDER.tar.gz"
mv build/bin "$FOLDER"
cp LICENSE.txt "$FOLDER" cp LICENSE.txt "$FOLDER"
tar -czf "$TAR" "$FOLDER" tar -czf "$TAR" "$FOLDER"
echo "TAR_NAME=$TAR" >> $GITHUB_ENV echo "TAR_NAME=$TAR" >> $GITHUB_ENV
@@ -95,22 +120,30 @@ jobs:
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install conan pip install conan
conan profile detect if [ "${{ matrix.arch }}" = "x86_64" ] && [ "$(uname -m)" = "arm64" ]; then
arch -x86_64 conan profile detect
else
conan profile detect
fi
- name: Build - name: Build
run: | run: |
# Create a build directory per arch
BUILD_DIR="build_${{ matrix.arch }}" BUILD_DIR="build_${{ matrix.arch }}"
mkdir -p "$BUILD_DIR" mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" cd "$BUILD_DIR"
# Use the matrix architecture for the build # Use Rosetta for x86_64 builds on Apple Silicon
export CFLAGS="-arch ${{ matrix.arch }}" if [ "${{ matrix.arch }}" = "x86_64" ] && [ "$(uname -m)" = "arm64" ]; then
export CXXFLAGS="-arch ${{ matrix.arch }}" arch -x86_64 bash -c "
export LDFLAGS="-arch ${{ matrix.arch }}" export CMAKE_OSX_ARCHITECTURES=x86_64
conan install .. --build=missing
conan install .. --build=missing conan build ..
conan build .. "
else
export CMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}"
conan install .. --build=missing
conan build ..
fi
cd .. cd ..
@@ -121,7 +154,7 @@ jobs:
ARCH="${{ matrix.arch }}" ARCH="${{ matrix.arch }}"
FOLDER="chloride-$TAG-$OS-$ARCH" FOLDER="chloride-$TAG-$OS-$ARCH"
TAR="$FOLDER.tar.gz" TAR="$FOLDER.tar.gz"
mv build_${ARCH}/bin "$FOLDER" mv build/bin "$FOLDER"
cp LICENSE.txt "$FOLDER" cp LICENSE.txt "$FOLDER"
tar -czf "$TAR" "$FOLDER" tar -czf "$TAR" "$FOLDER"
echo "TAR_NAME=$TAR" >> $GITHUB_ENV echo "TAR_NAME=$TAR" >> $GITHUB_ENV
@@ -134,9 +167,6 @@ jobs:
build-windows: build-windows:
runs-on: windows-latest runs-on: windows-latest
strategy:
matrix:
arch: [x86_64, arm64]
defaults: defaults:
run: run:
shell: msys2 {0} shell: msys2 {0}
@@ -146,8 +176,7 @@ jobs:
with: with:
submodules: recursive submodules: recursive
- name: Setup MSYS2 - uses: msys2/setup-msys2@v2
uses: msys2/setup-msys2@v2
with: with:
msystem: MINGW64 msystem: MINGW64
update: true update: true
@@ -168,42 +197,30 @@ jobs:
- name: Build Project - name: Build Project
run: | run: |
BUILD_DIR="build_${{ matrix.arch }}" conan install . --profile mingw-profile.txt --build=missing
mkdir -p "$BUILD_DIR" conan build . --profile mingw-profile.txt
cd "$BUILD_DIR"
if [ "${{ matrix.arch }}" = "arm64" ]; then
# Use the ARM64 cross-compiler
export CC=aarch64-w64-mingw32-gcc
export CXX=aarch64-w64-mingw32-g++
fi
conan install .. --profile mingw-profile.txt --build=missing
conan build .. --profile mingw-profile.txt
cd ..
- name: Package - name: Package
run: | run: |
TAG=${GITHUB_REF##refs/tags/} TAG=${GITHUB_REF##refs/tags/}
OS="windows" OS="windows"
ARCH="${{ matrix.arch }}" ARCH=$(uname -m)
FOLDER="chloride-$TAG-$OS-$ARCH" FOLDER="chloride-$TAG-$OS-$ARCH"
ZIP="$FOLDER.zip" TAR="$FOLDER.tar.gz"
mv build_${ARCH}/bin "$FOLDER" mv build/bin "$FOLDER"
cp LICENSE.txt "$FOLDER" cp LICENSE.txt "$FOLDER"
powershell Compress-Archive -Path "$FOLDER" -DestinationPath "$ZIP" tar -czf "$TAR" "$FOLDER"
echo "TAR_NAME=$ZIP" >> $GITHUB_ENV echo "TAR_NAME=$TAR" >> $GITHUB_ENV
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: windows-${{ matrix.arch }}-artifact name: windows-artifact
path: ${{ env.TAR_NAME }} path: ${{ env.TAR_NAME }}
release: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [build-linux, build-macos, build-windows] needs: [build-linux-x86_64, build-linux-arm64, build-macos, build-windows]
steps: steps:
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4

View File

@@ -14,10 +14,6 @@ LEXER_H = src/lexer/lex.yy.h
CFLAGS = $(ARCHFLAGS) -lm -lgc -lgmp -Wall -Wextra -Wno-unused-function -Werror=unused-result -Iexternal/cwalk/include -Iexternal/libdye/include CFLAGS = $(ARCHFLAGS) -lm -lgc -lgmp -Wall -Wextra -Wno-unused-function -Werror=unused-result -Iexternal/cwalk/include -Iexternal/libdye/include
LDFLAGS = -lgc -lgmp -lm LDFLAGS = -lgc -lgmp -lm
ifeq ($(MAKECMDGOALS),windows)
LDFLAGS = -Wl,-Bstatic -lgc -lgmp -Wl,-Bdynamic -lm
endif
all: $(BINARY) all: $(BINARY)
@@ -28,14 +24,6 @@ $(BINARY): $(CFILES) $(LEXER_C) $(LEXER_H)
mkdir -p bin mkdir -p bin
gcc -O3 -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS} -s gcc -O3 -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS} -s
windows: $(CFILES) $(LEXER_C) $(LEXER_H)
(echo -n "external/xxhash/xxhash.c " ; \
echo -n "external/cwalk/src/cwalk.c " ; \
echo -n "external/libdye/src/dye.c " ; \
find src -name '*.c' -print0 | xargs -0 echo -n) > sources.txt
mkdir -p bin
gcc -O3 -march=native -o $(BINARY) @sources.txt $(CFLAGS) -lbcrypt
native: $(CFILES) $(LEXER_C) $(LEXER_H) native: $(CFILES) $(LEXER_C) $(LEXER_H)
mkdir -p bin mkdir -p bin
gcc -O3 -march=native -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS} gcc -O3 -march=native -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}

View File

@@ -11,6 +11,7 @@
#include "lexer/token.h" #include "lexer/token.h"
#include "memory.h" #include "memory.h"
#include "parser/parser.h" #include "parser/parser.h"
#include "returnTypes.h"
#include "runtime/runtime.h" #include "runtime/runtime.h"
#include "translator/translator.h" #include "translator/translator.h"
@@ -66,8 +67,9 @@ static inline uint64_t htole64(uint64_t x) { return x; }
#define htole64(x) OSSwapHostToLittleInt64(x) #define htole64(x) OSSwapHostToLittleInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x) #define le64toh(x) OSSwapLittleToHostInt64(x)
// Add others as needed // Add others as needed
#else #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
#error "Unsupported platform" #include <stdlib.h>
#include <sys/endian.h>
#endif #endif
char *get_current_directory() { char *get_current_directory() {
@@ -158,7 +160,7 @@ int load_cache(Translated *translated_dest, char *joined_paths, uint64_t hash,
char *source_path) { char *source_path) {
FILE *bytecode_file = fopen(joined_paths, "rb"); FILE *bytecode_file = fopen(joined_paths, "rb");
if (!bytecode_file) { if (!bytecode_file) {
fprintf(stderr,"cache doesnt exist... compiling from source.\n"); fprintf(stderr, "cache doesnt exist... compiling from source.\n");
return 1; return 1;
} }
@@ -194,7 +196,7 @@ int load_cache(Translated *translated_dest, char *joined_paths, uint64_t hash,
XXH64_freeState(state); XXH64_freeState(state);
if (calc_hash != stored_hash) { if (calc_hash != stored_hash) {
fprintf(stderr,"cache hash mismatch (corrupted?)\n"); fprintf(stderr, "cache hash mismatch (corrupted?)\n");
goto FAILED; goto FAILED;
} }
@@ -268,27 +270,29 @@ int load_cache(Translated *translated_dest, char *joined_paths, uint64_t hash,
goto FAILED; goto FAILED;
} }
fprintf(stderr,"cache exists and is valid, so will be used.\n"); fprintf(stderr, "cache exists and is valid, so will be used.\n");
fclose(bytecode_file); fclose(bytecode_file);
return 0; return 0;
FAILED: FAILED:
fprintf(stderr,"cache is invalid... compiling from source.\n"); fprintf(stderr, "cache is invalid... compiling from source.\n");
fclose(bytecode_file); fclose(bytecode_file);
return 1; return 1;
} }
Execution execute(char *path, Stack *stack) { Translated load_argon_file(char *path, ArErr *err) {
clock_t start, end; clock_t start, end;
clock_t beginning = clock();
double time_spent, total_time_spent = 0; double time_spent, total_time_spent = 0;
const char *basename_ptr; const char *basename_ptr;
size_t basename_length; size_t basename_length;
cwk_path_get_basename(path, &basename_ptr, &basename_length); cwk_path_get_basename(path, &basename_ptr, &basename_length);
if (!basename_ptr) if (!basename_ptr) {
return (Execution){create_err(0, 0, 0, NULL, "Path Error", *err = create_err(0, 0, 0, NULL, "Path Error", "path has no basename '%s'",
"path has no basename '%s'", path), path);
(Stack){NULL, NULL}}; return (Translated){};
}
char basename[FILENAME_MAX]; char basename[FILENAME_MAX];
memcpy(basename, basename_ptr, basename_length); memcpy(basename, basename_ptr, basename_length);
@@ -312,9 +316,9 @@ Execution execute(char *path, Stack *stack) {
FILE *file = fopen(path, "r"); FILE *file = fopen(path, "r");
if (!file) { if (!file) {
return (Execution){create_err(0, 0, 0, NULL, "File Error", *err = create_err(0, 0, 0, NULL, "File Error", "Unable to open file '%s'",
"Unable to open file '%s'", path), path);
(Stack){NULL, NULL}}; return (Translated){};
} }
XXH3_state_t *hash_state = XXH3_createState(); XXH3_state_t *hash_state = XXH3_createState();
@@ -338,15 +342,14 @@ Execution execute(char *path, Stack *stack) {
LexerState state = {path, file, 0, 0, &tokens}; LexerState state = {path, file, 0, 0, &tokens};
start = clock(); start = clock();
ArErr err = lexer(state); *err = lexer(state);
if (err.exists) { if (err->exists) {
darray_free(&tokens, free_token); darray_free(&tokens, free_token);
return (Execution){err, (Stack){NULL, NULL}}; return (Translated){};
} }
end = clock(); end = clock();
time_spent = (double)(end - start) / CLOCKS_PER_SEC; time_spent = (double)(end - start) / CLOCKS_PER_SEC;
total_time_spent += time_spent; fprintf(stderr, "Lexer time taken: %f seconds\n", time_spent);
fprintf(stderr,"Lexer time taken: %f seconds\n", time_spent);
fclose(state.file); fclose(state.file);
DArray ast; DArray ast;
@@ -354,33 +357,31 @@ Execution execute(char *path, Stack *stack) {
darray_init(&ast, sizeof(ParsedValue)); darray_init(&ast, sizeof(ParsedValue));
start = clock(); start = clock();
err = parser(path, &ast, &tokens, false); *err = parser(path, &ast, &tokens, false);
if (err.exists) { if (err->exists) {
darray_free(&tokens, free_token); darray_free(&tokens, free_token);
darray_free(&ast, free_parsed); darray_free(&ast, free_parsed);
return (Execution){err, (Stack){NULL, NULL}}; return (Translated){};
} }
end = clock(); end = clock();
time_spent = (double)(end - start) / CLOCKS_PER_SEC; time_spent = (double)(end - start) / CLOCKS_PER_SEC;
total_time_spent += time_spent; fprintf(stderr, "Parser time taken: %f seconds\n", time_spent);
fprintf(stderr,"Parser time taken: %f seconds\n", time_spent);
darray_free(&tokens, free_token); darray_free(&tokens, free_token);
start = clock(); start = clock();
translated = init_translator(path); translated = init_translator(path);
err = translate(&translated, &ast); *err = translate(&translated, &ast);
if (err.exists) { if (err->exists) {
darray_free(&translated.bytecode, NULL); darray_free(&translated.bytecode, NULL);
free(translated.constants.data); free(translated.constants.data);
hashmap_free(translated.constants.hashmap, NULL); hashmap_free(translated.constants.hashmap, NULL);
darray_free(&ast, free_parsed); darray_free(&ast, free_parsed);
return (Execution){err, (Stack){NULL, NULL}}; return (Translated){};
} }
end = clock(); end = clock();
time_spent = (double)(end - start) / CLOCKS_PER_SEC; time_spent = (double)(end - start) / CLOCKS_PER_SEC;
total_time_spent += time_spent; fprintf(stderr, "Translation time taken: %f seconds\n", time_spent);
fprintf(stderr,"Translation time taken: %f seconds\n", time_spent);
darray_free(&ast, free_parsed); darray_free(&ast, free_parsed);
#if defined(__linux__) #if defined(__linux__)
@@ -444,18 +445,10 @@ Execution execute(char *path, Stack *stack) {
gc_translated.constants.capacity = translated.constants.capacity; gc_translated.constants.capacity = translated.constants.capacity;
darray_free(&translated.bytecode, NULL); darray_free(&translated.bytecode, NULL);
free(translated.constants.data); free(translated.constants.data);
total_time_spent = (double)(clock() - beginning) / CLOCKS_PER_SEC;
start = clock(); fprintf(stderr, "total time taken loading file (%s): %f seconds\n", path,
RuntimeState state = init_runtime_state(gc_translated, path); total_time_spent);
Stack *main_scope = create_scope(stack); return gc_translated;
ArErr err = runtime(gc_translated, state, main_scope);
end = clock();
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
total_time_spent += time_spent;
fprintf(stderr,"Execution time taken: %f seconds\n", time_spent);
fprintf(stderr,"total time taken: %f seconds\n", total_time_spent);
return (Execution){err, *main_scope};
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@@ -472,11 +465,25 @@ int main(int argc, char *argv[]) {
char path[FILENAME_MAX]; char path[FILENAME_MAX];
cwk_path_get_absolute(CWD, path_non_absolute, path, sizeof(path)); cwk_path_get_absolute(CWD, path_non_absolute, path, sizeof(path));
free(CWD); free(CWD);
Execution resp = execute(path, Global_Scope); ArErr err;
Translated translated = load_argon_file(path, &err);
if (err.exists) {
output_err(err);
return 1;
}
clock_t start = clock(), end;
RuntimeState state = init_runtime_state(translated, path);
Stack *main_scope = create_scope(Global_Scope);
err = runtime(translated, state, main_scope);
end = clock();
double time_spent = (double)(end - start) / CLOCKS_PER_SEC;
fprintf(stderr, "Execution time taken: %f seconds\n", time_spent);
if (runtime_hash_table) if (runtime_hash_table)
hashmap_free(runtime_hash_table, NULL); hashmap_free(runtime_hash_table, NULL);
if (resp.err.exists) { if (err.exists) {
output_err(resp.err); output_err(err);
return 1; return 1;
} }
// Your main thread code // Your main thread code

View File

@@ -20,9 +20,4 @@ typedef struct ArErr {
char type[32]; char type[32];
char message[ERR_MSG_MAX_LEN]; char message[ERR_MSG_MAX_LEN];
} ArErr; } ArErr;
typedef struct Execution {
ArErr err;
Stack stack;
} Execution;
#endif // RETURN_TYPES_ #endif // RETURN_TYPES_

View File

@@ -8,3 +8,8 @@ let say_hi(name) = do
return "hello "+u+", how are you?" return "hello "+u+", how are you?"
term.log(say_hi("william")) term.log(say_hi("william"))
let a = 9
let b = 10
term.log(string(a)+'+'+string(b)+'='+string(a+b))