fi
C_FILES="$C_FILES wasm_runtime"
-FLAGS="$FLAGS -DENABLE_RUN_WITH_WASMER -rdynamic"
+FLAGS="$FLAGS -DENABLE_RUN_WITH_WASMER"
LIBS="-L$CORE_DIR/lib -lwasmer -Wl,-rpath=$CORE_DIR/lib:./ -lpthread -ldl"
INCLUDES="-I$WASMER_INCLUDE_DIR"
struct AstNamedValue { AstTyped_base; AstTyped* value; };
struct AstUnaryOp { AstTyped_base; UnaryOp operation; AstTyped *expr; };
struct AstNumLit { AstTyped_base; union { i32 i; i64 l; f32 f; f64 d; } value; };
-struct AstStrLit { AstTyped_base; u64 addr; u64 length; };
+struct AstStrLit { AstTyped_base; u64 addr; u64 length; b32 is_cstr: 1; };
struct AstLocal { AstTyped_base; };
struct AstDereference { AstTyped_base; AstTyped *expr; };
struct AstSizeOf { AstTyped_base; AstType *so_ast_type; Type *so_type; u64 size; };
extern AstGlobal builtin_tls_base;
extern AstGlobal builtin_tls_size;
extern AstType *builtin_string_type;
+extern AstType *builtin_cstring_type;
extern AstType *builtin_range_type;
extern Type *builtin_range_type_type;
extern AstType *builtin_vararg_type;
char* (*wasm_memory_data)(wasm_memory_t *wasm_memory);
wasm_extern_t* (*wasm_extern_lookup_by_name)(wasm_module_t* module, wasm_instance_t* instance, const char* name);
wasm_func_t* (*wasm_extern_as_func)(wasm_extern_t* ext);
- wasm_trap_t* (*wasm_func_call)(wasm_func_t* wasm_func, wasm_val_vec_t* args, wasm_val_vec_t* results);
+ wasm_trap_t* (*wasm_func_call)(const wasm_func_t* wasm_func, const wasm_val_vec_t* args, wasm_val_vec_t* results);
} OnyxRuntime;
OnyxRuntime* runtime;
glfwDestroyCursor :: (cursor: GLFWcursor_p) -> void ---
glfwSetCursor :: (window: GLFWwindow_p, cursor: GLFWcursor_p) -> void ---
glfwSetKeyCallback :: (window: GLFWwindow_p, export_name: str) -> void ---
- // glfwSetCharCallback
- // glfwSetCharModsCallback
- // glfwSetMouseButtonCallback
- // glfwSetCursorPosCallback
- // glfwSetCursorEnterCallback
- // glfwSetScrollCallback
+ glfwSetCharCallback :: (window: GLFWwindow_p, export_name: str) -> void ---
+ glfwSetCharModsCallback :: (window: GLFWwindow_p, export_name: str) -> void ---
+ glfwSetMouseButtonCallback :: (window: GLFWwindow_p, export_name: str) -> void ---
+ glfwSetCursorPosCallback :: (window: GLFWwindow_p, export_name: str) -> void ---
+ glfwSetCursorEnterCallback :: (window: GLFWwindow_p, export_name: str) -> void ---
+ glfwSetScrollCallback :: (window: GLFWwindow_p, export_name: str) -> void ---
// glfwSetDropCallback
glfwJoystickPresent :: (jid: i32) -> i32 ---
// glfwGetJoystickAxes :: (jid: i32, count: ^i32) -> ^f32 ---
AstGlobal builtin_tls_size = { Ast_Kind_Global, 0, &builtin_tls_size_token, NULL, NULL, (AstType *) &basic_type_u32, NULL };
AstType *builtin_string_type;
+AstType *builtin_cstring_type;
AstType *builtin_range_type;
Type *builtin_range_type_type;
AstType *builtin_vararg_type;
return;
}
+ builtin_cstring_type = (AstType *) symbol_raw_resolve(p->scope, "cstr");
+ if (builtin_cstring_type == NULL) {
+ onyx_report_error((OnyxFilePos) { 0 }, "'cstr' type not found in builtin package.");
+ return;
+ }
+
builtin_range_type = (AstType *) symbol_raw_resolve(p->scope, "range");
if (builtin_range_type == NULL) {
onyx_report_error((OnyxFilePos) { 0 }, "'range' struct not found in builtin package.");
assert(builtin_code_type != NULL);
code_block->type_node = builtin_code_type;
-
+
code_block->code = (AstNode *) parse_expression(parser, 0);
expect_token(parser, ')');
retval = (AstTyped *) insert;
break;
}
+ else if (parse_possible_directive(parser, "cstr")) {
+ // Copy pasted from above.
+ AstStrLit* str_node = make_node(AstStrLit, Ast_Kind_StrLit);
+ str_node->token = expect_token(parser, Token_Type_Literal_String);
+ str_node->addr = 0;
+ str_node->flags |= Ast_Flag_Comptime;
+ str_node->is_cstr = 1;
+
+ ENTITY_SUBMIT(str_node);
+
+ retval = (AstTyped *) str_node;
+ break;
+ }
onyx_report_error(parser->curr->pos, "Invalid directive in expression.");
return NULL;
SYMRES(type, &(*expr)->type_node);
break;
- case Ast_Kind_StrLit:
- SYMRES(type, &builtin_string_type);
- (*expr)->type_node = builtin_string_type;
+ case Ast_Kind_StrLit: {
+ AstStrLit* str = (AstStrLit *) *expr;
+ if (str->is_cstr) {
+ SYMRES(type, &builtin_cstring_type);
+ str->type_node = builtin_cstring_type;
+
+ } else {
+ SYMRES(type, &builtin_string_type);
+ str->type_node = builtin_string_type;
+ }
break;
+ }
case Ast_Kind_Slice:
case Ast_Kind_Subscript:
case Ast_Kind_StrLit: {
WID(WI_PTR_CONST, ((AstStrLit *) expr)->addr);
- WID(WI_I32_CONST, ((AstStrLit *) expr)->length);
+
+ if (((AstStrLit *) expr)->is_cstr == 0)
+ WID(WI_I32_CONST, ((AstStrLit *) expr)->length);
break;
}
if (index != -1) {
StrLitInfo sti = mod->string_literals[index].value;
strlit->addr = sti.addr;
- strlit->length = sti.len;
+ strlit->length = sti.len + (strlit->is_cstr ? 1 : 0);
bh_free(global_heap_allocator, strdata);
return;
}
+ u32 actual_length = length + (strlit->is_cstr ? 1 : 0);
WasmDatum datum = {
.offset = mod->next_datum_offset,
- .length = length,
+ .length = actual_length,
.data = strdata,
};
strlit->addr = (u32) mod->next_datum_offset,
strlit->length = length;
- mod->next_datum_offset += length;
+ mod->next_datum_offset += actual_length;
shput(mod->string_literals, (char *) strdata, ((StrLitInfo) { strlit->addr, strlit->length }));