ox

The Ox programming language, compiler and tools (WIP)
Log | Files | Refs | README | LICENSE

typer.c (788B)



#include "typer.h"
#include "utils.h"
#include <string.h>

static const char*
c_types_to_ox_str(const char* ctype)
{
	if (strcmp(ctype, "__int32_t") == 0) {
		return "i32";
	} else if (strcmp(ctype, "__int64_t") == 0) {
		return "i64";
	} else {
		return "UNKNOWN C TYPE";
	}
}

void
types_match_or_panic(Node* node, gcc_jit_type* expect, gcc_jit_type* actual)
{
	if (!gcc_jit_compatible_types(expect, actual)) {
		gcc_jit_object* obj_a = gcc_jit_type_as_object(expect);
		gcc_jit_object* obj_b = gcc_jit_type_as_object(actual);
		const char* type_a = c_types_to_ox_str(gcc_jit_object_get_debug_string(obj_a));
		const char* type_b = c_types_to_ox_str(gcc_jit_object_get_debug_string(obj_b));
		panic_at(node, "Incompatible types: expected type <%s>, but got <%s>", type_a, type_b);
	}
}