#!/bin/sh
+set -e
+
DIST_DIR="./dist"
compile_all() {
bh_path_convert_separators(folder);
// This does not take into account #load_path'd folders...
-
+
bh_arr(char *) folders_to_process = NULL;
bh_arr_new(global_heap_allocator, folders_to_process, 2);
onyx_wasm_module_write_to_buffer(context.wasm_module, &code_buffer);
return onyx_run_module(code_buffer);
-
+
}
#endif
bh_file_watch_free(&watches);
} while(running_watch);
-
+
bh_printf("\e[2J\e[1;1H\e[?25h\n");
}
$ONYX_CC $FLAGS $INCLUDES -fPIC -o $(mktemp -p build_tmp -t XXXXXXX.o) -c $c_file $LIBS
done
-ar cr "$TARGET" build_tmp/*.o
+ar crs "$TARGET" build_tmp/*.o*
rm -r "build_tmp"
} debug_type_function_t;
typedef struct debug_type_slice_t {
- u32 type;
+ u32 type;
} debug_type_slice_t;
typedef struct debug_type_enum_value_t {
u32 client_fd;
bh_buffer send_buffer;
-
+
u32 state_change_pipes[2];
} debug_state_t;
debug_func_info_t func_info;
debug_file_info_t file_info;
debug_loc_info_t loc_info;
-
+
// "base_" refers to the top symbol. In a layered
// query, this information is not outputted, only
// used to lookup the values inside of it.
u32 it_loc;
u32 it_type;
char *it_name;
- bool it_has_children;
+ bool it_has_children;
} debug_runtime_value_builder_t;
void debug_runtime_value_build_init(debug_runtime_value_builder_t *builder, bh_allocator alloc);
// Represents the running configuration and static
// data needed by the VM. This is for more "global" data.
// If multiple threads are used, only one engine is needed.
-//
+//
struct ovm_engine_t {
ovm_store_t *store;
//
// Represents ephemeral state / execution context.
// If multiple threads are used, multiple states are needed.
-//
+//
#define OVM_MAX_PARAM_COUNT 64
i32 pc;
i32 value_number_offset;
-
+
bh_arr(ovm_value_t) numbered_values;
bh_arr(ovm_stack_frame_t) stack_frames;
bh_arr(ovm_value_t) registers;
i32 param_count;
ovm_external_func_t func;
};
-
+
ovm_func_t *ovm_func_new();
ovm_instr_t *ovm_func_add_instruction(ovm_func_t *func, ovm_instr_kind_t instr, ovm_valtype_t type);
void ovm_func_delete(ovm_func_t *func);
#define OVMI_TRANSMUTE_F32 0x4a // %r = *(t *) &%a (reinterpret bytes)
#define OVMI_TRANSMUTE_F64 0x4b // %r = *(t *) &%a (reinterpret bytes)
-#define OVMI_CMPXCHG 0x4c // %r = %r == %a ? %b : %r
+#define OVMI_CMPXCHG 0x4c // %r = %r == %a ? %b : %r
#define OVMI_BREAK 0x4d
#include <sys/mman.h>
#include <signal.h>
-#include <x86intrin.h>
+#if defined(__arm64__)
+ #include <arm_neon.h>
+#elif defined(__x86_64__)
+ #include <x86intrin.h>
+#else
+ #error "Unsupported architecture"
+#endif
+
+// @todo(judah): this may need to change in the future.
+#define __ovm_clz(v) __builtin_clz(v)
+#define __ovm_clzll(v) __builtin_clzll(v)
+#define __ovm_ctz(v) __builtin_ctz(v)
+#define __ovm_ctzll(v) __builtin_ctzll(v)
+#define __ovm_popcount(v) __builtin_popcount(v)
+#define __ovm_popcountll(v) __builtin_popcount(v)
+
#include <math.h> // REMOVE THIS!!! only needed for sqrt
#include <pthread.h>
if (engine->memory) {
munmap(engine->memory, engine->memory_size);
}
-
+
bh_free(store->heap_allocator, engine);
}
if (engine->memory == NULL) {
new_addr = mmap(NULL, minimum_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
} else {
- new_addr = mremap(engine->memory, engine->memory_size, minimum_size, MREMAP_MAYMOVE);
+ munmap(engine->memory, engine->memory_size);
+ new_addr = mmap(NULL, minimum_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ // new_addr = mremap(engine->memory, engine->memory_size, minimum_size, MREMAP_MAYMOVE);
}
if (new_addr == MAP_FAILED) {
VAL(instr->r).type = t; \
VAL(instr->r).ctype = (ctype) op (VAL(instr->a).ctype);
-OVMI_INSTR_EXEC(clz_i32) { OVM_OP(OVM_TYPE_I32, __builtin_clz, u32); NEXT_OP; }
-OVMI_INSTR_EXEC(clz_i64) { OVM_OP(OVM_TYPE_I64, __builtin_clzll, u64); NEXT_OP; }
-OVMI_INSTR_EXEC(ctz_i32) { OVM_OP(OVM_TYPE_I32, __builtin_ctz, u32); NEXT_OP; }
-OVMI_INSTR_EXEC(ctz_i64) { OVM_OP(OVM_TYPE_I64, __builtin_ctzll, u64); NEXT_OP; }
-OVMI_INSTR_EXEC(popcount_i32) { OVM_OP(OVM_TYPE_I32, __builtin_popcount, u32); NEXT_OP; }
-OVMI_INSTR_EXEC(popcount_i64) { OVM_OP(OVM_TYPE_I64, __builtin_popcountll, u64); NEXT_OP; }
+OVMI_INSTR_EXEC(clz_i32) { OVM_OP(OVM_TYPE_I32, __ovm_clz, u32); NEXT_OP; }
+OVMI_INSTR_EXEC(clz_i64) { OVM_OP(OVM_TYPE_I64, __ovm_clzll, u64); NEXT_OP; }
+OVMI_INSTR_EXEC(ctz_i32) { OVM_OP(OVM_TYPE_I32, __ovm_ctz, u32); NEXT_OP; }
+OVMI_INSTR_EXEC(ctz_i64) { OVM_OP(OVM_TYPE_I64, __ovm_ctzll, u64); NEXT_OP; }
+OVMI_INSTR_EXEC(popcount_i32) { OVM_OP(OVM_TYPE_I32, __ovm_popcount, u32); NEXT_OP; }
+OVMI_INSTR_EXEC(popcount_i64) { OVM_OP(OVM_TYPE_I64, __ovm_popcountll, u64); NEXT_OP; }
OVM_OP_FLOAT_EXEC(abs, __ovm_abs)
OVM_OP_FLOAT_EXEC(neg, -)
state->engine->memory_size + VAL(instr->a).u32 * 65536)) {
VAL(instr->r).i32 = -1;
}
-
+
memory = state->engine->memory;
NEXT_OP;
}
// ATOMIC ARENA ALLOCATOR
-// Currently, this is only available on Linux, as it is using pthreads.
-#ifdef _BH_LINUX
+// Currently, this is only available on Linux/MacOS, as it is using pthreads.
+#if defined(_BH_LINUX) || defined(_BH_DARWIN)
typedef struct bh_atomic_arena {
bh_allocator backing;
}
bh_managed_heap__link *newptr = bh_heap_allocator_proc(NULL, action, size + sizeof(*old), alignment, old, flags);
-
+
if (action == bh_allocator_action_alloc || action == bh_allocator_action_resize) {
if (newptr) {
newptr->magic_number = bh_managed_heap_magic_number;
trailer = walker;
}
}
-
+
alloc->current_arena = alloc->first_arena;
alloc->size = sizeof(ptr);
}
// ATOMIC ARENA ALLOCATOR IMPLEMENTATION
-#ifdef _BH_LINUX
+#if defined(_BH_LINUX) || defined(_BH_DARWIN)
BH_DEF void bh_atomic_arena_init(bh_atomic_arena* alloc, bh_allocator backing, isize arena_size) {
arena_size = bh_max(arena_size, size_of(ptr));
ptr data = bh_alloc(backing, arena_size);
zero_shifted = zero_shifted << shift;
return res | zero_shifted;
}
-
+
return res;
}
return result;
#elif defined(_BH_LINUX) || defined (_BH_DARWIN)
- char* p = realpath(filename, NULL);
+ char* p = realpath(filename, NULL);
// Check if the file did not exists.
// :Cleanup should this return NULL?
if (p == NULL) return (char *) filename;
-
+
i32 len = strlen(p);
char* result = bh_alloc_array(a, char, len + 1);
memmove(result, p, len);
(void) read(w->kill_pipe[0], &buf, sizeof(buf));
return 0;
}
-
+
FD_ZERO(&w->fds);
FD_SET(w->inotify_fd, &w->fds);
FD_SET(w->kill_pipe[0], &w->fds);
#if defined(_BH_WINDOWS)
u64 curr = bh_time_curr();
u64 duration = curr - old;
-
+
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
duration *= 1000;