Example #1
0
	void compile(const char* path, CompileOptions& opts)
	{
		Buffer unit_data(default_allocator());

		UnitCompiler uc(opts);
		uc.compile_unit(path);

		opts.write(uc.blob());
	}
Example #2
0
	void compile(CompileOptions& opts)
	{
		Buffer unit_data(default_allocator());

		UnitCompiler uc(opts);
		uc.compile_unit(opts.source_path());

		opts.write(uc.blob());
	}
Example #3
0
void *
malloc(size_t size)
{
	malloc_unit_t *unit;
	DPRINTF("size:%d\n", size);
	for (unit = unit_list_head; unit; unit = unit->next)
#ifdef DEBUG
	{
		if (unit->allocated)
			assert(unit->magic == 0xdeadbeef);
#endif
		if (!unit->allocated && unit->size >= size)
			break;
#ifdef DEBUG
	}
#endif
	if (unit->allocated)
	{
		printf("Ugh, no left memory!\n");
		DPRINTF("return:NULL\n");
		return 0;
	}
	if (unit->size > size + sizeof(malloc_unit_t))
	{
		malloc_unit_t *new_unit =(malloc_unit_t *)(unit_data(unit) + size);
#ifdef DEBUG
		new_unit->magic = 0xdeadbeef;
#endif
		new_unit->size = unit_tail(unit) - unit_data(new_unit);
		new_unit->allocated = false;
		unit->size = size;
		unit_add(new_unit, unit);
	}
	unit->allocated = true;
	DPRINTF("return:%x\n", unit_data(unit));
#ifdef DEBUG
	assert(md_memory_head() < (char *)unit_data(unit));
	assert(md_memory_tail() > (char *)unit_data(unit));
#endif
	return unit_data(unit);
}