Alien-LibJIT
view release on metacpan or search on metacpan
libjit/dpas/dpas-function.c view on Meta::CPAN
/*
* dpas-function.c - Special handling for Dynamic Pascal functions.
*
* Copyright (C) 2004 Southern Storm Software, Pty Ltd.
*
* This file is part of the libjit library.
*
* The libjit library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 2.1 of
* the License, or (at your option) any later version.
*
* The libjit library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the libjit library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include "dpas-internal.h"
static jit_context_t current_context;
static jit_function_t *function_stack = 0;
static int function_stack_size = 0;
static jit_function_t *main_list = 0;
static int main_list_size = 0;
jit_context_t dpas_current_context(void)
{
if(!current_context)
{
current_context = jit_context_create();
if(!current_context)
{
dpas_out_of_memory();
}
}
return current_context;
}
jit_function_t dpas_current_function(void)
{
if(function_stack_size > 0)
{
return function_stack[function_stack_size - 1];
}
else
{
/* We are probably compiling the "main" method for this module */
jit_type_t signature = jit_type_create_signature
(jit_abi_cdecl, jit_type_void, 0, 0, 1);
if(!signature)
{
dpas_out_of_memory();
}
return dpas_new_function(signature);
}
}
jit_function_t dpas_new_function(jit_type_t signature)
{
jit_function_t func;
func = jit_function_create(dpas_current_context(), signature);
if(!func)
{
dpas_out_of_memory();
}
function_stack = (jit_function_t *)jit_realloc
(function_stack, sizeof(jit_function_t) * (function_stack_size + 1));
if(!function_stack)
{
dpas_out_of_memory();
}
function_stack[function_stack_size++] = func;
return func;
}
( run in 1.749 second using v1.01-cache-2.11-cpan-df04353d9ac )