Compare commits

...

26 Commits

Author SHA1 Message Date
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
William Bell
fb8b6a89ae build for more architectures 2025-08-16 03:41:32 +01:00
William Bell
6ddf9953e7 change windows builds to tar.gz 2025-08-16 03:23:01 +01:00
William Bell
1609227a42 add bcrypt for windows 2025-08-16 03:10:50 +01:00
William Bell
51f6a88ce8 add profile to build 2025-08-16 03:00:01 +01:00
William Bell
f420273471 fix backslashes 2025-08-16 02:46:33 +01:00
William Bell
4b2a747338 use msys/flex 2025-08-16 02:36:47 +01:00
William Bell
5277814af0 fix conan 2025-08-16 02:31:15 +01:00
William Bell
8928ab2d99 add cmake as dependency 2025-08-16 02:20:57 +01:00
William Bell
d08b307c6e add python as a dependency 2025-08-16 02:12:55 +01:00
William Bell
6474329afc switch to conan for windows 2025-08-16 02:08:56 +01:00
William Bell
c49e67c839 switch windows to use conan 2025-08-16 02:04:00 +01:00
William Bell
25cb96e473 try get it to be static 2025-08-16 01:57:56 +01:00
William Bell
f11890a8b3 fix linking for linux and macos 2025-08-16 01:39:44 +01:00
William Bell
59b1d222c2 fix cmake 2025-08-16 01:32:57 +01:00
William Bell
2fba132016 make gc and gmp static and math dynamic 2025-08-16 01:22:08 +01:00
William Bell
bddc2cdc79 fix release to merge multiple 2025-08-16 01:06:06 +01:00
William Bell
e1b80b42d9 fix make release 2025-08-16 01:02:48 +01:00
William Bell
dab86925b4 fix winblows 2025-08-16 00:58:56 +01:00
William Bell
0f45052dce fix for winblows 2025-08-16 00:56:35 +01:00
William Bell
68f4207216 fix for winblows 2025-08-16 00:54:33 +01:00
9 changed files with 179 additions and 92 deletions

View File

