Compare commits
14 Commits
prerelease
...
release-v4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47db2ca27d | ||
|
|
2e7b3b4baa | ||
|
|
24163e3389 | ||
|
|
0c0832d131 | ||
|
|
1742a0c52d | ||
|
|
224039ba43 | ||
|
|
5e7ce495e4 | ||
|
|
35a0f35cf8 | ||
|
|
f9490ceac0 | ||
|
|
4cda311008 | ||
|
|
b3aa653076 | ||
|
|
fc3321bcf0 | ||
|
|
868b3bfc3d | ||
|
|
f5e241aba0 |
45
.github/workflows/release.yml
vendored
45
.github/workflows/release.yml
vendored
@@ -11,7 +11,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-linux-x86_64:
|
build-linux-x86_64:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest # build both architectures
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
@@ -51,40 +51,39 @@ jobs:
|
|||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: linux-${{ matrix.arch }}-artifact
|
name: linux-x86_64-artifact
|
||||||
path: ${{ env.TAR_NAME }}
|
path: ${{ env.TAR_NAME }}
|
||||||
|
|
||||||
build-linux-arm64:
|
build-linux-arm64:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04-arm # build both architectures
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Install build tools
|
||||||
uses: docker/setup-qemu-action@v3
|
run: sudo apt-get update && sudo apt-get install -y flex bison
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Setup Python
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
- name: Run build in arm64 container
|
- name: Install Conan
|
||||||
run: |
|
run: |
|
||||||
docker run --rm --platform linux/arm64 \
|
python -m pip install --upgrade pip
|
||||||
-v $PWD:/work -w /work \
|
pip install conan
|
||||||
ubuntu:latest \
|
conan profile detect
|
||||||
bash -c "
|
|
||||||
apt-get update && apt-get install -y python3-pip g++ flex bison &&
|
- name: Build
|
||||||
pip install --break-system-packages conan &&
|
run: |
|
||||||
conan profile detect --force &&
|
conan install . --build=missing
|
||||||
conan install . --build=missing &&
|
conan build .
|
||||||
conan build .
|
|
||||||
"
|
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
run: |
|
run: |
|
||||||
TAG=${GITHUB_REF##refs/tags/}
|
TAG=${GITHUB_REF##refs/tags/}
|
||||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
ARCH=arm64
|
ARCH=$(uname -m)
|
||||||
FOLDER="chloride-$TAG-$OS-$ARCH"
|
FOLDER="chloride-$TAG-$OS-$ARCH"
|
||||||
TAR="$FOLDER.tar.gz"
|
TAR="$FOLDER.tar.gz"
|
||||||
mv build/bin "$FOLDER"
|
mv build/bin "$FOLDER"
|
||||||
@@ -95,7 +94,7 @@ jobs:
|
|||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: linux-${{ matrix.arch }}-artifact
|
name: linux-arm64-artifact
|
||||||
path: ${{ env.TAR_NAME }}
|
path: ${{ env.TAR_NAME }}
|
||||||
|
|
||||||
build-macos:
|
build-macos:
|
||||||
@@ -197,8 +196,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Build Project
|
- name: Build Project
|
||||||
run: |
|
run: |
|
||||||
conan install . --profile mingw-profile.txt --build=missing
|
conan install . --profile windows-profile.txt --build=missing
|
||||||
conan build . --profile mingw-profile.txt
|
conan build . --profile windows-profile.txt
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -11,3 +11,6 @@
|
|||||||
[submodule "external/libdye"]
|
[submodule "external/libdye"]
|
||||||
path = external/libdye
|
path = external/libdye
|
||||||
url = https://github.com/Ugric/libdye.git
|
url = https://github.com/Ugric/libdye.git
|
||||||
|
[submodule "external/linenoise"]
|
||||||
|
path = external/linenoise
|
||||||
|
url = https://github.com/antirez/linenoise
|
||||||
|
|||||||
@@ -33,8 +33,16 @@ add_custom_command(
|
|||||||
# Step 2: Custom target for lexer
|
# Step 2: Custom target for lexer
|
||||||
add_custom_target(GenerateLexer DEPENDS ${LEXER_C} ${LEXER_H})
|
add_custom_target(GenerateLexer DEPENDS ${LEXER_C} ${LEXER_H})
|
||||||
|
|
||||||
|
set(SOURCES
|
||||||
|
external/xxhash/xxhash.c external/cwalk/src/cwalk.c external/libdye/src/dye.c ${CFILES} ${LEXER_C}
|
||||||
|
)
|
||||||
|
|
||||||
|
if(NOT WIN32)
|
||||||
|
list(APPEND SOURCES external/linenoise/linenoise.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Step 3: Add executable
|
# Step 3: Add executable
|
||||||
add_executable(argon external/xxhash/xxhash.c external/cwalk/src/cwalk.c external/libdye/src/dye.c ${CFILES} ${LEXER_C})
|
add_executable(argon ${SOURCES})
|
||||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
target_include_directories(argon PRIVATE ${CMAKE_SOURCE_DIR}/external/cwalk/include)
|
target_include_directories(argon PRIVATE ${CMAKE_SOURCE_DIR}/external/cwalk/include)
|
||||||
target_include_directories(argon PRIVATE ${CMAKE_SOURCE_DIR}/external/libdye/include)
|
target_include_directories(argon PRIVATE ${CMAKE_SOURCE_DIR}/external/libdye/include)
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -6,7 +6,7 @@
|
|||||||
BINARY = bin/argon
|
BINARY = bin/argon
|
||||||
FLEX_TOOL = flex
|
FLEX_TOOL = flex
|
||||||
|
|
||||||
CFILES = external/xxhash/xxhash.c external/cwalk/src/cwalk.c external/libdye/src/dye.c $(shell find src -name '*.c')
|
CFILES = external/xxhash/xxhash.c external/cwalk/src/cwalk.c external/libdye/src/dye.c external/linenoise/linenoise.c $(shell find src -name '*.c')
|
||||||
|
|
||||||
LEXER_SRC = src/lexer/lex.l
|
LEXER_SRC = src/lexer/lex.l
|
||||||
LEXER_C = src/lexer/lex.yy.c
|
LEXER_C = src/lexer/lex.yy.c
|
||||||
|
|||||||
1
external/linenoise
vendored
Submodule
1
external/linenoise
vendored
Submodule
Submodule external/linenoise added at d895173d67
12
src/main.c
12
src/main.c
@@ -12,6 +12,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "parser/parser.h"
|
#include "parser/parser.h"
|
||||||
#include "returnTypes.h"
|
#include "returnTypes.h"
|
||||||
|
#include "shell.h"
|
||||||
#include "runtime/runtime.h"
|
#include "runtime/runtime.h"
|
||||||
#include "translator/translator.h"
|
#include "translator/translator.h"
|
||||||
|
|
||||||
@@ -358,32 +359,29 @@ Translated load_argon_file(char *path, ArErr *err) {
|
|||||||
|
|
||||||
start = clock();
|
start = clock();
|
||||||
*err = parser(path, &ast, &tokens, false);
|
*err = parser(path, &ast, &tokens, false);
|
||||||
|
darray_free(&tokens, free_token);
|
||||||
if (err->exists) {
|
if (err->exists) {
|
||||||
darray_free(&tokens, free_token);
|
|
||||||
darray_free(&ast, free_parsed);
|
darray_free(&ast, free_parsed);
|
||||||
return (Translated){};
|
return (Translated){};
|
||||||
}
|
}
|
||||||
end = clock();
|
end = clock();
|
||||||
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||||
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);
|
|
||||||
|
|
||||||
start = clock();
|
start = clock();
|
||||||
|
|
||||||
translated = init_translator(path);
|
translated = init_translator(path);
|
||||||
*err = translate(&translated, &ast);
|
*err = translate(&translated, &ast);
|
||||||
|
darray_free(&ast, free_parsed);
|
||||||
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);
|
|
||||||
return (Translated){};
|
return (Translated){};
|
||||||
}
|
}
|
||||||
end = clock();
|
end = clock();
|
||||||
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
time_spent = (double)(end - start) / CLOCKS_PER_SEC;
|
||||||
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);
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
malloc_trim(0);
|
malloc_trim(0);
|
||||||
#endif
|
#endif
|
||||||
@@ -458,9 +456,9 @@ int main(int argc, char *argv[]) {
|
|||||||
generate_siphash_key(siphash_key);
|
generate_siphash_key(siphash_key);
|
||||||
bootstrap_types();
|
bootstrap_types();
|
||||||
bootstrap_globals();
|
bootstrap_globals();
|
||||||
char *CWD = get_current_directory();
|
|
||||||
if (argc <= 1)
|
if (argc <= 1)
|
||||||
return -1;
|
return shell();
|
||||||
|
char *CWD = get_current_directory();
|
||||||
char *path_non_absolute = argv[1];
|
char *path_non_absolute = argv[1];
|
||||||
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));
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "../../memory.h"
|
#include "../../memory.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
#include <gmp.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -180,7 +179,8 @@ ParsedValueReturn parse_number(Token *token, char *path) {
|
|||||||
mpq_init(*r_ptr);
|
mpq_init(*r_ptr);
|
||||||
int err = mpq_set_decimal_str_exp(*r_ptr, token->value, token->length);
|
int err = mpq_set_decimal_str_exp(*r_ptr, token->value, token->length);
|
||||||
if (err) {
|
if (err) {
|
||||||
free_parsed(parsedValue);
|
mpq_clear(*r_ptr);
|
||||||
|
free(r_ptr);
|
||||||
free(parsedValue);
|
free(parsedValue);
|
||||||
return (ParsedValueReturn){create_err(token->line, token->column,
|
return (ParsedValueReturn){create_err(token->line, token->column,
|
||||||
token->length, path, "Parsing Error",
|
token->length, path, "Parsing Error",
|
||||||
@@ -190,3 +190,4 @@ ParsedValueReturn parse_number(Token *token, char *path) {
|
|||||||
parsedValue->data = r_ptr;
|
parsedValue->data = r_ptr;
|
||||||
return (ParsedValueReturn){no_err, parsedValue};
|
return (ParsedValueReturn){no_err, parsedValue};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
264
src/shell.c
Normal file
264
src/shell.c
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2025 William Bell
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
#else
|
||||||
|
#include "../external/linenoise/linenoise.h"
|
||||||
|
#endif
|
||||||
|
#include "./lexer/lexer.h"
|
||||||
|
#include "./runtime/call/call.h"
|
||||||
|
#include "./runtime/objects/functions/functions.h"
|
||||||
|
#include "./runtime/objects/term/term.h"
|
||||||
|
#include "./runtime/runtime.h"
|
||||||
|
#include "./translator/translator.h"
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#if defined(__linux__)
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
volatile sig_atomic_t interrupted = 0;
|
||||||
|
|
||||||
|
// Ctrl+C handler
|
||||||
|
void handle_sigint(int sig) {
|
||||||
|
(void)sig;
|
||||||
|
interrupted = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int execute_code(FILE *stream, char *path, Stack *scope,
|
||||||
|
RuntimeState *runtime_state) {
|
||||||
|
if (!stream) {
|
||||||
|
perror("fmemopen");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArErr err;
|
||||||
|
|
||||||
|
DArray tokens;
|
||||||
|
darray_init(&tokens, sizeof(Token));
|
||||||
|
LexerState state = {path, stream, 0, 0, &tokens};
|
||||||
|
err = lexer(state);
|
||||||
|
if (err.exists) {
|
||||||
|
darray_free(&tokens, free_token);
|
||||||
|
output_err(err);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DArray ast;
|
||||||
|
|
||||||
|
darray_init(&ast, sizeof(ParsedValue));
|
||||||
|
|
||||||
|
err = parser(path, &ast, &tokens, false);
|
||||||
|
darray_free(&tokens, free_token);
|
||||||
|
if (err.exists) {
|
||||||
|
darray_free(&ast, free_parsed);
|
||||||
|
output_err(err);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Translated __translated = init_translator(path);
|
||||||
|
err = translate(&__translated, &ast);
|
||||||
|
darray_free(&ast, free_parsed);
|
||||||
|
if (err.exists) {
|
||||||
|
darray_free(&__translated.bytecode, NULL);
|
||||||
|
free(__translated.constants.data);
|
||||||
|
hashmap_free(__translated.constants.hashmap, NULL);
|
||||||
|
output_err(err);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hashmap_free(__translated.constants.hashmap, NULL);
|
||||||
|
Translated translated = {
|
||||||
|
__translated.registerCount, NULL, {}, {}, __translated.path};
|
||||||
|
translated.bytecode.data = ar_alloc(__translated.bytecode.capacity);
|
||||||
|
memcpy(translated.bytecode.data, __translated.bytecode.data,
|
||||||
|
__translated.bytecode.capacity);
|
||||||
|
translated.bytecode.element_size = __translated.bytecode.element_size;
|
||||||
|
translated.bytecode.size = __translated.bytecode.size;
|
||||||
|
translated.bytecode.resizable = false;
|
||||||
|
translated.bytecode.capacity =
|
||||||
|
__translated.bytecode.size * __translated.bytecode.element_size;
|
||||||
|
translated.constants.data = ar_alloc(__translated.constants.capacity);
|
||||||
|
memcpy(translated.constants.data, __translated.constants.data,
|
||||||
|
__translated.constants.capacity);
|
||||||
|
translated.constants.size = __translated.constants.size;
|
||||||
|
translated.constants.capacity = __translated.constants.capacity;
|
||||||
|
darray_free(&__translated.bytecode, NULL);
|
||||||
|
free(__translated.constants.data);
|
||||||
|
*runtime_state = init_runtime_state(translated, path);
|
||||||
|
err = runtime(translated, *runtime_state, scope);
|
||||||
|
if (err.exists) {
|
||||||
|
output_err(err);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
// Simple input function
|
||||||
|
char *input(const char *prompt) {
|
||||||
|
printf("%s", prompt);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
char *buffer = NULL;
|
||||||
|
size_t size = 0;
|
||||||
|
ssize_t len = getline(&buffer, &size, stdin);
|
||||||
|
|
||||||
|
if (len == -1) {
|
||||||
|
free(buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove trailing newline
|
||||||
|
if (len > 0 && buffer[len - 1] == '\n') {
|
||||||
|
buffer[len - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *read_all_stdin(size_t *out_len) {
|
||||||
|
size_t size = 1024;
|
||||||
|
size_t len = 0;
|
||||||
|
char *buffer = malloc(size);
|
||||||
|
if (!buffer)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
int c;
|
||||||
|
while ((c = fgetc(stdin)) != EOF) {
|
||||||
|
if (len + 1 >= size) {
|
||||||
|
size *= 2;
|
||||||
|
buffer = realloc(buffer, size);
|
||||||
|
if (!buffer)
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
buffer[len++] = (char)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_len = len;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
int shell() {
|
||||||
|
|
||||||
|
Stack *main_scope = create_scope(Global_Scope);
|
||||||
|
|
||||||
|
if (!isatty(STDIN_FILENO)) {
|
||||||
|
RuntimeState runtime_state;
|
||||||
|
size_t len;
|
||||||
|
char *data = read_all_stdin(&len);
|
||||||
|
FILE *file = fmemopen(data, len, "r");
|
||||||
|
int resp = execute_code(file, "<stdin>", main_scope, &runtime_state);
|
||||||
|
fclose(file);
|
||||||
|
free(data);
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
signal(SIGINT, handle_sigint);
|
||||||
|
|
||||||
|
printf("Welcome to the Argon shell!\n\n");
|
||||||
|
|
||||||
|
ArgonObject *output_object = create_argon_native_function("log", term_log);
|
||||||
|
char *totranslate = NULL;
|
||||||
|
size_t totranslatelength = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
#if defined(__linux__)
|
||||||
|
malloc_trim(0);
|
||||||
|
#endif
|
||||||
|
if (totranslate) {
|
||||||
|
free(totranslate);
|
||||||
|
totranslate = NULL;
|
||||||
|
totranslatelength = 0;
|
||||||
|
};
|
||||||
|
int indent = 0;
|
||||||
|
char textBefore[] = ">>> ";
|
||||||
|
|
||||||
|
// Dynamic array of lines
|
||||||
|
|
||||||
|
do {
|
||||||
|
// indent string
|
||||||
|
size_t isz = (size_t)indent * 4;
|
||||||
|
char *indentStr = (char *)malloc(isz + 1);
|
||||||
|
if (!indentStr)
|
||||||
|
exit(1);
|
||||||
|
memset(indentStr, ' ', isz);
|
||||||
|
indentStr[isz] = '\0';
|
||||||
|
|
||||||
|
// prompt
|
||||||
|
size_t p_len = strlen(textBefore) + isz;
|
||||||
|
char *prompt = (char *)malloc(p_len + 1);
|
||||||
|
if (!prompt)
|
||||||
|
exit(1);
|
||||||
|
memcpy(prompt, textBefore, strlen(textBefore));
|
||||||
|
memcpy(prompt + strlen(textBefore), indentStr, isz + 1);
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
char *inp = input(prompt);
|
||||||
|
#else
|
||||||
|
char *inp = linenoise(prompt);
|
||||||
|
#endif
|
||||||
|
free(prompt);
|
||||||
|
|
||||||
|
if (!inp) {
|
||||||
|
printf("\nBye :)\n");
|
||||||
|
// Free previously collected lines
|
||||||
|
free(inp);
|
||||||
|
free(totranslate);
|
||||||
|
free(indentStr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
#else
|
||||||
|
if (inp[0] != '\0') {
|
||||||
|
// Optionally add line to history
|
||||||
|
linenoiseHistoryAdd(inp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Append line to totranslate
|
||||||
|
size_t length = strlen(inp);
|
||||||
|
totranslate = realloc(totranslate, totranslatelength + isz + length + 1);
|
||||||
|
memcpy(totranslate + totranslatelength, indentStr, isz);
|
||||||
|
memcpy(totranslate + totranslatelength + isz, inp, length);
|
||||||
|
totranslatelength += isz + length + 1;
|
||||||
|
totranslate[totranslatelength - 1] = '\n';
|
||||||
|
|
||||||
|
char *trimmed = inp;
|
||||||
|
while (*trimmed == ' ' || *trimmed == '\t')
|
||||||
|
trimmed++;
|
||||||
|
|
||||||
|
size_t len = strlen(trimmed);
|
||||||
|
if (len >= 2 && strcmp(trimmed + len - 2, "do") == 0) {
|
||||||
|
indent++;
|
||||||
|
} else if (len == 0 && indent > 0) {
|
||||||
|
indent--;
|
||||||
|
}
|
||||||
|
free(inp);
|
||||||
|
strcpy(textBefore, "... ");
|
||||||
|
free(indentStr);
|
||||||
|
|
||||||
|
} while (indent > 0);
|
||||||
|
totranslate = realloc(totranslate, totranslatelength + 1);
|
||||||
|
totranslate[totranslatelength] = '\0';
|
||||||
|
RuntimeState runtime_state;
|
||||||
|
FILE *file = fmemopen((void *)totranslate, totranslatelength, "r");
|
||||||
|
int resp = execute_code(file, "<shell>", main_scope, &runtime_state);
|
||||||
|
fclose(file);
|
||||||
|
if (resp) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ArErr err;
|
||||||
|
argon_call(output_object, 1, (ArgonObject *[]){runtime_state.registers[0]},
|
||||||
|
&err, &runtime_state);
|
||||||
|
totranslatelength = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
12
src/shell.h
Normal file
12
src/shell.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2025 William Bell
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ARGON_SHELL_H
|
||||||
|
#define ARGON_SHELL_H
|
||||||
|
|
||||||
|
int shell();
|
||||||
|
|
||||||
|
#endif // ARGON_SHELL_H
|
||||||
Reference in New Issue
Block a user