void entity_bring_to_state(Entity* ent, EntityState state);
void symres_entity(Entity* ent);
void check_entity(Entity* ent);
-void emit_entity(Entity* ent);
+void emit_c_entity(Entity* ent);
+// void emit_wasm_entity(Entity* ent);
struct Package {
char *name;
bh_arr(bh_file_contents) loaded_files;
// NOTE: This is defined in onyxwasm.h
- struct OnyxWasmModule* wasm_module;
+ // struct OnyxWasmModule* wasm_module;
+
+ // NOTE: This is defined in onyxc.h
+ struct OnyxCFile* c_file;
b32 cycle_detected : 1;
};
#include "onyxerrors.h"
#include "onyxparser.h"
#include "onyxutils.h"
-#include "onyxwasm.h"
+#include "onyxc.h"
#include "onyxdoc.h"
#define VERSION "v0.1.0-beta"
"\n"
"Flags:\n"
"\t<input files> List of initial files\n"
- "\t-o <target_file> Specify the target file (default: out.wasm)\n"
+ "\t-o <target_file> Specify the target file (default: out.c)\n"
"\t--runtime, -r <runtime> Specifies a runtime. Can be: wasi, js, custom.\n"
"\t--verbose, -V Verbose output\n"
"\t -VV Very verbose output\n"
.runtime = Runtime_Wasi,
.files = NULL,
- .target_file = "out.wasm",
+ .target_file = "out.c",
};
bh_arr_new(alloc, options.files, 2);
bh_arena_init(&context.ast_arena, global_heap_allocator, 16 * 1024 * 1024); // 16MB
context.ast_alloc = bh_arena_allocator(&context.ast_arena);
- context.wasm_module = bh_alloc_item(global_heap_allocator, OnyxWasmModule);
- *context.wasm_module = onyx_wasm_module_create(global_heap_allocator);
+ // context.wasm_module = bh_alloc_item(global_heap_allocator, OnyxWasmModule);
+ // *context.wasm_module = onyx_wasm_module_create(global_heap_allocator);
+ context.c_file = bh_alloc_item(global_heap_allocator, OnyxCFile);
entity_heap_init(&context.entities);
case Entity_State_Comptime_Check_Types:
case Entity_State_Check_Types: check_entity(ent); break;
- case Entity_State_Code_Gen: emit_entity(ent); break;
+ case Entity_State_Code_Gen: emit_c_entity(ent); break;
}
return ent->state != before_state;
if (bh_file_create(&output_file, context.options->target_file) != BH_FILE_ERROR_NONE)
return ONYX_COMPILER_PROGRESS_FAILED_OUTPUT;
+ if (context.options->verbose_output)
+ bh_printf("Outputting to C file: %s\n", output_file.filename);
+
+ onyx_output_c_file(context.c_file, output_file);
+
+ return ONYX_COMPILER_PROGRESS_SUCCESS;
+#if 0
if (context.options->verbose_output)
bh_printf("Outputting to WASM file: %s\n", output_file.filename);
}
return ONYX_COMPILER_PROGRESS_SUCCESS;
+#endif
}
int main(int argc, char *argv[]) {
--- /dev/null
+#include "onyxc.h"
+
+
+static char* BOILERPLATE_TOP =
+ "#include <stdlib.h>\n"
+ "#include <stdint.h>\n"
+ "typedef uint8_t u8;\n"
+ "typedef uint16_t u16;\n"
+ "typedef uint32_t u32;\n"
+ "typedef uint64_t u64;\n"
+ "typedef int8_t i8;\n"
+ "typedef int16_t i16;\n"
+ "typedef int32_t i32;\n"
+ "typedef int64_t i64;\n"
+ "typedef float f32;\n"
+ "typedef double f64;\n"
+ "typedef void *rawptr;\n";
+
+
+
+
+void onyx_output_c_file(OnyxCFile* cfile, bh_file file) {
+ bh_file_write(&file, BOILERPLATE_TOP, strlen(BOILERPLATE_TOP));
+}