LIBS="-lpthread -ldl -lm"
INCLUDES="-I./include -I../shared/include -I../shared/include/dyncall"
-WARNINGS='-Wimplicit -Wmisleading-indentation -Wparentheses -Wsequence-point -Wreturn-type -Wshift-negative-value -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wmaybe-uninitialized -Wsign-compare -Wstrict-overflow -Wduplicated-branches -Wduplicated-cond -Wtrigraphs -Waddress -Wlogical-op'
+WARNINGS='-Wimplicit -Wmisleading-indentation -Wparentheses -Wsequence-point -Wreturn-type -Wshift-negative-value -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wsign-compare -Wstrict-overflow -Wtrigraphs -Waddress'
if [ "$1" = "debug" ]; then
FLAGS="$WARNINGS -g3"
case "$ONYX_ARCH" in
*darwin*)
- LIBS="$LIBS -lffi -lSystem -framework CoreFoundation -framework SystemConfiguration"
+ LIBS="$LIBS -lffi -framework CoreFoundation -framework SystemConfiguration"
;;
esac
switch (node->operation) {
case Binary_Op_Equal: res->value.l = left_type->id == right_type->id; break;
case Binary_Op_Not_Equal: res->value.l = left_type->id != right_type->id; break;
- default: assert(("Bad case in ast_reduce_type_compare", 0));
+ default: assert("Bad case in ast_reduce_type_compare" && 0);
}
return res;
return 1;
}
if (type->Basic.size == 8) {
- if (bh_abs(num->value.l) >= (1ull << 52)) {
+ if (bh_abs(num->value.l) >= (1ll << 52)) {
onyx_report_error(num->token->pos, Error_Critical, "Integer '%l' does not fit in 64-bit float exactly.", num->value.l);
return 0;
}
case TYPE_MATCH_SUCCESS: break;
case TYPE_MATCH_FAILED: return TYPE_MATCH_FAILED;
case TYPE_MATCH_YIELD: return TYPE_MATCH_YIELD;
+ default: break;
}
}
case TYPE_MATCH_SUCCESS: break;
case TYPE_MATCH_FAILED: return TYPE_MATCH_FAILED;
case TYPE_MATCH_YIELD: return TYPE_MATCH_YIELD;
+ default: break;
}
}
if (node->kind == Ast_Kind_NumLit && node->type->kind == Type_Kind_Basic) {
if (node->type->Basic.kind == Basic_Kind_Int_Unsized) {
- b32 big = bh_abs(((AstNumLit *) node)->value.l) >= (1ull << 32);
+ b32 big = bh_abs(((AstNumLit *) node)->value.l) >= (1ll << 32);
b32 unsign = ((AstNumLit *) node)->was_hex_literal;
if (((AstNumLit *) node)->was_char_literal) return &basic_types[Basic_Kind_U8];
if (node->kind == Ast_Kind_NumLit && node->type->kind == Type_Kind_Basic) {
if (node->type->Basic.kind == Basic_Kind_Int_Unsized) {
- b32 big = bh_abs(((AstNumLit *) node)->value.l) >= (1ull << 32);
+ b32 big = bh_abs(((AstNumLit *) node)->value.l) >= (1ll << 32);
b32 unsign = ((AstNumLit *) node)->was_hex_literal;
if (((AstNumLit *) node)->was_char_literal) convert_numlit_to_type((AstNumLit *) node, &basic_types[Basic_Kind_U8]);
// CLEANUP: Maybe this should allocate on the heap?
// I guess if in all cases the memory is allocated on the heap,
// then the caller can free the memory.
- i8* strdata = bh_alloc_array(global_heap_allocator, i8, str->token->length + 1);
+ char* strdata = bh_alloc_array(global_heap_allocator, char, str->token->length + 1);
i32 length = string_process_escape_seqs(strdata, str->token->text, str->token->length);
strdata[length] = '\0';
AstNumLit* num = onyx_ast_node_new(a, sizeof(AstNumLit), Ast_Kind_NumLit);
num->flags |= Ast_Flag_Comptime;
- if (bh_abs(i) >= ((u64) 1 << 32))
+ if (bh_abs(i) >= (1ll << 32))
num->type_node = (AstType *) &basic_type_i64;
else
num->type_node = (AstType *) &basic_type_i32;
case Type_Kind_MultiPointer: effective_flags = Basic_Flag_Multi_Pointer; break;
case Type_Kind_Enum: effective_flags = Basic_Flag_Integer; break;
case Type_Kind_Function: effective_flags = Basic_Flag_Equality; break;
+
+ default: break;
}
return (binop_allowed[operation] & effective_flags) != 0;
}
break;
}
+
+ default: break;
}
type = original_type;
*constraint->report_status = Constraint_Check_Status_Success;
return Check_Complete;
}
+
+ default: break;
}
onyx_errors_enable();
case TYPE_MATCH_SUCCESS: return Check_Complete;
case TYPE_MATCH_FAILED: return Check_Error;
case TYPE_MATCH_YIELD: return Check_Yield_Macro;
+ case TYPE_MATCH_SPECIAL: return Check_Yield_Macro;
}
return Check_Error;
clear_attempts:
ent->macro_attempts = 0;
ent->micro_attempts = 0;
+
+ default: break;
}
}
case Ast_Kind_Capture_Local: return sizeof(AstCaptureLocal);
case Ast_Kind_Union_Type: return sizeof(AstUnionType);
case Ast_Kind_Union_Variant: return sizeof(AstUnionVariant);
- case Ast_Kind_Count: return 0;
+
+ default: break;
}
return 0;
bh_buffer_append(buffer, node->token->text, node->token->length);
return;
+
+ default: break;
}
unknown_case:
}
bh_buffer_write_string(&tmp_buffer, ")");
- write_string(buffer, tmp_buffer.length, tmp_buffer.data);
+ write_string(buffer, tmp_buffer.length, (char *) tmp_buffer.data);
constraint_count += 1;
}
poly_param->poly_sym->flags |= Ast_Flag_Symbol_Is_PolyVar;
bh_buffer_write_string(&tmp_buffer, ")");
- write_string(buffer, tmp_buffer.length, tmp_buffer.data);
+ write_string(buffer, tmp_buffer.length, (char *) tmp_buffer.data);
constraint_count += 1;
}
case Ast_Kind_Function: binding = node->original_binding_to_node; break;
case Ast_Kind_Macro: binding = ((AstMacro *) node)->original_binding_to_node; break;
case Ast_Kind_Overloaded_Function: binding = ((AstOverloadedFunction *) node)->original_binding_to_node; break;
+ default: break;
}
OnyxToken tmp_name_token;
write_string(buffer, param->local->token->length, param->local->token->text);
write_type_node(¶m_type_buf, param->local->type_node);
- write_string(buffer, param_type_buf.length, param_type_buf.data);
+ write_string(buffer, param_type_buf.length, (char *) param_type_buf.data);
write_cstring(buffer, "");
}
// Return type
bh_buffer_clear(¶m_type_buf);
write_type_node(¶m_type_buf, func->return_type);
- write_string(buffer, param_type_buf.length, param_type_buf.data);
+ write_string(buffer, param_type_buf.length, (char *) param_type_buf.data);
bh_buffer_free(¶m_type_buf);
// Overload procs
write_type_node(&type_buf, smem->type_node);
write_string(buffer, smem->token->length, smem->token->text);
- write_string(buffer, type_buf.length, type_buf.data);
+ write_string(buffer, type_buf.length, (char *) type_buf.data);
write_cstring(buffer, "");
bh_buffer_write_u32(buffer, smem->is_used ? 1 : 0);
write_type_node(&type_buf, param->type_node);
write_string(buffer, param->token->length, param->token->text);
- write_string(buffer, type_buf.length, type_buf.data);
+ write_string(buffer, type_buf.length, (char *) type_buf.data);
write_cstring(buffer, "");
}
write_type_node(&type_buf, uv->type_node);
write_string(buffer, uv->token->length, uv->token->text);
- write_string(buffer, type_buf.length, type_buf.data);
+ write_string(buffer, type_buf.length, (char *) type_buf.data);
}
// Polymorph parameters
write_type_node(&type_buf, param->type_node);
write_string(buffer, param->token->length, param->token->text);
- write_string(buffer, type_buf.length, type_buf.data);
+ write_string(buffer, type_buf.length, (char *) type_buf.data);
write_cstring(buffer, "");
}
bh_buffer type_buf;
bh_buffer_init(&type_buf, global_scratch_allocator, 256);
write_type_node(&type_buf, distinct_node->base_type);
- write_string(buffer, type_buf.length, type_buf.data);
+ write_string(buffer, type_buf.length, (char *) type_buf.data);
bh_buffer_free(&type_buf);
write_doc_methods(buffer, distinct_node->scope);
bh_snprintf(fullpath, 511, "%s/%s", folder, entry.name);
bh_path_convert_separators(fullpath);
- u8* formatted_name = bh_path_get_full_name(fullpath, global_heap_allocator);
+ char* formatted_name = bh_path_get_full_name(fullpath, global_heap_allocator);
AstInclude* new_include = onyx_ast_node_new(context.ast_alloc, sizeof(AstInclude), Ast_Kind_Load_File);
new_include->token = include->token;
if (!strcmp(entry.name, ".") || !strcmp(entry.name, "..")) continue;
bh_snprintf(fullpath, 511, "%s/%s", folder, entry.name);
- u8* formatted_name = bh_path_get_full_name(fullpath, global_scratch_allocator); // Could this overflow the scratch allocator?
+ char* formatted_name = bh_path_get_full_name(fullpath, global_scratch_allocator); // Could this overflow the scratch allocator?
bh_arr_push(folders_to_process, formatted_name);
}
emit_entity(ent);
break;
}
+
+ default: break;
}
b32 changed = ent->state != before_state;
// TODO: Replace these with bh_printf when padded formatting is added.
printf("\nStatistics:\n");
printf(" Time taken: %lf ms\n", (double) duration);
- printf(" Processed %ld lines (%f lines/second).\n", context.lexer_lines_processed, ((f32) 1000 * context.lexer_lines_processed) / (duration));
- printf(" Processed %ld tokens (%f tokens/second).\n", context.lexer_tokens_processed, ((f32) 1000 * context.lexer_tokens_processed) / (duration));
+ printf(" Processed %llu lines (%f lines/second).\n", context.lexer_lines_processed, ((f32) 1000 * context.lexer_lines_processed) / (duration));
+ printf(" Processed %llu tokens (%f tokens/second).\n", context.lexer_tokens_processed, ((f32) 1000 * context.lexer_tokens_processed) / (duration));
printf("\n");
}
default: break;
}
- switch (compiler_progress) {
- case ONYX_COMPILER_PROGRESS_FAILED_OUTPUT:
- bh_printf_err("Failed to open file for writing: '%s'\n", compile_opts.target_file);
- break;
+ if (compiler_progress == ONYX_COMPILER_PROGRESS_FAILED_OUTPUT) {
+ bh_printf_err("Failed to open file for writing: '%s'\n", compile_opts.target_file);
}
cleanup_compilation();
bh_arr_new(global_heap_allocator, poly_proc->poly_params, bh_arr_length(params));
fori (i, 0, bh_arr_length(params)) {
bh_arr_push(poly_proc->poly_params, ((AstPolyParam) {
- .kind = PSK_Type,
+ .kind = PPK_Poly_Type,
.idx = i,
.poly_sym = poly_params[i],
.type_expr = (AstType *) poly_params[i],
node = (AstNode *) sln->value;
break;
+
+ case PSK_Undefined: assert("Unexpected PSK_Undefined" && 0); break;
}
symbol_introduce(scope, sln->poly_sym->token, node);
SYMRES(type, &distinct->base_type);
break;
}
+
+ default: break;
}
return Symres_Success;
}
UnaryOp unop = Unary_Op_Count;
- switch (operator->operator_token->type) {
- case '?': unop = Unary_Op_Try; break;
+ if (operator->operator_token->type == (TokenType) '?') {
+ unop = Unary_Op_Try;
}
if (unop == Unary_Op_Count) {
package->package = current_entity->package;
return Symres_Complete;
}
+
+ default: assert("Bad directive in symres_process_directive" && 0); break;
}
return Symres_Success;
onyx_errors_enable();
return Symres_Success;
}
+
+ default: break;
}
return Symres_Success;
return 0;
default:
- assert(("Invalid type", 0));
+ assert("Invalid type" && 0);
break;
}
return u_type;
}
+
+ default: break;
}
return NULL;
AstInterface* inter = (AstInterface *) node;
return symbol_raw_resolve(inter->scope, symbol);
}
+
+ default: break;
}
return NULL;
overload = (AstFunction *) node;
arguments_clear_baked_flags(&args);
break;
+ default: break;
}
// NOTE: Overload is not something that is known to be overloadable.
return polymorphic_proc_build_only_header_with_slns(pp, slns, error_if_failed);
}
- default: assert(("Bad macro body type.", 0));
+ default: assert("Bad macro body type." && 0);
}
return NULL;
return type_structlike_mem_count(sl->type);
}
+
+ default: break;
}
// NOTE: This returns int_max for anything other than struct literals because the
AstInterface* inter = (AstInterface *) node;
return &inter->scope;
}
+
+ default: break;
}
return NULL;
}
bh_buffer_write_byte(&mod->debug_context->op_buffer, DOT_SYM);
- u32 leb_len=0;
+ i32 leb_len=0;
u8 *bytes = uint_to_uleb128(id, &leb_len);
bh_buffer_append(&mod->debug_context->op_buffer, bytes, leb_len);
bh_buffer_write_byte(&mod->debug_context->op_buffer, DOT_SET);
mod->debug_context->last_op_was_rep = 0;
- u32 leb_len=0;
+ i32 leb_len=0;
u8 *bytes = uint_to_uleb128(file_id, &leb_len);
bh_buffer_append(&mod->debug_context->op_buffer, bytes, leb_len);
case Binary_Op_Less: case Binary_Op_Less_Equal:
case Binary_Op_Greater: case Binary_Op_Greater_Equal:
is_sign_significant = 1;
+ default: break;
}
WasmType operator_type = onyx_type_to_wasm_type(binop->left->type);
case Unary_Op_Auto_Cast:
case Unary_Op_Cast: emit_cast(mod, &code, unop); break;
+
+ case Unary_Op_Try: // Should be handled in operator overload
+ case Unary_Op_Count:
+ break;
}
*pcode = code;
reserve_size += 4 + POINTER_SIZE;
break;
}
+
+ case VA_Kind_Not_VA:
+ break;
}
CallingConvention cc = type_function_get_cc(call->callee->type);
break;
}
- default: assert(("Unsupported intrinsic", 0));
+ default: assert("Unsupported intrinsic" && 0);
}
*pcode = code;
param_count += mem_count - 1;
break;
}
+
+ case Param_Pass_Invalid: assert("Invalid parameter passing" && 0);
}
param_type++;
case Ast_Kind_Global: wasm_export.kind = WASM_FOREIGN_GLOBAL;
break;
+
+ default: assert("Invalid export node" && 0);
}
shput(mod->exports, export->export_name->text, wasm_export);
case WASM_TYPE_FLOAT32: bh_arr_push(glob.initial_value, ((WasmInstruction) { WI_F32_CONST, 0 })); break;
case WASM_TYPE_FLOAT64: bh_arr_push(glob.initial_value, ((WasmInstruction) { WI_F64_CONST, 0 })); break;
- default: assert(("Invalid global type", 0)); break;
+ default: assert("Invalid global type" && 0); break;
}
bh_arr_set_at(module->globals, global_idx, glob);
// NOTE: Allocating more than necessary, but there are no cases
// in a string literal that create more bytes than already
// existed. You can create less however ('\n' => 0x0a).
- i8* strdata = bh_alloc_array(global_heap_allocator, i8, len + 1);
+ char* strdata = bh_alloc_array(global_heap_allocator, char, len + 1);
i32 length = string_process_escape_seqs(strdata, data, len);
i32 index = shgeti(mod->string_literals, (char *) strdata);
patch->data_id = ((AstMemRes *) patch->node_to_use_if_data_id_is_null)->data_id;
} else {
- assert(("Unexpected empty data_id in linking!", 0));
+ assert("Unexpected empty data_id in linking!" && 0);
}
}
output_limits(import->min, import->max, import->shared, &vec_buff);
break;
- case WASM_FOREIGN_TABLE: assert(0);
+ case WASM_FOREIGN_GLOBAL:
+ case WASM_FOREIGN_TABLE: assert("Bad foreign import kind" && 0);
}
}
continue;
}
- assert(("Unhandled type", 0));
+ assert("Unhandled type in debug info builder" && 0);
}
output_unsigned_integer(section_buff.length, buff);
i32 section_start = cursor;
if (section_number == 0) {
u64 name_len = uleb128_to_uint(wasm_bytes.data, &cursor);
- if (!strncmp(wasm_bytes.data + cursor, "_onyx_libs", name_len)) {
+ if (!strncmp((const char *) wasm_bytes.data + cursor, "_onyx_libs", name_len)) {
cursor += name_len;
u64 lib_count = uleb128_to_uint(wasm_bytes.data, &cursor);
lib_path_length = bh_min(lib_path_length, 512);
char *lib_path = malloc(lib_path_length);
- strncpy(lib_path, wasm_bytes.data + cursor, lib_path_length);
+ strncpy(lib_path, (const char *) wasm_bytes.data + cursor, lib_path_length);
lib_path[lib_path_length] = '\0';
bh_path_convert_separators(lib_path);
cursor += lib_path_length;
lib_name_length = bh_min(lib_name_length, 256);
char library_name[256];
- strncpy(library_name, wasm_bytes.data + cursor, lib_name_length);
+ strncpy(library_name, (const char *) wasm_bytes.data + cursor, lib_name_length);
library_name[lib_name_length] = '\0';
cursor += lib_name_length;
i32 section_start = cursor;
if (section_number == 0) {
u64 name_len = uleb128_to_uint(wasm_raw_bytes.data, &cursor);
- if (!strncmp(wasm_raw_bytes.data + cursor, "_onyx_func_offsets", name_len)) {
+ if (!strncmp((const char *) wasm_raw_bytes.data + cursor, "_onyx_func_offsets", name_len)) {
cursor += name_len;
func_name_section = cursor;
break;
if (func_name_section > 0) {
i32 cursor = func_name_section + 4 * func_idx;
i32 func_offset = *(i32 *) (wasm_raw_bytes.data + cursor);
- char* func_name = wasm_raw_bytes.data + func_name_section + func_offset;
+ char* func_name = (char *) wasm_raw_bytes.data + func_name_section + func_offset;
bh_printf(" func[%d]:%p at %s\n", func_idx, mod_offset, func_name);
} else {
wasm_byte_vec_t wasm_data;
wasm_data.size = wasm_bytes.length;
- wasm_data.data = wasm_bytes.data;
+ wasm_data.data = (wasm_byte_t *) wasm_bytes.data;
wasm_module = wasm_module_new(wasm_store, &wasm_data);
if (!wasm_module) {
break;
}
+
+ case Type_Kind_Invalid:
+ case Type_Kind_Count:
+ break;
}
}
typedef int32_t i32;
typedef int64_t i64;
typedef int64_t isize;
-typedef i32 b32;
+typedef u32 b32;
typedef void* ptr;
typedef float f32;
typedef double f64;
bh_file_contents bh_file_read_contents_bh_file(bh_allocator alloc, bh_file* file);
bh_file_contents bh_file_read_contents_direct(bh_allocator alloc, const char* filename);
-i32 bh_file_contents_free(bh_file_contents* contents);
+b32 bh_file_contents_free(bh_file_contents* contents);
#ifdef _BH_WINDOWS
#endif
}
-b32 bh_file_read(bh_file* file, void* buffer, isize buff_size) {
+i32 bh_file_read(bh_file* file, void* buffer, isize buff_size) {
return bh_file_read_at(file, bh_file_tell(file), buffer, buff_size, NULL);
}
-b32 bh_file_write(bh_file* file, void* buffer, isize buff_size) {
+i32 bh_file_write(bh_file* file, void* buffer, isize buff_size) {
return bh_file_write_at(file, bh_file_tell(file), buffer, buff_size, NULL);
}