Beispiel #1
0
bool LibJITFormula::buildFunction ()
{
	// Create a context
	jit_context_t context;
	context = jit_context_create ();
	jit_context_build_start (context);

	// Create a signature for double (*func)();
	jit_type_t signature;
	signature = jit_type_create_signature (jit_abi_cdecl, jit_type_float64,
	                                       NULL, 0, 1);

	// Create a function
	function = jit_function_create (context, signature);

	// Return the result of compiling the whole mess
	jit_value_t val;
	val = (jit_value_t)parseTree->generate (this);
	if (!val)
		return false;

	jit_insn_return (function, val);
	jit_context_build_end (context);

	if (!jit_function_compile (function))
	{
		jit_function_abandon (function);
		return false;
	}

	func = (FunctionPointer)jit_function_to_closure (function);
	if (!func)
	{
		jit_function_abandon (function);
		return false;
	}

	return true;
}
Beispiel #2
0
static void
function_dealloc(PyJitFunction *self)
{
    if (self->weakreflist)
        PyObject_ClearWeakRefs((PyObject *)self);

    if (self->function) {
        PYJIT_BEGIN_ALLOW_EXCEPTION
        if (pyjit_weak_cache_delitem(function_cache,
                                     (long)self->function) < 0) {
            PYJIT_TRACE("this shouldn't have happened");
            abort();
        }
        PYJIT_END_ALLOW_EXCEPTION

        jit_function_abandon(self->function);
    }