static bool genfun_allocator(compile_t* c, gentype_t* g) { // No allocator for primitive types or pointers. if((g->primitive != NULL) || is_pointer(g->ast)) return true; const char* funname = genname_fun(g->type_name, "Alloc", NULL); LLVMTypeRef ftype = LLVMFunctionType(g->use_type, NULL, 0, false); LLVMValueRef fun = codegen_addfun(c, funname, ftype); codegen_startfun(c, fun, false); LLVMValueRef result; switch(g->underlying) { case TK_PRIMITIVE: case TK_CLASS: // Allocate the object or return the global instance. result = gencall_alloc(c, g); break; case TK_ACTOR: // Allocate the actor. result = gencall_create(c, g); break; default: assert(0); return false; } LLVMBuildRet(c->builder, result); codegen_finishfun(c); return true; }
static LLVMValueRef create_main(compile_t* c, gentype_t* g) { // Create the main actor and become it. LLVMValueRef actor = gencall_create(c, g); LLVMValueRef object = LLVMBuildBitCast(c->builder, actor, c->object_ptr, ""); gencall_runtime(c, "pony_become", &object, 1, ""); return object; }
LLVMValueRef gencall_alloc(compile_t* c, reach_type_t* t) { // Do nothing for primitives. if(t->primitive != NULL) return NULL; // Do nothing for Pointer and Maybe. if(is_pointer(t->ast) || is_maybe(t->ast)) return NULL; // Use the global instance if we have one. if(t->instance != NULL) return t->instance; if(t->underlying == TK_ACTOR) return gencall_create(c, t); return gencall_allocstruct(c, t); }