@@ -10,7 +10,7 @@ on:
- '*' # Any tag
jobs:
build-linux:
build-linux-x86_64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@@ -51,11 +51,58 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: linux-artifact
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 g++ flex bison &&
pip install 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"
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-macos:
runs-on: macos-latest
strategy:
matrix:
arch: [x86_64, arm64] # build both architectures
steps:
- uses: actions/checkout@v3
with:
@@ -73,18 +120,38 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install conan
if [ "${{ matrix.arch }}" = "x86_64" ] && [ "$(uname -m)" = "arm64" ]; then
arch -x86_64 conan profile detect
else
conan profile detect
fi
- name: Build
run: |
conan install . --build=missing
conan build .
BUILD_DIR="build_${{ matrix.arch }}"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Use Rosetta for x86_64 builds on Apple Silicon
if [ "${{ matrix.arch }}" = "x86_64" ] && [ "$(uname -m)" = "arm64" ]; then
arch -x86_64 bash -c "
export CMAKE_OSX_ARCHITECTURES=x86_64
conan install .. --build=missing
conan build ..
"
else
export CMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}"
conan install .. --build=missing
conan build ..
fi
cd ..
- name: Package
run: |
TAG=${GITHUB_REF##refs/tags/}
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
OS="macos"
ARCH="${{ matrix.arch }}"
FOLDER="chloride-$TAG-$OS-$ARCH"
TAR="$FOLDER.tar.gz"
mv build/bin "$FOLDER"
@@ -95,7 +162,7 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: macos-artifact
name: macos-${{ matrix.arch }}-artifact
path: ${{ env.TAR_NAME }}
build-windows:
@@ -117,24 +184,33 @@ jobs:
base-devel
mingw-w64-x86_64-gcc
mingw-w64-x86_64-make
mingw-w64-x86_64-gmp
mingw-w64-x86_64-gc
mingw-w64-x86_64-cmake
mingw-w64-x86_64-python
mingw-w64-x86_64-python-pip
msys/flex
- name: Install Conan
run: |
python -m pip install --upgrade pip
pip install conan
conan profile detect
- name: Build Project
run: |
make windows
conan install . --profile mingw-profile.txt --build=missing
conan build . --profile mingw-profile.txt
- name: Package
run: |
$TAG = $env:GITHUB_REF -replace 'refs/tags/', ''
$ARCH = if ([Environment]::Is64BitOperatingSystem) { 'x64' } else { 'x86' }
$FOLDER = "chloride-$TAG-windows-$ARCH"
$ZIP = "$FOLDER.zip"
Rename-Item bin $FOLDER
Copy-Item LICENSE.txt $FOLDER
Compress-Archive -Path $FOLDER -DestinationPath $ZIP
echo "TAR_NAME=$ZIP" >> $env:GITHUB_ENV
shell: pwsh
TAG=${GITHUB_REF##refs/tags/}
OS="windows"
ARCH=$(uname -m)
FOLDER="chloride-$TAG-$OS-$ARCH"
TAR="$FOLDER.tar.gz"
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
@@ -144,12 +220,13 @@ jobs:
release:
runs-on: ubuntu-latest
needs: [build-linux, build-macos, build-windows]
needs: [build-linux-x86_64, build-linux-arm64, build-macos, build-windows]
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
merge-multiple: true
- name: Create GitHub Release
uses: ncipollo/release-action@v1

View File

@@ -52,14 +52,12 @@ find_package(BDWgc REQUIRED)
find_package(gmp REQUIRED)
target_compile_options(argon PRIVATE -O3 -Wall -Wextra -Wno-unused-function -s)
if(NOT APPLE)
target_link_options(argon PRIVATE -static)
endif()
target_link_libraries(argon PRIVATE
BDWgc::BDWgc
gmp::gmp
m
$<$<PLATFORM_ID:Windows>:bcrypt>
)
target_include_directories(argon PRIVATE

View File

@@ -12,6 +12,7 @@ LEXER_SRC = src/lexer/lex.l
LEXER_C = src/lexer/lex.yy.c
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
LDFLAGS = -lgc -lgmp -lm
all: $(BINARY)
@@ -21,16 +22,11 @@ $(LEXER_C) $(LEXER_H): $(LEXER_SRC)
$(BINARY): $(CFILES) $(LEXER_C) $(LEXER_H)
mkdir -p bin
gcc -O3 -o $(BINARY) $(CFILES) $(CFLAGS) -s
windows: $(CFILES) $(LEXER_C) $(LEXER_H)
find external/xxhash external/cwalk external/libdye src -name '*.c' > sources.txt
mkdir -p bin
gcc -O3 -march=native -o $(BINARY) @sources.txt $(CFLAGS)
gcc -O3 -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS} -s
native: $(CFILES) $(LEXER_C) $(LEXER_H)
mkdir -p bin
gcc -O3 -march=native -o $(BINARY) $(CFILES) $(CFLAGS)
gcc -O3 -march=native -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}
debug: $(CFILES) $(LEXER_C) $(LEXER_H)
mkdir -p bin
@@ -38,13 +34,13 @@ debug: $(CFILES) $(LEXER_C) $(LEXER_H)
full-debug: $(CFILES) $(LEXER_C) $(LEXER_H)
mkdir -p bin
gcc -g -O0 -fsanitize=address -fno-omit-frame-pointer -o $(BINARY) $(CFILES) $(CFLAGS)
gcc -g -O0 -fsanitize=address -fno-omit-frame-pointer -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}
optimised: $(CFILES) $(LEXER_C) $(LEXER_H)
mkdir -p bin
gcc -O3 -fprofile-generate -o $(BINARY) $(CFILES) $(CFLAGS)
gcc -O3 -fprofile-generate -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}
${BINARY} rand_test.ar
gcc -O3 -fprofile-use -o $(BINARY) $(CFILES) $(CFLAGS)
gcc -O3 -fprofile-use -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}
clean:

View File

@@ -33,11 +33,6 @@ class ArgonConan(ConanFile):
os.environ["CONAN_NON_INTERACTIVE"] = "1"
tc = CMakeToolchain(self)
if os.name == "nt": # Windows
flex_path = which("win_flex") or which("win_flex.exe")
if not flex_path:
raise Exception("win_flex not found in PATH. Install winflexbison via choco.")
else:
flex_path = which("flex")
if not flex_path:
raise Exception("Flex not found in system PATH. Please install flex on Linux/macOS.")

12
mingw-profile.txt Normal file
View File

@@ -0,0 +1,12 @@
[settings]
os=Windows
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.threads=posix
compiler.exception=seh
arch=x86_64
build_type=Release
[tool_requires]
mingw-builds/12.2.0

View File

