Replace many built-in procedures with user-level procedures

This commit is contained in:
Ginger Bill
2017-07-04 23:52:00 +01:00
parent 36392d658e
commit 3d2d461867
7 changed files with 248 additions and 120 deletions
+8 -6
View File
@@ -4217,7 +4217,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->type = type;
} break;
#if 1
#if 0
case BuiltinProc_free: {
// proc free(^Type)
// proc free([]Type)
@@ -4250,6 +4250,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
#endif
#if 0
case BuiltinProc_reserve: {
// proc reserve([dynamic]Type, count: int) {
// proc reserve(map[Key]Type, count: int) {
@@ -4276,7 +4277,8 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->type = NULL;
operand->mode = Addressing_NoValue;
} break;
#endif
#if 0
case BuiltinProc_clear: {
Type *type = operand->type;
bool is_pointer = is_type_pointer(type);
@@ -4291,7 +4293,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->type = NULL;
operand->mode = Addressing_NoValue;
} break;
#endif
#if 0
case BuiltinProc_append: {
// proc append([dynamic]Type, item: ..Type)
@@ -4341,7 +4343,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->type = t_int;
} break;
#endif
#if 0
case BuiltinProc_delete: {
// proc delete(map[Key]Value, key: Key)
Type *type = operand->type;
@@ -4372,6 +4374,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->mode = Addressing_NoValue;
} break;
#endif
case BuiltinProc_size_of: {
@@ -4701,7 +4704,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
} break;
#if 1
#if 0
case BuiltinProc_slice_ptr: {
// proc slice_ptr(a: ^T, len: int) -> []T
// proc slice_ptr(a: ^T, len, cap: int) -> []T
@@ -4759,7 +4762,6 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->mode = Addressing_Value;
} break;
#endif
case BuiltinProc_expand_to_tuple: {
Type *type = base_type(operand->type);
if (!is_type_struct(type) &
+12 -26
View File
@@ -29,12 +29,12 @@ enum BuiltinProcId {
// BuiltinProc_new,
BuiltinProc_make,
BuiltinProc_free,
// BuiltinProc_free,
BuiltinProc_reserve,
BuiltinProc_clear,
// BuiltinProc_reserve,
// BuiltinProc_clear,
// BuiltinProc_append,
BuiltinProc_delete,
// BuiltinProc_delete,
BuiltinProc_size_of,
BuiltinProc_align_of,
@@ -51,8 +51,8 @@ enum BuiltinProcId {
BuiltinProc_imag,
BuiltinProc_conj,
BuiltinProc_slice_ptr,
BuiltinProc_slice_to_bytes,
// BuiltinProc_slice_ptr,
// BuiltinProc_slice_to_bytes,
BuiltinProc_expand_to_tuple,
@@ -61,12 +61,6 @@ enum BuiltinProcId {
BuiltinProc_abs,
BuiltinProc_clamp,
/* BuiltinProc_sqrt,
BuiltinProc_sin,
BuiltinProc_cos,
BuiltinProc_tan,
BuiltinProc_pow, */
BuiltinProc_transmute,
BuiltinProc_DIRECTIVE, // NOTE(bill): This is used for specialized hash-prefixed procedures
@@ -81,12 +75,12 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
// {STR_LIT("new"), 1, false, Expr_Expr},
{STR_LIT("make"), 1, true, Expr_Expr},
{STR_LIT("free"), 1, false, Expr_Stmt},
// {STR_LIT("free"), 1, false, Expr_Stmt},
{STR_LIT("reserve"), 2, false, Expr_Stmt},
{STR_LIT("clear"), 1, false, Expr_Stmt},
// {STR_LIT("reserve"), 2, false, Expr_Stmt},
// {STR_LIT("clear"), 1, false, Expr_Stmt},
// {STR_LIT("append"), 1, true, Expr_Expr},
{STR_LIT("delete"), 2, false, Expr_Stmt},
// {STR_LIT("delete"), 2, false, Expr_Stmt},
{STR_LIT("size_of"), 1, false, Expr_Expr},
{STR_LIT("align_of"), 1, false, Expr_Expr},
@@ -103,8 +97,8 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
{STR_LIT("imag"), 1, false, Expr_Expr},
{STR_LIT("conj"), 1, false, Expr_Expr},
{STR_LIT("slice_ptr"), 2, true, Expr_Expr},
{STR_LIT("slice_to_bytes"), 1, false, Expr_Stmt},
// {STR_LIT("slice_ptr"), 2, true, Expr_Expr},
// {STR_LIT("slice_to_bytes"), 1, false, Expr_Expr},
{STR_LIT("expand_to_tuple"), 1, false, Expr_Expr},
@@ -113,14 +107,6 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
{STR_LIT("abs"), 1, false, Expr_Expr},
{STR_LIT("clamp"), 3, false, Expr_Expr},
/*
{STR_LIT("__sqrt"), 1, false, Expr_Expr},
{STR_LIT("__sin"), 1, false, Expr_Expr},
{STR_LIT("__cos"), 1, false, Expr_Expr},
{STR_LIT("__tan"), 1, false, Expr_Expr},
{STR_LIT("__pow"), 2, false, Expr_Expr},
*/
{STR_LIT("transmute"), 2, false, Expr_Expr},
{STR_LIT(""), 0, true, Expr_Expr}, // DIRECTIVE
+8 -7
View File
@@ -3922,7 +3922,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
}
} break;
#if 1
#if 0
case BuiltinProc_free: {
ir_emit_comment(proc, str_lit("free"));
@@ -3997,7 +3997,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
return ir_emit_global_call(proc, "free_ptr", args, 1);
} break;
#endif
#if 0
case BuiltinProc_reserve: {
ir_emit_comment(proc, str_lit("reserve"));
gbAllocator a = proc->module->allocator;
@@ -4032,7 +4032,8 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
GB_PANIC("Unknown type for `reserve`");
}
} break;
#endif
#if 0
case BuiltinProc_clear: {
ir_emit_comment(proc, str_lit("clear"));
Type *original_type = type_of_expr(proc->module->info, ce->args[0]);
@@ -4058,7 +4059,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
}
return NULL;
} break;
#endif
#if 0
case BuiltinProc_append: {
ir_emit_comment(proc, str_lit("append"));
@@ -4169,7 +4170,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
return ir_emit_global_call(proc, "__dynamic_array_append", daa_args, 5);
} break;
#endif
#if 0
case BuiltinProc_delete: {
ir_emit_comment(proc, str_lit("delete"));
irValue *map = ir_build_expr(proc, ce->args[0]);
@@ -4186,7 +4187,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
args[1] = ir_gen_map_key(proc, key, key_type);
return ir_emit_global_call(proc, "__dynamic_map_delete", args, 2);
} break;
#endif
case BuiltinProc_swizzle: {
ir_emit_comment(proc, str_lit("swizzle.begin"));
@@ -4260,7 +4261,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
return ir_emit_load(proc, res);
} break;
#if 1
#if 0
case BuiltinProc_slice_ptr: {
ir_emit_comment(proc, str_lit("slice_ptr"));
irValue *ptr = ir_build_expr(proc, ce->args[0]);
+3
View File
@@ -919,6 +919,9 @@ bool is_type_untyped_undef(Type *t) {
bool is_type_valid_for_keys(Type *t) {
t = core_type(t);
if (t->kind == Type_Generic) {
return true;
}
if (is_type_untyped(t)) {
return false;
}