add license to shell
This commit is contained in:
54
Makefile
54
Makefile
@@ -2,46 +2,52 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# Default FLEX tool
|
|
||||||
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 external/linenoise/linenoise.c $(shell find src -name '*.c')
|
SRC_DIRS = src external/xxhash external/cwalk/src external/libdye/src external/linenoise
|
||||||
|
CFILES = $(shell find $(SRC_DIRS) -name '*.c' \
|
||||||
|
! -path "*/tests/*" \
|
||||||
|
! -path "*/fuzz/*" \
|
||||||
|
! -path "*/cli/*" \
|
||||||
|
! -path "*/example*") \
|
||||||
|
$(LEXER_C)
|
||||||
|
OBJDIR = build
|
||||||
|
OBJS = $(CFILES:%.c=$(OBJDIR)/%.o)
|
||||||
|
|
||||||
LEXER_SRC = src/lexer/lex.l
|
CFLAGS = $(ARCHFLAGS) -Wall -Wextra -Wno-unused-function -Werror=unused-result \
|
||||||
LEXER_C = src/lexer/lex.yy.c
|
-Iexternal/cwalk/include -Iexternal/libdye/include
|
||||||
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
|
LDFLAGS = -lgc -lgmp -lm
|
||||||
|
|
||||||
all: $(BINARY)
|
all: $(BINARY)
|
||||||
|
|
||||||
|
# Rule to build lexer
|
||||||
$(LEXER_C) $(LEXER_H): $(LEXER_SRC)
|
$(LEXER_C) $(LEXER_H): $(LEXER_SRC)
|
||||||
$(FLEX_TOOL) --header-file=$(LEXER_H) -o $(LEXER_C) $(LEXER_SRC)
|
$(FLEX_TOOL) --header-file=$(LEXER_H) -o $(LEXER_C) $(LEXER_SRC)
|
||||||
|
|
||||||
$(BINARY): $(CFILES) $(LEXER_C) $(LEXER_H)
|
# Pattern rule for compiling .c -> .o
|
||||||
mkdir -p bin
|
$(OBJDIR)/%.o: %.c $(LEXER_C) $(LEXER_H)
|
||||||
gcc -O3 -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS} -s
|
@mkdir -p $(dir $@)
|
||||||
|
gcc -O3 -c $< -o $@ $(CFLAGS)
|
||||||
|
|
||||||
native: $(CFILES) $(LEXER_C) $(LEXER_H)
|
# Link final binary
|
||||||
mkdir -p bin
|
$(BINARY): $(OBJS)
|
||||||
gcc -O3 -march=native -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}
|
@mkdir -p bin
|
||||||
|
gcc -o $@ $^ $(CFLAGS) $(LDFLAGS) -s
|
||||||
|
|
||||||
debug: $(CFILES) $(LEXER_C) $(LEXER_H)
|
native: CFLAGS += -march=native
|
||||||
mkdir -p bin
|
native: $(BINARY)
|
||||||
gcc -g -O3 -o $(BINARY) $(CFILES) $(CFLAGS)
|
|
||||||
|
|
||||||
full-debug: $(CFILES) $(LEXER_C) $(LEXER_H)
|
debug: CFLAGS += -g
|
||||||
mkdir -p bin
|
debug: $(BINARY)
|
||||||
gcc -g -O3 -fsanitize=address -fno-omit-frame-pointer -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}
|
|
||||||
|
|
||||||
optimised: $(CFILES) $(LEXER_C) $(LEXER_H)
|
full-debug: CFLAGS += -g -fsanitize=address -fno-omit-frame-pointer
|
||||||
mkdir -p bin
|
full-debug: $(BINARY)
|
||||||
gcc -O3 -fprofile-generate -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}
|
|
||||||
|
optimised: CFLAGS += -fprofile-generate
|
||||||
|
optimised: $(BINARY)
|
||||||
${BINARY} rand_test.ar
|
${BINARY} rand_test.ar
|
||||||
gcc -O3 -fprofile-use -o $(BINARY) $(CFILES) $(CFLAGS) ${LDFLAGS}
|
$(MAKE) CFLAGS="$(CFLAGS:-fprofile-generate=-fprofile-use)" $(BINARY)
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build bin
|
rm -rf build bin
|
||||||
|
|||||||
2893
src/LICENSE_c.h
Normal file
2893
src/LICENSE_c.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@
|
|||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "../external/libdye/include/dye.h"
|
#include "../external/libdye/include/dye.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@@ -14,7 +15,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
|
ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||||
@@ -61,13 +61,13 @@ ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const ArErr no_err = (ArErr){false};
|
const ArErr no_err = (ArErr){"", "", "", 0, 0, 0, false};
|
||||||
|
|
||||||
ArErr create_err(int64_t line, int64_t column, int length, char *path,
|
ArErr create_err(int64_t line, int64_t column, int length, char *path,
|
||||||
const char *type, const char *fmt, ...) {
|
const char *type, const char *fmt, ...) {
|
||||||
ArErr err;
|
ArErr err;
|
||||||
err.exists = true;
|
err.exists = true;
|
||||||
err.path = path;
|
strcpy(err.path, path);
|
||||||
err.line = line;
|
err.line = line;
|
||||||
err.column = column;
|
err.column = column;
|
||||||
err.length = length;
|
err.length = length;
|
||||||
@@ -103,7 +103,7 @@ void output_err(ArErr err) {
|
|||||||
dyefg(stderr, DYE_RESET);
|
dyefg(stderr, DYE_RESET);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
if (err.path && err.line) {
|
if (strlen(err.path) && err.line) {
|
||||||
dyefg(stderr, DYE_GRAY);
|
dyefg(stderr, DYE_GRAY);
|
||||||
fprintf(stderr, " --> ");
|
fprintf(stderr, " --> ");
|
||||||
dyefg(stderr, DYE_CYAN);
|
dyefg(stderr, DYE_CYAN);
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ const char CACHE_FOLDER[] = "__arcache__";
|
|||||||
const char FILE_IDENTIFIER[5] = "ARBI";
|
const char FILE_IDENTIFIER[5] = "ARBI";
|
||||||
const char BYTECODE_EXTENTION[] = "arbin";
|
const char BYTECODE_EXTENTION[] = "arbin";
|
||||||
const uint32_t version_number = 0;
|
const uint32_t version_number = 0;
|
||||||
|
const char version_string[] = "4.0.0";
|
||||||
|
|
||||||
bool file_exists(const char *path) {
|
bool file_exists(const char *path) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
extern char*CWD;
|
extern char*CWD;
|
||||||
|
|
||||||
|
extern const char version_string[];
|
||||||
|
|
||||||
Stack *ar_import(char *current_directory, char *path_relative, ArErr *err);
|
Stack *ar_import(char *current_directory, char *path_relative, ArErr *err);
|
||||||
|
|
||||||
#endif // IMPORT_H
|
#endif // IMPORT_H
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "hashmap/hashmap.h"
|
#include "hashmap/hashmap.h"
|
||||||
#include "import.h"
|
#include "import.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "runtime/objects/object.h"
|
#include "runtime/runtime.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
|
||||||
#include "hash_data/hash_data.h"
|
#include "hash_data/hash_data.h"
|
||||||
@@ -65,6 +65,7 @@ int main(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
free(CWD);
|
free(CWD);
|
||||||
|
ar_memory_shutdown();
|
||||||
if (runtime_hash_table)
|
if (runtime_hash_table)
|
||||||
hashmap_free(runtime_hash_table, NULL);
|
hashmap_free(runtime_hash_table, NULL);
|
||||||
if (err.exists) {
|
if (err.exists) {
|
||||||
|
|||||||
27
src/memory.c
27
src/memory.c
@@ -7,10 +7,11 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include <gc.h>
|
#include <gc.h>
|
||||||
#include <gc/gc.h>
|
#include <gc/gc.h>
|
||||||
#include <gmp.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h> // for malloc/free (temp arena fallback)
|
#include <stdlib.h> // for malloc/free (temp arena fallback)
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
void *checked_malloc(size_t size) {
|
void *checked_malloc(size_t size) {
|
||||||
void *ptr = malloc(size);
|
void *ptr = malloc(size);
|
||||||
@@ -21,19 +22,23 @@ void *checked_malloc(size_t size) {
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *gmp_gc_realloc(void *ptr, size_t old_size, size_t new_size) {
|
struct allocation*memory_allocations = NULL;
|
||||||
(void)old_size; // Ignore old_size, Boehm doesn't need it
|
size_t memory_allocations_size = 0;
|
||||||
return GC_realloc(ptr, new_size);
|
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
}
|
|
||||||
|
|
||||||
void gmp_gc_free(void *ptr, size_t size) {
|
|
||||||
(void)size; // Boehm GC manages this itself
|
|
||||||
// No-op — memory will be collected automatically
|
|
||||||
GC_FREE(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ar_memory_init() {
|
void ar_memory_init() {
|
||||||
GC_INIT();
|
GC_INIT();
|
||||||
|
// memory_allocations_size = 8;
|
||||||
|
// memory_allocations = malloc(memory_allocations_size*sizeof(struct allocation));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ar_memory_shutdown() {
|
||||||
|
// for (size_t i = 0; i<memory_allocations_size;i++) {
|
||||||
|
// if (memory_allocations[i].status != allocation_fully_freed) {
|
||||||
|
// free(memory_allocations[i].ptr);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// free(memory_allocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ar_alloc(size_t size) { return GC_MALLOC(size); }
|
void *ar_alloc(size_t size) { return GC_MALLOC(size); }
|
||||||
|
|||||||
14
src/memory.h
14
src/memory.h
@@ -8,10 +8,23 @@
|
|||||||
#define ARGON_MEMORY_H
|
#define ARGON_MEMORY_H
|
||||||
|
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // for size_t
|
||||||
|
#include <stdbool.h>
|
||||||
#include <gc/gc.h>
|
#include <gc/gc.h>
|
||||||
|
|
||||||
// GC-managed allocations
|
// GC-managed allocations
|
||||||
|
|
||||||
|
typedef enum allocation_status {
|
||||||
|
allocation_used,
|
||||||
|
allocation_soft_free, // avaiable for use, since it hasnt been freed but isnt in use.
|
||||||
|
allocation_fully_freed,
|
||||||
|
} allocation_status;
|
||||||
|
|
||||||
|
struct allocation {
|
||||||
|
void*ptr;
|
||||||
|
size_t size;
|
||||||
|
allocation_status status;
|
||||||
|
};
|
||||||
|
|
||||||
void ar_finalizer(void *obj, GC_finalization_proc fn, void *client_data,
|
void ar_finalizer(void *obj, GC_finalization_proc fn, void *client_data,
|
||||||
GC_finalization_proc *old_fn, void **old_client_data);
|
GC_finalization_proc *old_fn, void **old_client_data);
|
||||||
void *ar_alloc(size_t size);
|
void *ar_alloc(size_t size);
|
||||||
@@ -21,6 +34,7 @@ char *ar_strdup(const char *str);
|
|||||||
|
|
||||||
// Memory init/shutdown
|
// Memory init/shutdown
|
||||||
void ar_memory_init();
|
void ar_memory_init();
|
||||||
|
void ar_memory_shutdown();
|
||||||
|
|
||||||
void *checked_malloc(size_t size);
|
void *checked_malloc(size_t size);
|
||||||
|
|
||||||
|
|||||||
@@ -8,16 +8,16 @@
|
|||||||
#define RETURN_TYPES_H
|
#define RETURN_TYPES_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "arobject.h"
|
#include "arobject.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define ERR_MSG_MAX_LEN 32
|
|
||||||
|
|
||||||
typedef struct ArErr {
|
typedef struct ArErr {
|
||||||
char *path;
|
char path[FILENAME_MAX];
|
||||||
|
char message[128];
|
||||||
|
char type[64];
|
||||||
int64_t line;
|
int64_t line;
|
||||||
int64_t column;
|
int64_t column;
|
||||||
int length;
|
int length;
|
||||||
char message[ERR_MSG_MAX_LEN];
|
|
||||||
char type[16];
|
|
||||||
bool exists;
|
bool exists;
|
||||||
} ArErr;
|
} ArErr;
|
||||||
#endif // RETURN_TYPES_
|
#endif // RETURN_TYPES_
|
||||||
@@ -85,15 +85,13 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv,
|
|||||||
if (object->type != TYPE_FUNCTION && object->type != TYPE_NATIVE_FUNCTION &&
|
if (object->type != TYPE_FUNCTION && object->type != TYPE_NATIVE_FUNCTION &&
|
||||||
object->type != TYPE_METHOD) {
|
object->type != TYPE_METHOD) {
|
||||||
ArgonObject *call_method = get_builtin_field_for_class(
|
ArgonObject *call_method = get_builtin_field_for_class(
|
||||||
get_builtin_field(object, __class__), __call__,
|
get_builtin_field(object, __class__), __call__, original_object);
|
||||||
original_object);
|
|
||||||
if (call_method) {
|
if (call_method) {
|
||||||
object = call_method;
|
object = call_method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (object->type == TYPE_METHOD) {
|
if (object->type == TYPE_METHOD) {
|
||||||
ArgonObject *binding_object =
|
ArgonObject *binding_object = get_builtin_field(object, __binding__);
|
||||||
get_builtin_field(object, __binding__);
|
|
||||||
if (binding_object) {
|
if (binding_object) {
|
||||||
ArgonObject **new_call_args =
|
ArgonObject **new_call_args =
|
||||||
ar_alloc(sizeof(ArgonObject *) * (argc + 1));
|
ar_alloc(sizeof(ArgonObject *) * (argc + 1));
|
||||||
@@ -104,16 +102,14 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv,
|
|||||||
argv = new_call_args;
|
argv = new_call_args;
|
||||||
argc++;
|
argc++;
|
||||||
}
|
}
|
||||||
ArgonObject *function_object =
|
ArgonObject *function_object = get_builtin_field(object, __function__);
|
||||||
get_builtin_field(object, __function__);
|
|
||||||
if (function_object)
|
if (function_object)
|
||||||
object = function_object;
|
object = function_object;
|
||||||
}
|
}
|
||||||
if (object->type == TYPE_FUNCTION) {
|
if (object->type == TYPE_FUNCTION) {
|
||||||
if (argc != object->value.argon_fn->number_of_parameters) {
|
if (argc != object->value.argon_fn->number_of_parameters) {
|
||||||
ArgonObject *type_object_name = get_builtin_field_for_class(
|
ArgonObject *type_object_name = get_builtin_field_for_class(
|
||||||
get_builtin_field(object, __class__), __name__,
|
get_builtin_field(object, __class__), __name__, original_object);
|
||||||
original_object);
|
|
||||||
ArgonObject *object_name =
|
ArgonObject *object_name =
|
||||||
get_builtin_field_for_class(object, __name__, original_object);
|
get_builtin_field_for_class(object, __name__, original_object);
|
||||||
*err = create_err(
|
*err = create_err(
|
||||||
@@ -122,7 +118,8 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv,
|
|||||||
"%.*s %.*s takes %" PRIu64 " argument(s) but %" PRIu64 " was given",
|
"%.*s %.*s takes %" PRIu64 " argument(s) but %" PRIu64 " was given",
|
||||||
(int)type_object_name->value.as_str->length,
|
(int)type_object_name->value.as_str->length,
|
||||||
type_object_name->value.as_str->data,
|
type_object_name->value.as_str->data,
|
||||||
(int)object_name->value.as_str->length, object_name->value.as_str->data,
|
(int)object_name->value.as_str->length,
|
||||||
|
object_name->value.as_str->data,
|
||||||
object->value.argon_fn->number_of_parameters, argc);
|
object->value.argon_fn->number_of_parameters, argc);
|
||||||
}
|
}
|
||||||
Stack *scope = create_scope(object->value.argon_fn->stack, true);
|
Stack *scope = create_scope(object->value.argon_fn->stack, true);
|
||||||
@@ -191,13 +188,12 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv,
|
|||||||
err->line = state->source_location.line;
|
err->line = state->source_location.line;
|
||||||
err->column = state->source_location.column;
|
err->column = state->source_location.column;
|
||||||
err->length = state->source_location.length;
|
err->length = state->source_location.length;
|
||||||
err->path = state->path;
|
strcpy(err->path, state->path);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArgonObject *type_object_name = get_builtin_field_for_class(
|
ArgonObject *type_object_name = get_builtin_field_for_class(
|
||||||
get_builtin_field(original_object, __class__), __name__,
|
get_builtin_field(original_object, __class__), __name__, original_object);
|
||||||
original_object);
|
|
||||||
*err = create_err(state->source_location.line, state->source_location.column,
|
*err = create_err(state->source_location.line, state->source_location.column,
|
||||||
state->source_location.length, state->path, "Type Error",
|
state->source_location.length, state->path, "Type Error",
|
||||||
"'%.*s' object is not callable",
|
"'%.*s' object is not callable",
|
||||||
|
|||||||
0
src/runtime/objects/dictionary/dictionary.c
Normal file
0
src/runtime/objects/dictionary/dictionary.c
Normal file
0
src/runtime/objects/dictionary/dictionary.h
Normal file
0
src/runtime/objects/dictionary/dictionary.h
Normal file
@@ -13,9 +13,8 @@
|
|||||||
|
|
||||||
ArgonObject *ARGON_STRING_TYPE = NULL;
|
ArgonObject *ARGON_STRING_TYPE = NULL;
|
||||||
|
|
||||||
ArgonObject *new_string_object_without_memcpy(char *data, size_t length, uint64_t prehash,
|
void init_string(ArgonObject*object,char *data, size_t length, uint64_t prehash,
|
||||||
uint64_t hash) {
|
uint64_t hash) {
|
||||||
ArgonObject *object = new_instance(ARGON_STRING_TYPE);
|
|
||||||
add_builtin_field(object, field_length,
|
add_builtin_field(object, field_length,
|
||||||
new_number_object_from_int64(length));
|
new_number_object_from_int64(length));
|
||||||
object->type = TYPE_STRING;
|
object->type = TYPE_STRING;
|
||||||
@@ -26,6 +25,12 @@ ArgonObject *new_string_object_without_memcpy(char *data, size_t length, uint64_
|
|||||||
object->value.as_str->hash = hash;
|
object->value.as_str->hash = hash;
|
||||||
object->value.as_str->length = length;
|
object->value.as_str->length = length;
|
||||||
object->as_bool = length;
|
object->as_bool = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArgonObject *new_string_object_without_memcpy(char *data, size_t length, uint64_t prehash,
|
||||||
|
uint64_t hash) {
|
||||||
|
ArgonObject *object = new_instance(ARGON_STRING_TYPE);
|
||||||
|
init_string(object,data,length,prehash,hash);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
|
|
||||||
extern ArgonObject *ARGON_STRING_TYPE;
|
extern ArgonObject *ARGON_STRING_TYPE;
|
||||||
|
|
||||||
|
void init_string(ArgonObject*object,char *data, size_t length, uint64_t prehash,
|
||||||
|
uint64_t hash);
|
||||||
|
|
||||||
ArgonObject *new_string_object_without_memcpy(char *data, size_t length, uint64_t prehash,
|
ArgonObject *new_string_object_without_memcpy(char *data, size_t length, uint64_t prehash,
|
||||||
uint64_t hash);
|
uint64_t hash);
|
||||||
|
|
||||||
|
|||||||
@@ -64,23 +64,23 @@ ArgonObject *BASE_CLASS___getattribute__(size_t argc, ArgonObject **argv,
|
|||||||
access->value.as_str->hash = hash;
|
access->value.as_str->hash = hash;
|
||||||
access->value.as_str->hash_computed = true;
|
access->value.as_str->hash_computed = true;
|
||||||
}
|
}
|
||||||
ArgonObject *value = get_field_l(to_access, access->value.as_str->data, hash,
|
ArgonObject *value =
|
||||||
|
get_field_l(to_access, access->value.as_str->data, hash,
|
||||||
access->value.as_str->length, true, false);
|
access->value.as_str->length, true, false);
|
||||||
if (value)
|
if (value)
|
||||||
return value;
|
return value;
|
||||||
ArgonObject *cls__get_attr__ = get_builtin_field_for_class(
|
ArgonObject *cls__get_attr__ = get_builtin_field_for_class(
|
||||||
get_builtin_field(to_access, __class__), __get_attr__,
|
get_builtin_field(to_access, __class__), __get_attr__, to_access);
|
||||||
to_access);
|
|
||||||
if (cls__get_attr__) {
|
if (cls__get_attr__) {
|
||||||
value = argon_call(cls__get_attr__, 1, (ArgonObject *[]){access}, err, state);
|
value =
|
||||||
|
argon_call(cls__get_attr__, 1, (ArgonObject *[]){access}, err, state);
|
||||||
if (err->exists) {
|
if (err->exists) {
|
||||||
return ARGON_NULL;
|
return ARGON_NULL;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
ArgonObject *name = get_builtin_field_for_class(
|
ArgonObject *name = get_builtin_field_for_class(
|
||||||
get_builtin_field(to_access, __class__), __name__,
|
get_builtin_field(to_access, __class__), __name__, to_access);
|
||||||
to_access);
|
|
||||||
*err = create_err(
|
*err = create_err(
|
||||||
0, 0, 0, "", "Runtime Error", "'%.*s' object has no attribute '%.*s'",
|
0, 0, 0, "", "Runtime Error", "'%.*s' object has no attribute '%.*s'",
|
||||||
(int)name->value.as_str->length, name->value.as_str->data,
|
(int)name->value.as_str->length, name->value.as_str->data,
|
||||||
@@ -101,8 +101,7 @@ ArgonObject *ARGON_ADDITION_FUNCTION(size_t argc, ArgonObject **argv,
|
|||||||
ArgonObject *object__add__ = get_builtin_field_for_class(
|
ArgonObject *object__add__ = get_builtin_field_for_class(
|
||||||
get_builtin_field(output, __class__), __add__, output);
|
get_builtin_field(output, __class__), __add__, output);
|
||||||
if (!object__add__) {
|
if (!object__add__) {
|
||||||
ArgonObject *cls___name__ =
|
ArgonObject *cls___name__ = get_builtin_field(output, __name__);
|
||||||
get_builtin_field(output, __name__);
|
|
||||||
*err = create_err(0, 0, 0, "", "Runtime Error",
|
*err = create_err(0, 0, 0, "", "Runtime Error",
|
||||||
"Object '%.*s' is missing __add__ method",
|
"Object '%.*s' is missing __add__ method",
|
||||||
(int)cls___name__->value.as_str->length,
|
(int)cls___name__->value.as_str->length,
|
||||||
@@ -126,11 +125,9 @@ ArgonObject *ARGON_SUBTRACTION_FUNCTION(size_t argc, ArgonObject **argv,
|
|||||||
ArgonObject *output = argv[0];
|
ArgonObject *output = argv[0];
|
||||||
for (size_t i = 1; i < argc; i++) {
|
for (size_t i = 1; i < argc; i++) {
|
||||||
ArgonObject *function__subtract__ = get_builtin_field_for_class(
|
ArgonObject *function__subtract__ = get_builtin_field_for_class(
|
||||||
get_builtin_field(output, __class__), __subtract__,
|
get_builtin_field(output, __class__), __subtract__, output);
|
||||||
output);
|
|
||||||
if (!function__subtract__) {
|
if (!function__subtract__) {
|
||||||
ArgonObject *cls___name__ =
|
ArgonObject *cls___name__ = get_builtin_field(output, __name__);
|
||||||
get_builtin_field(output, __name__);
|
|
||||||
*err = create_err(0, 0, 0, "", "Runtime Error",
|
*err = create_err(0, 0, 0, "", "Runtime Error",
|
||||||
"Object '%.*s' is missing __subtract__ method",
|
"Object '%.*s' is missing __subtract__ method",
|
||||||
(int)cls___name__->value.as_str->length,
|
(int)cls___name__->value.as_str->length,
|
||||||
@@ -154,11 +151,9 @@ ArgonObject *ARGON_MULTIPLY_FUNCTION(size_t argc, ArgonObject **argv,
|
|||||||
ArgonObject *output = argv[0];
|
ArgonObject *output = argv[0];
|
||||||
for (size_t i = 1; i < argc; i++) {
|
for (size_t i = 1; i < argc; i++) {
|
||||||
ArgonObject *function__multiply__ = get_builtin_field_for_class(
|
ArgonObject *function__multiply__ = get_builtin_field_for_class(
|
||||||
get_builtin_field(output, __class__), __multiply__,
|
get_builtin_field(output, __class__), __multiply__, output);
|
||||||
output);
|
|
||||||
if (!function__multiply__) {
|
if (!function__multiply__) {
|
||||||
ArgonObject *cls___name__ =
|
ArgonObject *cls___name__ = get_builtin_field(output, __name__);
|
||||||
get_builtin_field(output, __name__);
|
|
||||||
*err = create_err(0, 0, 0, "", "Runtime Error",
|
*err = create_err(0, 0, 0, "", "Runtime Error",
|
||||||
"Object '%.*s' is missing __multiply__ method",
|
"Object '%.*s' is missing __multiply__ method",
|
||||||
(int)cls___name__->value.as_str->length,
|
(int)cls___name__->value.as_str->length,
|
||||||
@@ -182,11 +177,9 @@ ArgonObject *ARGON_DIVISION_FUNCTION(size_t argc, ArgonObject **argv,
|
|||||||
ArgonObject *output = argv[0];
|
ArgonObject *output = argv[0];
|
||||||
for (size_t i = 1; i < argc; i++) {
|
for (size_t i = 1; i < argc; i++) {
|
||||||
ArgonObject *function__division__ = get_builtin_field_for_class(
|
ArgonObject *function__division__ = get_builtin_field_for_class(
|
||||||
get_builtin_field(output, __class__), __division__,
|
get_builtin_field(output, __class__), __division__, output);
|
||||||
output);
|
|
||||||
if (!function__division__) {
|
if (!function__division__) {
|
||||||
ArgonObject *cls___name__ =
|
ArgonObject *cls___name__ = get_builtin_field(output, __name__);
|
||||||
get_builtin_field(output, __name__);
|
|
||||||
*err = create_err(0, 0, 0, "", "Runtime Error",
|
*err = create_err(0, 0, 0, "", "Runtime Error",
|
||||||
"Object '%.*s' is missing __division__ method",
|
"Object '%.*s' is missing __division__ method",
|
||||||
(int)cls___name__->value.as_str->length,
|
(int)cls___name__->value.as_str->length,
|
||||||
@@ -218,8 +211,7 @@ ArgonObject *ARGON_TYPE_TYPE___call__(size_t argc, ArgonObject **argv,
|
|||||||
ArgonObject *cls___new__ =
|
ArgonObject *cls___new__ =
|
||||||
get_builtin_field_for_class(argv[0], __new__, NULL);
|
get_builtin_field_for_class(argv[0], __new__, NULL);
|
||||||
if (!cls___new__) {
|
if (!cls___new__) {
|
||||||
ArgonObject *cls___name__ =
|
ArgonObject *cls___name__ = get_builtin_field(argv[0], __name__);
|
||||||
get_builtin_field(argv[0], __name__);
|
|
||||||
*err = create_err(
|
*err = create_err(
|
||||||
0, 0, 0, "", "Runtime Error",
|
0, 0, 0, "", "Runtime Error",
|
||||||
"Object '%.*s' is missing __new__ method, so cannot be initialised",
|
"Object '%.*s' is missing __new__ method, so cannot be initialised",
|
||||||
@@ -239,8 +231,7 @@ ArgonObject *ARGON_TYPE_TYPE___call__(size_t argc, ArgonObject **argv,
|
|||||||
ArgonObject *cls___init__ =
|
ArgonObject *cls___init__ =
|
||||||
get_builtin_field_for_class(argv[0], __init__, new_object);
|
get_builtin_field_for_class(argv[0], __init__, new_object);
|
||||||
if (!cls___init__) {
|
if (!cls___init__) {
|
||||||
ArgonObject *cls___name__ =
|
ArgonObject *cls___name__ = get_builtin_field(argv[0], __name__);
|
||||||
get_builtin_field(argv[0], __name__);
|
|
||||||
*err = create_err(
|
*err = create_err(
|
||||||
0, 0, 0, "", "Runtime Error",
|
0, 0, 0, "", "Runtime Error",
|
||||||
"Object '%.*s' is missing __init__ method, so cannot be initialised",
|
"Object '%.*s' is missing __init__ method, so cannot be initialised",
|
||||||
@@ -338,10 +329,6 @@ ArgonObject *ARGON_STRING_TYPE___init__(size_t argc, ArgonObject **argv,
|
|||||||
}
|
}
|
||||||
ArgonObject *self = argv[0];
|
ArgonObject *self = argv[0];
|
||||||
ArgonObject *object = argv[1];
|
ArgonObject *object = argv[1];
|
||||||
|
|
||||||
self->value.as_str->data = NULL;
|
|
||||||
self->value.as_str->length = 0;
|
|
||||||
self->type = TYPE_STRING;
|
|
||||||
ArgonObject *string_convert_method = get_builtin_field_for_class(
|
ArgonObject *string_convert_method = get_builtin_field_for_class(
|
||||||
get_builtin_field(object, __class__), __string__, object);
|
get_builtin_field(object, __class__), __string__, object);
|
||||||
if (string_convert_method) {
|
if (string_convert_method) {
|
||||||
@@ -349,12 +336,14 @@ ArgonObject *ARGON_STRING_TYPE___init__(size_t argc, ArgonObject **argv,
|
|||||||
argon_call(string_convert_method, 0, NULL, err, state);
|
argon_call(string_convert_method, 0, NULL, err, state);
|
||||||
if (err->exists)
|
if (err->exists)
|
||||||
return ARGON_NULL;
|
return ARGON_NULL;
|
||||||
self->value.as_str->data =
|
init_string(self, string_object->value.as_str->data,
|
||||||
ar_alloc_atomic(string_object->value.as_str->length);
|
string_object->value.as_str->length,
|
||||||
memcpy(self->value.as_str->data, string_object->value.as_str->data,
|
string_object->value.as_str->prehash,
|
||||||
string_object->value.as_str->length);
|
string_object->value.as_str->hash);
|
||||||
self->value.as_str->length = string_object->value.as_str->length;
|
return ARGON_NULL;
|
||||||
}
|
}
|
||||||
|
*err = create_err(0, 0, 0, "", "String Conversion Error",
|
||||||
|
"cannot convert to string");
|
||||||
return ARGON_NULL;
|
return ARGON_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,8 +611,8 @@ void bootstrap_types() {
|
|||||||
add_builtin_field(
|
add_builtin_field(
|
||||||
ARGON_BOOL_TYPE, __number__,
|
ARGON_BOOL_TYPE, __number__,
|
||||||
create_argon_native_function("__number__", ARGON_BOOL_TYPE___number__));
|
create_argon_native_function("__number__", ARGON_BOOL_TYPE___number__));
|
||||||
GETATTRIBUTE_FUNCTION = create_argon_native_function("__get_attr__",
|
GETATTRIBUTE_FUNCTION =
|
||||||
BASE_CLASS___getattribute__);
|
create_argon_native_function("__get_attr__", BASE_CLASS___getattribute__);
|
||||||
ADDITION_FUNCTION =
|
ADDITION_FUNCTION =
|
||||||
create_argon_native_function("add", ARGON_ADDITION_FUNCTION);
|
create_argon_native_function("add", ARGON_ADDITION_FUNCTION);
|
||||||
SUBTRACTION_FUNCTION =
|
SUBTRACTION_FUNCTION =
|
||||||
@@ -874,8 +863,8 @@ void runtime(Translated _translated, RuntimeState _state, Stack *stack,
|
|||||||
continue;
|
continue;
|
||||||
DO_LOAD_GETATTRIBUTE_FUNCTION:
|
DO_LOAD_GETATTRIBUTE_FUNCTION:
|
||||||
state->registers[0] = get_builtin_field_for_class(
|
state->registers[0] = get_builtin_field_for_class(
|
||||||
get_builtin_field(state->registers[0], __class__),
|
get_builtin_field(state->registers[0], __class__), __getattribute__,
|
||||||
__getattribute__, state->registers[0]);
|
state->registers[0]);
|
||||||
if (!state->registers[0]) {
|
if (!state->registers[0]) {
|
||||||
*err = create_err(
|
*err = create_err(
|
||||||
state->source_location.line, state->source_location.column,
|
state->source_location.line, state->source_location.column,
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ RuntimeState init_runtime_state(Translated translated, char *path);
|
|||||||
|
|
||||||
Stack *create_scope(Stack *prev, bool force);
|
Stack *create_scope(Stack *prev, bool force);
|
||||||
|
|
||||||
|
void add_to_scope(Stack *stack, char *name, ArgonObject *value);
|
||||||
|
|
||||||
void runtime(Translated translated, RuntimeState state, Stack *stack,
|
void runtime(Translated translated, RuntimeState state, Stack *stack,
|
||||||
ArErr *err);
|
ArErr *err);
|
||||||
|
|
||||||
|
|||||||
12
src/shell.c
12
src/shell.c
@@ -9,6 +9,10 @@
|
|||||||
#include "./runtime/objects/term/term.h"
|
#include "./runtime/objects/term/term.h"
|
||||||
#include "./runtime/runtime.h"
|
#include "./runtime/runtime.h"
|
||||||
#include "./translator/translator.h"
|
#include "./translator/translator.h"
|
||||||
|
#include "LICENSE_c.h"
|
||||||
|
#include "import.h"
|
||||||
|
#include "runtime/objects/literals/literals.h"
|
||||||
|
#include "runtime/objects/string/string.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -180,10 +184,14 @@ int shell() {
|
|||||||
free(data);
|
free(data);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
add_to_scope(main_scope, "license",
|
||||||
|
new_string_object_without_memcpy((char *)LICENSE_txt,
|
||||||
|
LICENSE_txt_len, 0, 0));
|
||||||
|
|
||||||
signal(SIGINT, handle_sigint);
|
signal(SIGINT, handle_sigint);
|
||||||
|
|
||||||
printf("Welcome to the Argon shell!\n\n");
|
printf("Argon (Chloride %s)\nType \"license\" for more information.\n",
|
||||||
|
version_string);
|
||||||
|
|
||||||
ArgonObject *output_object = create_argon_native_function("log", term_log);
|
ArgonObject *output_object = create_argon_native_function("log", term_log);
|
||||||
char *totranslate = NULL;
|
char *totranslate = NULL;
|
||||||
@@ -266,7 +274,7 @@ int shell() {
|
|||||||
if (resp) {
|
if (resp) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (runtime_state.registers[0]) {
|
if (runtime_state.registers[0]&&runtime_state.registers[0] != ARGON_NULL) {
|
||||||
ArErr err = no_err;
|
ArErr err = no_err;
|
||||||
argon_call(output_object, 1,
|
argon_call(output_object, 1,
|
||||||
(ArgonObject *[]){runtime_state.registers[0]}, &err,
|
(ArgonObject *[]){runtime_state.registers[0]}, &err,
|
||||||
|
|||||||
4
tests/iteration-test.py
Normal file
4
tests/iteration-test.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
i = 1000000
|
||||||
|
while i:
|
||||||
|
print(i)
|
||||||
|
i=i-1
|
||||||
Reference in New Issue
Block a user