@@ -11,6 +11,7 @@
#include "lexer/token.h"
#include "memory.h"
#include "parser/parser.h"
#include "returnTypes.h"
#include "runtime/runtime.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 le64toh(x) OSSwapLittleToHostInt64(x)
// Add others as needed
#else
#error "Unsupported platform"
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
#include <stdlib.h>
#include <sys/endian.h>
#endif
char *get_current_directory() {
@@ -277,18 +279,20 @@ FAILED:
return 1;
}
Execution execute(char *path, Stack *stack) {
Translated load_argon_file(char *path, ArErr *err) {
clock_t start, end;
clock_t beginning = clock();
double time_spent, total_time_spent = 0;
const char *basename_ptr;
size_t basename_length;
cwk_path_get_basename(path, &basename_ptr, &basename_length);
if (!basename_ptr)
return (Execution){create_err(0, 0, 0, NULL, "Path Error",
"path has no basename '%s'", path),
(Stack){NULL, NULL}};
if (!basename_ptr) {
*err = create_err(0, 0, 0, NULL, "Path Error", "path has no basename '%s'",
path);
return (Translated){};
}
char basename[FILENAME_MAX];
memcpy(basename, basename_ptr, basename_length);
@@ -312,9 +316,9 @@ Execution execute(char *path, Stack *stack) {
FILE *file = fopen(path, "r");
if (!file) {
return (Execution){create_err(0, 0, 0, NULL, "File Error",
"Unable to open file '%s'", path),
(Stack){NULL, NULL}};
*err = create_err(0, 0, 0, NULL, "File Error", "Unable to open file '%s'",
path);
return (Translated){};
}
XXH3_state_t *hash_state = XXH3_createState();
@@ -338,14 +342,13 @@ Execution execute(char *path, Stack *stack) {
LexerState state = {path, file, 0, 0, &tokens};
start = clock();
ArErr err = lexer(state);
if (err.exists) {
*err = lexer(state);
if (err->exists) {
darray_free(&tokens, free_token);
return (Execution){err, (Stack){NULL, NULL}};
return (Translated){};
}
end = clock();
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
total_time_spent += time_spent;
fprintf(stderr, "Lexer time taken: %f seconds\n", time_spent);
fclose(state.file);
@@ -354,32 +357,30 @@ Execution execute(char *path, Stack *stack) {
darray_init(&ast, sizeof(ParsedValue));
start = clock();
err = parser(path, &ast, &tokens, false);
if (err.exists) {
*err = parser(path, &ast, &tokens, false);
if (err->exists) {
darray_free(&tokens, free_token);
darray_free(&ast, free_parsed);
return (Execution){err, (Stack){NULL, NULL}};
return (Translated){};
}
end = clock();
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
total_time_spent += time_spent;
fprintf(stderr, "Parser time taken: %f seconds\n", time_spent);
darray_free(&tokens, free_token);
start = clock();
translated = init_translator(path);
err = translate(&translated, &ast);
if (err.exists) {
*err = translate(&translated, &ast);
if (err->exists) {
darray_free(&translated.bytecode, NULL);
free(translated.constants.data);
hashmap_free(translated.constants.hashmap, NULL);
darray_free(&ast, free_parsed);
return (Execution){err, (Stack){NULL, NULL}};
return (Translated){};
}
end = clock();
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
total_time_spent += time_spent;
fprintf(stderr, "Translation time taken: %f seconds\n", time_spent);
darray_free(&ast, free_parsed);
@@ -444,18 +445,10 @@ Execution execute(char *path, Stack *stack) {
gc_translated.constants.capacity = translated.constants.capacity;
darray_free(&translated.bytecode, NULL);
free(translated.constants.data);
start = clock();
RuntimeState state = init_runtime_state(gc_translated, path);
Stack *main_scope = create_scope(stack);
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};
total_time_spent = (double)(clock() - beginning) / CLOCKS_PER_SEC;
fprintf(stderr, "total time taken loading file (%s): %f seconds\n", path,
total_time_spent);
return gc_translated;
}
int main(int argc, char *argv[]) {
@@ -472,11 +465,25 @@ int main(int argc, char *argv[]) {
char path[FILENAME_MAX];
cwk_path_get_absolute(CWD, path_non_absolute, path, sizeof(path));
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)
hashmap_free(runtime_hash_table, NULL);
if (resp.err.exists) {
output_err(resp.err);
if (err.exists) {
output_err(err);
return 1;
}
// Your main thread code

View File

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

View File

@@ -16,7 +16,9 @@
#include <string.h>
#if defined(_WIN32)
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0602
#endif
#include <windows.h>
#include <psapi.h>

View File

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