buildflagset_t* buildflagset_create() { buildflagset_t* p = POOL_ALLOC(buildflagset_t); assert(p != NULL); p->have_os_flags = false; p->have_size_flags = false; p->started_enum = false; p->flags = POOL_ALLOC(flagtab_t); flagtab_init(p->flags, 8); p->text_buffer = NULL; p->buffer_size = 0; return p; }
static bool detect(pony_ctx_t* ctx, detector_t* d, view_t* view) { assert(view->perceived == NULL); scan_grey(d, view, 0); int count = scan_white(view); assert(count >= 0); if(count == 0) return false; d->detected++; perceived_t* per = (perceived_t*)POOL_ALLOC(perceived_t); per->token = d->next_token++; per->ack = 0; per->last_conf = HASHMAP_BEGIN; ponyint_viewmap_init(&per->map, count); ponyint_perceivedmap_put(&d->perceived, per); int count2 = collect_white(per, view, 0); (void)count2; assert(count2 == count); assert(ponyint_viewmap_size(&per->map) == (size_t)count); send_conf(ctx, d, per); return true; }
package_group_t* package_group_new() { package_group_t* group = POOL_ALLOC(package_group_t); group->signature = NULL; package_set_init(&group->members, 1); return group; }
errors_t* errors_alloc() { errors_t* errors = POOL_ALLOC(errors_t); memset(errors, 0, sizeof(errors_t)); errors->output_stream = stderr; return errors; }
void* pony_deserialise_offset(pony_ctx_t* ctx, pony_type_t* t, uintptr_t offset) { // If the high bit of the offset is set, it is either an unserialised // primitive, or an unserialised field in an opaque object. if((offset & HIGH_BIT) != 0) { offset &= ~HIGH_BIT; if(offset > __DescTableSize) return NULL; // Return the global instance, if there is one. It's ok to return null if // there is no global instance, as this will then be an unserialised // field in an opaque object. t = (&__DescTable)[offset]; return t->instance; } // Lookup the offset, return the associated object if there is one. serialise_t k; k.key = offset; serialise_t* s = ponyint_serialise_get(&ctx->serialise, &k); if(s != NULL) return (void*)s->value; // If we haven't been passed a type descriptor, read one. if(t == NULL) { // Make sure we have space to read a type id. if((offset + sizeof(uintptr_t)) > ctx->serialise_size) pony_throw(); // Turn the type id into a descriptor pointer. uintptr_t id = *(uintptr_t*)((uintptr_t)ctx->serialise_buffer + offset); t = (&__DescTable)[id]; } // If it's a primitive, return the global instance. if(t->instance != NULL) return t->instance; // Make sure we have space to read the object. if((offset + t->size) > ctx->serialise_size) pony_throw(); // Allocate the object, memcpy to it. void* object = pony_alloc(ctx, t->size); memcpy(object, (void*)((uintptr_t)ctx->serialise_buffer + offset), t->size); // Store a mapping of offset to object. s = POOL_ALLOC(serialise_t); s->key = offset; s->value = (uintptr_t)object; ponyint_serialise_put(&ctx->serialise, s); recurse(ctx, object, t->deserialise); return object; }
static void add_rmethod(reachable_method_stack_t** s, reachable_type_t* t, reachable_method_name_t* n, ast_t* typeargs) { const char* name = genname_fun(NULL, n->name, typeargs); reachable_method_t* m = reach_method(n, name); if(m == NULL) { m = POOL_ALLOC(reachable_method_t); m->name = name; m->typeargs = ast_dup(typeargs); m->vtable_index = (uint32_t)-1; ast_t* fun = lookup(NULL, NULL, t->type, n->name); if(typeargs != NULL) { // Reify the method with its typeargs, if it has any. AST_GET_CHILDREN(fun, cap, id, typeparams, params, result, can_error, body); ast_t* r_fun = reify(fun, typeparams, typeargs); ast_free_unattached(fun); fun = r_fun; } m->r_fun = ast_dup(fun); ast_free_unattached(fun); reachable_methods_put(&n->r_methods, m); // Put on a stack of reachable methods to trace. *s = reachable_method_stack_push(*s, m); } }
PONY_API asio_event_t* pony_asio_event_create(pony_actor_t* owner, int fd, uint32_t flags, uint64_t nsec, bool noisy) { if((flags == ASIO_DISPOSABLE) || (flags == ASIO_DESTROYED)) return NULL; pony_type_t* type = *(pony_type_t**)owner; uint32_t msg_id = type->event_notify; if(msg_id == (uint32_t)-1) return NULL; asio_event_t* ev = POOL_ALLOC(asio_event_t); ev->magic = ev; ev->owner = owner; ev->msg_id = msg_id; ev->fd = fd; ev->flags = flags; ev->noisy = noisy; ev->nsec = nsec; ev->writeable = false; ev->readable = false; // The event is effectively being sent to another thread, so mark it here. pony_ctx_t* ctx = pony_ctx(); pony_gc_send(ctx); pony_traceknown(ctx, owner, type, PONY_TRACE_OPAQUE); pony_send_done(ctx); pony_asio_event_subscribe(ev); return ev; }
/* 7.4 */ SWmlString * insertString(SDocData *data, PString s) { /* * Place a copy of 's' into the 'm_stringTable' of DocData, * and treat it as 'inline'. * *--------------------------------------------------------------------------- */ /* Data Structures */ SWmlString *_node; /* Code */ POOL_ALLOC(DOCPOOL, _node); _node->m_string = strXDup(s,DOCPOOL); _node->m_site = STR_INLINE; _node->m_offset = ~0; if(STR_LEN(s)) { SLL_INSERT(data->m_stringTable[ (*(STR_DATA(s)))&0x7f], _node); } else { SLL_INSERT(data->m_stringTable[0], _node); } return _node; }
builder_t* builder_create(const char* description) { if(description == NULL) return NULL; source_t* source = source_open_string(description); symtab_t* symtab = symtab_new(); ast_t* ast = build_ast(source, symtab); if(ast == NULL) { // Error, tidy up source_close(source); symtab_free(symtab); return NULL; } // Success, create builder builder_t* builder = POOL_ALLOC(builder_t); builder->sources = NULL; builder->defs = symtab; builder->dummy_root = ast_blank(TK_TEST); ast_add(builder->dummy_root, ast); add_source(builder, source); return builder; }
static void add_rmethod_to_subtype(reach_t* r, reach_type_t* t, reach_method_name_t* n, reach_method_t* m, pass_opt_t* opt) { // Add the method to the type if it isn't already there. reach_method_name_t* n2 = add_method_name(t, n->name); add_rmethod(r, t, n2, m->cap, m->typeargs, opt); // Add this mangling to the type if it isn't already there. reach_method_t* mangled = reach_mangled_get(&n2->r_mangled, m); if(mangled != NULL) return; mangled = POOL_ALLOC(reach_method_t); memset(mangled, 0, sizeof(reach_method_t)); mangled->name = m->name; mangled->mangled_name = m->mangled_name; mangled->full_name = make_full_name(t, mangled); mangled->cap = m->cap; mangled->r_fun = ast_dup(m->r_fun); mangled->typeargs = ast_dup(m->typeargs); mangled->forwarding = true; mangled->param_count = m->param_count; mangled->params = (reach_param_t*)ponyint_pool_alloc_size( mangled->param_count * sizeof(reach_param_t)); memcpy(mangled->params, m->params, m->param_count * sizeof(reach_param_t)); mangled->result = m->result; // Add to the mangled table only. reach_mangled_put(&n2->r_mangled, mangled); }
// Add the given AST to the given list, under the specified name static void doc_list_add(ast_list_t* list, ast_t* ast, const char* name) { assert(list != NULL); assert(ast != NULL); ast_list_t* n = POOL_ALLOC(ast_list_t); n->ast = ast; n->name = name; n->next = NULL; // Find where to add name in sorted list ast_list_t* prev = list; for(ast_list_t* p = prev->next; p != NULL; prev = p, p = p->next) { assert(p->name != NULL); if(strcmp(p->name, name) > 0) { // Add new node before p n->next = p; prev->next = n; return; } } // Add new node at end of list prev->next = n; }
static void add_method(reachable_method_stack_t** s, reachable_type_t* t, const char* name, ast_t* typeargs) { reachable_method_name_t* n = reach_method_name(t, name); if(n == NULL) { n = POOL_ALLOC(reachable_method_name_t); n->name = name; reachable_methods_init(&n->r_methods, 0); reachable_method_names_put(&t->methods, n); } add_rmethod(s, t, n, typeargs); // Add to subtypes if we're an interface or trait. ast_t* def = (ast_t*)ast_data(t->type); switch(ast_id(def)) { case TK_INTERFACE: case TK_TRAIT: { size_t i = HASHMAP_BEGIN; reachable_type_t* t2; while((t2 = reachable_type_cache_next(&t->subtypes, &i)) != NULL) add_method(s, t2, name, typeargs); break; } default: {} } }
static proto_t* init() { proto_t* p = POOL_ALLOC(proto_t); proto_reset(p); return p; }
/* 7.7 */ SWmlToken * addTokenWithStr(SDocData *data, UINT16 code, PString str, ESite site) { /* * Append a new node for 'code' and 'str' to the list of WML tokens. * If str has never been seen before, create a new entry for it to remember, * otherwise treat the string entry as going to string table of the * output stream. * Note: site==STR_IN_TABLE only when it was called for unknown element * or attribute. *--------------------------------------------------------------------------- */ /* Data Structures */ SWmlToken * _node; SWmlString * _strEntry = str ? lookupString(data,str) : 0; /* Code */ if(site==STR_OPAQUE_DATE && str && STR_LEN(str)) { POOL_ALLOC(DOCPOOL, _strEntry); _strEntry->m_string = strXDup(str,DOCPOOL); _strEntry->m_site = STR_OPAQUE_DATE; _strEntry->m_offset = ~0; SLL_INSERT(data->m_stringTable[0], _strEntry); } else if(_strEntry) { /* it has been seen */ appendToTbl(data,_strEntry, 0); /* 0: try to insert */ } else if(str) { _strEntry = insertString(data,str); if(site==STR_IN_TABLE) { appendToTbl(data,_strEntry, 1); /* 1: must insert */ } } /* If _strEntry is still NULL, it behaves as 'addToken'. */ POOL_ALLOC(DOCPOOL, _node); _node->m_code = code; _node->m_strEntry = _strEntry; FIFO_INSERT(data->m_tokenList, _node); return _node; }
static flag_t* flag_dup(flag_t* flag) { assert(flag != NULL); flag_t* f = POOL_ALLOC(flag_t); memcpy(f, flag, sizeof(flag_t)); return f; }
token_t* token_dup(token_t* token) { assert(token != NULL); token_t* t = POOL_ALLOC(token_t); memcpy(t, token, sizeof(token_t)); t->printed = NULL; return t; }
reach_t* reach_new() { reach_t* r = POOL_ALLOC(reach_t); r->stack = NULL; r->next_type_id = 0; reach_types_init(&r->types, 64); return r; }
static bnf_t* bnf_create(bnf_id id) { bnf_t* b = POOL_ALLOC(bnf_t); memset(b, 0, sizeof(bnf_t)); b->id = id; return b; }
void package_add_magic(const char* path, const char* src) { magic_package_t* n = POOL_ALLOC(magic_package_t); n->path = stringtab(path); n->src = src; n->next = magic_packages; magic_packages = n; }
void codegen_setlocal(compile_t* c, const char* name, LLVMValueRef alloca) { compile_local_t* p = POOL_ALLOC(compile_local_t); p->name = name; p->alloca = alloca; compile_locals_put(&c->frame->locals, p); }
bool parse(ast_t* package, source_t* source, rule_t start, const char* expected) { assert(package != NULL); assert(source != NULL); assert(expected != NULL); // Open the lexer lexer_t* lexer = lexer_open(source); if(lexer == NULL) return false; // Create a parser and attach the lexer parser_t* parser = POOL_ALLOC(parser_t); parser->source = source; parser->lexer = lexer; parser->token = lexer_next(lexer); parser->last_matched = NULL; parser->last_token_line = 0; parser->next_flags = 0; parser->failed = false; // Parse given start rule builder_fn_t build_fn; ast_t* ast = start(parser, &build_fn, expected); if(ast == PARSE_ERROR) ast = NULL; if(ast == RULE_NOT_FOUND) { syntax_error(parser, expected, NULL, NULL); ast = NULL; } if(parser->failed) { ast_free(ast); ast = NULL; } lexer_close(lexer); token_free(parser->token); POOL_FREE(parser_t, parser); if(ast == NULL) { source_close(source); return false; } assert(ast_id(ast) == TK_MODULE); assert(ast_data(ast) == NULL); ast_setdata(ast, source); ast_add(package, ast); return true; }
void* heap_alloc_small(pony_actor_t* actor, heap_t* heap, uint32_t sizeclass) { chunk_t* chunk = heap->small_free[sizeclass]; void* m; // If there are none in this size class, get a new one. if(chunk != NULL) { // Clear and use the first available slot. uint32_t slots = chunk->slots; uint32_t bit = __pony_ffs(slots) - 1; slots &= ~(1 << bit); m = chunk->m + (bit << HEAP_MINBITS); chunk->slots = slots; if(slots == 0) { heap->small_free[sizeclass] = chunk->next; chunk->next = heap->small_full[sizeclass]; heap->small_full[sizeclass] = chunk; } } else { chunk_t* n = (chunk_t*) POOL_ALLOC(chunk_t); n->actor = actor; n->m = (char*) POOL_ALLOC(block_t); n->size = sizeclass; // Clear the first bit. n->shallow = n->slots = sizeclass_init[sizeclass]; n->next = NULL; pagemap_set(n->m, n); heap->small_free[sizeclass] = n; chunk = n; // Use the first slot. m = chunk->m; } heap->used += SIZECLASS_SIZE(sizeclass); return m; }
void mpmcq_push(mpmcq_t* q, void* data) { mpmcq_node_t* node = POOL_ALLOC(mpmcq_node_t); node->data = data; node->next = NULL; mpmcq_node_t* prev = (mpmcq_node_t*)_atomic_exchange(&q->head, node); _atomic_store(&prev->next, node); }
token_t* token_new(token_id id, source_t* source) { token_t* t = POOL_ALLOC(token_t); memset(t, 0, sizeof(token_t)); t->id = id; t->source = source; t->debug_info = true; return t; }
void package_add_magic_src(const char* path, const char* src, pass_opt_t* opt) { magic_package_t* n = POOL_ALLOC(magic_package_t); n->path = stringtab(path); n->src = src; n->mapped_path = NULL; n->next = opt->magic_packages; opt->magic_packages = n; }
printbuf_t* printbuf_new() { printbuf_t* buf = POOL_ALLOC(printbuf_t); buf->m = (char*)malloc(32); buf->m[0] = '\0'; buf->size = 32; buf->offset = 0; return buf; }
printbuf_t* printbuf_new() { printbuf_t* buf = POOL_ALLOC(printbuf_t); buf->m = (char*)ponyint_pool_alloc_size(32); buf->m[0] = '\0'; buf->size = 32; buf->offset = 0; return buf; }
void mpmcq_init(mpmcq_t* q) { mpmcq_node_t* node = POOL_ALLOC(mpmcq_node_t); node->data = NULL; node->next = NULL; q->head = node; q->tail.node = node; }
static actorref_t* actorref_alloc(pony_actor_t* actor, uint32_t mark) { actorref_t* aref = (actorref_t*)POOL_ALLOC(actorref_t); memset(aref, 0, sizeof(actorref_t)); aref->actor = actor; // a new actorref is unmarked aref->mark = mark - 1; return aref; }
// Add a source to the builder static void add_source(builder_t* builder, source_t* source) { assert(builder != NULL); assert(source != NULL); builder_src_t* newsrc = POOL_ALLOC(builder_src_t); newsrc->source = source; newsrc->next = builder->sources; builder->sources = newsrc; }