new as a user-level procedure

This commit is contained in:
Ginger Bill
2017-06-25 22:31:30 +01:00
parent 4e7150b470
commit 3ab481df17
5 changed files with 13 additions and 8 deletions
+1 -5
View File
@@ -4,11 +4,7 @@ import (
proc main() {
proc new_type(T: type) -> ^T {
return ^T(alloc(size_of(T), align_of(T)));
}
var ptr = new_type(int);
var ptr = new(int);
ptr^ = 123;
fmt.println(ptr^);
+5
View File
@@ -264,6 +264,11 @@ proc resize(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGN
}
proc new(T: type) -> ^T {
return ^T(alloc(size_of(T), align_of(T)));
}
proc default_resize_align(old_memory: rawptr, old_size, new_size, alignment: int) -> rawptr {
if old_memory == nil {
+3 -1
View File
@@ -3784,7 +3784,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
switch (id) {
case BuiltinProc_new:
// case BuiltinProc_new:
case BuiltinProc_make:
case BuiltinProc_size_of:
case BuiltinProc_align_of:
@@ -3878,6 +3878,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->type = type;
} break;
#if 0
case BuiltinProc_new: {
// proc new(Type) -> ^Type
Operand op = {};
@@ -3890,6 +3891,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
operand->mode = Addressing_Value;
operand->type = make_type_pointer(c->allocator, type);
} break;
#endif
#if 0
case BuiltinProc_new_slice: {
// proc new_slice(Type, len: int) -> []Type
+2 -2
View File
@@ -27,7 +27,7 @@ enum BuiltinProcId {
BuiltinProc_len,
BuiltinProc_cap,
BuiltinProc_new,
// BuiltinProc_new,
BuiltinProc_make,
BuiltinProc_free,
@@ -75,7 +75,7 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
{STR_LIT("len"), 1, false, Expr_Expr},
{STR_LIT("cap"), 1, false, Expr_Expr},
{STR_LIT("new"), 1, false, Expr_Expr},
// {STR_LIT("new"), 1, false, Expr_Expr},
{STR_LIT("make"), 1, true, Expr_Expr},
{STR_LIT("free"), 1, false, Expr_Stmt},
+2
View File
@@ -3772,6 +3772,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
} break;
#if 0
case BuiltinProc_new: {
ir_emit_comment(proc, str_lit("new"));
// proc new(Type) -> ^Type
@@ -3807,6 +3808,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
}
return v;
} break;
#endif
case BuiltinProc_make: {
ir_emit_comment(proc, str_lit("make"));