2012-05-23 21:26:15 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gbx_jit.c
|
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
(c) 2018 Benoît Minisini <g4mba5@gmail.com>
|
2012-05-23 21:26:15 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBX_JIT_C
|
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_common_buffer.h"
|
|
|
|
#include "gb_common_case.h"
|
|
|
|
#include "gbx_component.h"
|
2018-05-28 03:18:44 +02:00
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_object.h"
|
2012-05-23 21:26:15 +02:00
|
|
|
#include "gbx_api.h"
|
2018-05-26 16:50:00 +02:00
|
|
|
#include "gbx_jit.h"
|
|
|
|
|
2018-06-01 03:50:42 +02:00
|
|
|
typedef
|
|
|
|
struct {
|
|
|
|
JIT_FUNC addr;
|
|
|
|
PCODE *code;
|
|
|
|
}
|
|
|
|
JIT_FUNCTION;
|
|
|
|
|
2018-08-11 07:53:02 +02:00
|
|
|
bool JIT_disabled = FALSE;
|
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
static bool _component_loaded = FALSE;
|
2018-06-01 03:50:42 +02:00
|
|
|
static GB_FUNCTION _jit_compile_func;
|
2019-03-11 16:34:50 +01:00
|
|
|
static GB_FUNCTION _jit_wait_func;
|
2012-05-23 21:26:15 +02:00
|
|
|
|
2019-04-04 22:58:06 +02:00
|
|
|
static char _jit_state = JIT_NOT_COMPILED;
|
2018-05-26 16:50:00 +02:00
|
|
|
static void *_jit_library = NULL;
|
2012-05-23 21:26:15 +02:00
|
|
|
|
2018-06-01 03:50:42 +02:00
|
|
|
static JIT_FUNCTION *_jit_func = NULL;
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
static bool _debug = FALSE;
|
|
|
|
|
2020-09-17 23:51:13 +02:00
|
|
|
static void find_method(GB_FUNCTION *func, const char *method, const char *sign, const char *type)
|
|
|
|
{
|
|
|
|
if (GB_GetFunction(func, CLASS_find_global("Jit"), method, sign, type))
|
|
|
|
ERROR_panic("Unable to find JIT.&1() method", method);
|
|
|
|
}
|
|
|
|
|
2021-06-05 14:29:58 +02:00
|
|
|
void JIT_init(void)
|
|
|
|
{
|
|
|
|
char *var = getenv("GB_NO_JIT");
|
|
|
|
if (var && var[0] && !(var[0] == '0' && var[1] == 0))
|
|
|
|
JIT_disabled = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-03-11 16:34:50 +01:00
|
|
|
void JIT_abort(void)
|
|
|
|
{
|
2020-09-17 23:51:13 +02:00
|
|
|
GB_FUNCTION func;
|
2019-03-11 16:34:50 +01:00
|
|
|
|
2019-03-13 12:59:14 +01:00
|
|
|
if (!_component_loaded || JIT_disabled)
|
2019-03-11 17:53:18 +01:00
|
|
|
return;
|
|
|
|
|
2020-09-17 23:51:13 +02:00
|
|
|
find_method(&func, "_Abort", NULL, NULL);
|
|
|
|
GB_Call(&func, 0, FALSE);
|
2022-04-13 02:24:55 +02:00
|
|
|
GB_Wait(-1);
|
2020-03-02 14:20:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void JIT_exit(void)
|
|
|
|
{
|
|
|
|
ARRAY_delete(&_jit_func);
|
2019-03-11 16:34:50 +01:00
|
|
|
}
|
|
|
|
|
2019-04-04 22:58:06 +02:00
|
|
|
static int get_state(ARCHIVE *arch)
|
|
|
|
{
|
|
|
|
return arch ? arch->jit_state : _jit_state;
|
|
|
|
}
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
bool JIT_can_compile(ARCHIVE *arch)
|
|
|
|
{
|
2019-04-04 22:58:06 +02:00
|
|
|
return get_state(arch) == JIT_NOT_COMPILED;
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 16:34:50 +01:00
|
|
|
void JIT_compile(ARCHIVE *arch)
|
2012-05-24 01:39:02 +02:00
|
|
|
{
|
2018-06-09 22:42:35 +02:00
|
|
|
COMPONENT *current;
|
2012-05-23 21:26:15 +02:00
|
|
|
|
2018-08-11 07:53:02 +02:00
|
|
|
if (JIT_disabled)
|
2019-03-11 16:34:50 +01:00
|
|
|
return;
|
2012-05-23 21:26:15 +02:00
|
|
|
|
2019-03-11 16:34:50 +01:00
|
|
|
if (arch ? arch->jit_library : _jit_library)
|
|
|
|
return;
|
2012-05-23 21:26:15 +02:00
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
if (!_component_loaded)
|
2012-05-23 21:26:15 +02:00
|
|
|
{
|
2018-06-09 22:42:35 +02:00
|
|
|
char *var;
|
2020-09-14 21:15:20 +02:00
|
|
|
GB_FUNCTION init_func;
|
|
|
|
GB_VALUE *ret;
|
2012-05-26 00:24:13 +02:00
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
_component_loaded = TRUE;
|
2012-05-23 21:26:15 +02:00
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
var = getenv("GB_JIT_DEBUG");
|
|
|
|
if (var && var[0] && !(var[0] == '0' && var[1] == 0))
|
|
|
|
_debug = TRUE;
|
|
|
|
|
|
|
|
if (_debug)
|
|
|
|
fprintf(stderr, "gbx3: loading gb.jit component\n");
|
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
COMPONENT_load(COMPONENT_create("gb.jit"));
|
2020-09-14 21:15:20 +02:00
|
|
|
|
|
|
|
find_method(&init_func, "_Search", NULL, NULL);
|
|
|
|
|
|
|
|
ret = GB_Call(&init_func, 0, FALSE);
|
|
|
|
if (ret->_boolean.value)
|
|
|
|
{
|
|
|
|
JIT_disabled = TRUE;
|
|
|
|
fprintf(stderr, "gbx3: no compiler found. JIT is disabled.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
find_method(&_jit_compile_func, "_Compile", "s", "b");
|
|
|
|
find_method(&_jit_wait_func, "_Wait", "s", "s");
|
2012-05-23 21:26:15 +02:00
|
|
|
}
|
2012-06-01 02:18:38 +02:00
|
|
|
|
2019-04-04 22:58:06 +02:00
|
|
|
arch ? (arch->jit_state = JIT_COMPILING) : (_jit_state = JIT_COMPILING);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
current = COMPONENT_current;
|
|
|
|
COMPONENT_current = NULL;
|
|
|
|
|
|
|
|
GB_Push(1, T_STRING, arch ? arch->name : "", -1);
|
2019-03-11 16:34:50 +01:00
|
|
|
GB_Call(&_jit_compile_func, 1, FALSE);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
COMPONENT_current = current;
|
2019-03-11 16:34:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool wait_for_compilation(ARCHIVE *arch)
|
|
|
|
{
|
|
|
|
COMPONENT *current;
|
|
|
|
void *lib;
|
|
|
|
void **iface;
|
|
|
|
GB_VALUE *ret;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
if (JIT_disabled)
|
|
|
|
return TRUE;
|
2018-06-09 22:42:35 +02:00
|
|
|
|
2019-03-11 16:34:50 +01:00
|
|
|
if (arch ? arch->jit_library : _jit_library)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
current = COMPONENT_current;
|
|
|
|
COMPONENT_current = NULL;
|
|
|
|
|
|
|
|
GB_Push(1, T_STRING, arch ? arch->name : "", -1);
|
|
|
|
ret = GB_Call(&_jit_wait_func, 1, FALSE);
|
|
|
|
|
|
|
|
COMPONENT_current = current;
|
2018-05-26 16:50:00 +02:00
|
|
|
|
2019-04-04 22:58:06 +02:00
|
|
|
arch ? (arch->jit_state = JIT_COMPILED) : (_jit_state = JIT_COMPILED);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
2019-03-11 16:34:50 +01:00
|
|
|
path = GB_ToZeroString((GB_STRING *)ret);
|
|
|
|
if (!*path)
|
|
|
|
ERROR_panic("Unable to compile JIT source file");
|
|
|
|
|
2018-05-28 03:18:44 +02:00
|
|
|
//fprintf(stderr, "gbx3: shared jit library is: %s\n", path);
|
2018-05-26 16:50:00 +02:00
|
|
|
|
|
|
|
lib = dlopen(path, RTLD_NOW);
|
|
|
|
if (!lib)
|
2018-07-03 00:52:19 +02:00
|
|
|
ERROR_panic("Unable to load JIT library: %s", dlerror());
|
2018-05-26 16:50:00 +02:00
|
|
|
|
|
|
|
if (arch)
|
|
|
|
arch->jit_library = lib;
|
|
|
|
else
|
|
|
|
_jit_library = lib;
|
|
|
|
|
2018-05-28 03:18:44 +02:00
|
|
|
iface = dlsym(lib, "GB_PTR");
|
|
|
|
if (iface) *((void **)iface) = &GAMBAS_Api;
|
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
iface = dlsym(lib, "JIT_PTR");
|
2018-05-28 03:18:44 +02:00
|
|
|
if (iface) *((void **)iface) = &GAMBAS_JitApi;
|
2018-05-26 16:50:00 +02:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
static bool create_function(CLASS *class, int index)
|
2018-05-26 16:50:00 +02:00
|
|
|
{
|
2018-06-09 22:42:35 +02:00
|
|
|
ARCHIVE *arch;
|
2018-06-01 03:50:42 +02:00
|
|
|
FUNCTION *func;
|
|
|
|
JIT_FUNCTION *jit;
|
2018-05-26 16:50:00 +02:00
|
|
|
void *lib;
|
|
|
|
void *addr;
|
|
|
|
int i;
|
|
|
|
int len;
|
2018-06-09 22:42:35 +02:00
|
|
|
char *name;
|
2019-08-21 22:08:45 +02:00
|
|
|
int jit_index;
|
2021-06-05 14:29:58 +02:00
|
|
|
char c;
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
arch = class->component ? class->component->archive : NULL;
|
2018-05-26 16:50:00 +02:00
|
|
|
|
2019-04-04 22:58:06 +02:00
|
|
|
if (!class->loaded)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/*if (get_state(arch) == JIT_NOT_COMPILED) // don't use JIT if we are compiling the corresponding archive
|
|
|
|
return TRUE;*/
|
|
|
|
|
2019-03-11 16:34:50 +01:00
|
|
|
if (wait_for_compilation(arch))
|
|
|
|
{
|
|
|
|
for (i = 0; i < class->load->n_func; i++)
|
|
|
|
class->load->func[i].fast = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-06-01 03:50:42 +02:00
|
|
|
func = &class->load->func[index];
|
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
if (!arch)
|
|
|
|
lib = _jit_library;
|
|
|
|
else
|
|
|
|
lib = arch->jit_library;
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
name = class->name;
|
|
|
|
while (*name == '^')
|
|
|
|
name++;
|
|
|
|
|
|
|
|
len = sprintf(COMMON_buffer, "jit_%s_%d", name, index);
|
2018-05-26 16:50:00 +02:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
2021-06-05 14:29:58 +02:00
|
|
|
{
|
|
|
|
c = tolower(COMMON_buffer[i]);
|
|
|
|
if (c == ':')
|
|
|
|
c = '$';
|
|
|
|
COMMON_buffer[i] = c;
|
|
|
|
}
|
2012-05-23 21:26:15 +02:00
|
|
|
|
2018-05-26 16:50:00 +02:00
|
|
|
addr = dlsym(lib, COMMON_buffer);
|
2018-06-01 03:50:42 +02:00
|
|
|
if (!addr)
|
|
|
|
{
|
|
|
|
func->fast = FALSE;
|
2018-06-09 22:42:35 +02:00
|
|
|
return TRUE;
|
2018-06-01 03:50:42 +02:00
|
|
|
}
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
if (_debug && func->debug)
|
2018-06-01 03:50:42 +02:00
|
|
|
fprintf(stderr, "gbx3: loading jit function: %s.%s\n", class->name, func->debug->name);
|
|
|
|
|
|
|
|
if (!_jit_func)
|
|
|
|
ARRAY_create(&_jit_func);
|
2019-08-21 22:08:45 +02:00
|
|
|
|
|
|
|
jit_index = ARRAY_count(_jit_func);
|
2018-06-01 03:50:42 +02:00
|
|
|
jit = (JIT_FUNCTION *)ARRAY_add(&_jit_func);
|
|
|
|
|
|
|
|
jit->addr = addr;
|
|
|
|
jit->code = func->code;
|
|
|
|
|
2019-08-21 22:08:45 +02:00
|
|
|
func->code = (PCODE *)(intptr_t)jit_index;
|
2021-06-05 14:29:58 +02:00
|
|
|
func->fast_linked = TRUE;
|
2019-08-21 22:08:45 +02:00
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
return FALSE;
|
2012-05-23 21:26:15 +02:00
|
|
|
}
|
|
|
|
|
2018-05-28 03:18:44 +02:00
|
|
|
|
2019-03-13 12:59:14 +01:00
|
|
|
bool JIT_exec(bool ret_on_stack)
|
2018-05-28 03:18:44 +02:00
|
|
|
{
|
|
|
|
VALUE *sp = SP;
|
2018-06-01 03:50:42 +02:00
|
|
|
JIT_FUNCTION *jit;
|
2018-06-09 22:42:35 +02:00
|
|
|
CLASS *class = EXEC.class;
|
2019-03-11 16:34:50 +01:00
|
|
|
void *object = EXEC.object;
|
2018-06-01 14:40:07 +02:00
|
|
|
char nparam = EXEC.nparam;
|
2018-06-02 17:59:47 +02:00
|
|
|
VALUE ret;
|
|
|
|
FUNCTION *func = EXEC.func;
|
|
|
|
|
2021-06-05 14:29:58 +02:00
|
|
|
if (JIT_disabled)
|
|
|
|
return TRUE;
|
|
|
|
|
2018-10-31 01:56:35 +01:00
|
|
|
if (UNLIKELY(nparam < func->npmin))
|
|
|
|
THROW(E_NEPARAM);
|
|
|
|
else if (UNLIKELY(nparam > func->n_param && !func->vararg))
|
|
|
|
THROW(E_TMPARAM);
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
if (!func->fast_linked)
|
|
|
|
{
|
|
|
|
if (create_function(class, EXEC.index))
|
2019-03-13 12:59:14 +01:00
|
|
|
return TRUE;
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
|
2018-06-02 17:59:47 +02:00
|
|
|
STACK_push_frame(&EXEC_current, func->stack_usage);
|
2018-05-28 03:18:44 +02:00
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
CP = class;
|
2019-03-11 16:34:50 +01:00
|
|
|
OP = object;
|
2018-06-12 16:30:11 +02:00
|
|
|
FP = func;
|
2018-11-29 09:10:56 +01:00
|
|
|
EC = NULL;
|
2018-05-28 03:18:44 +02:00
|
|
|
|
2019-08-21 22:08:45 +02:00
|
|
|
jit = &_jit_func[(intptr_t)func->code];
|
2018-06-01 03:50:42 +02:00
|
|
|
|
2018-06-12 16:30:11 +02:00
|
|
|
PROFILE_ENTER_FUNCTION();
|
|
|
|
|
2018-06-22 04:47:44 +02:00
|
|
|
TRY
|
|
|
|
{
|
|
|
|
(*(jit->addr))(nparam);
|
|
|
|
}
|
|
|
|
CATCH
|
|
|
|
{
|
|
|
|
PROFILE_LEAVE_FUNCTION();
|
2018-11-27 02:59:21 +01:00
|
|
|
if (SP != sp)
|
2018-12-07 01:03:47 +01:00
|
|
|
ERROR_panic("Stack mismatch in JIT function (SP %+ld)\n", SP - sp);
|
2018-06-22 04:47:44 +02:00
|
|
|
RELEASE_MANY(SP, nparam);
|
|
|
|
STACK_pop_frame(&EXEC_current);
|
|
|
|
PROPAGATE();
|
|
|
|
}
|
|
|
|
END_TRY
|
2018-05-28 03:18:44 +02:00
|
|
|
|
2018-06-12 16:30:11 +02:00
|
|
|
PROFILE_LEAVE_FUNCTION();
|
|
|
|
|
2018-05-28 03:18:44 +02:00
|
|
|
if (SP != sp)
|
2018-12-07 01:03:47 +01:00
|
|
|
ERROR_panic("Stack mismatch in JIT function (SP %+ld)\n", SP - sp);
|
2018-05-28 03:18:44 +02:00
|
|
|
|
2018-06-02 17:59:47 +02:00
|
|
|
if (func->type != T_VOID)
|
|
|
|
{
|
|
|
|
ret = TEMP;
|
|
|
|
BORROW(&ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret.type = T_VOID;
|
|
|
|
|
2018-06-01 14:40:07 +02:00
|
|
|
RELEASE_MANY(SP, nparam);
|
|
|
|
|
2018-06-02 17:59:47 +02:00
|
|
|
STACK_pop_frame(&EXEC_current);
|
2018-06-05 11:43:39 +02:00
|
|
|
|
|
|
|
if (ret_on_stack)
|
|
|
|
{
|
|
|
|
if (SP[-1].type == T_FUNCTION)
|
|
|
|
{
|
|
|
|
SP--;
|
|
|
|
OBJECT_UNREF(SP->_function.object);
|
|
|
|
}
|
|
|
|
|
|
|
|
*SP++ = ret;
|
|
|
|
ret.type = T_VOID;
|
|
|
|
}
|
2020-01-09 04:48:22 +01:00
|
|
|
else
|
|
|
|
RET = ret;
|
2019-03-13 12:59:14 +01:00
|
|
|
|
|
|
|
return FALSE;
|
2018-06-02 17:59:47 +02:00
|
|
|
}
|
|
|
|
|
2018-07-02 19:37:37 +02:00
|
|
|
PCODE *JIT_get_code(FUNCTION *func)
|
2018-05-28 03:18:44 +02:00
|
|
|
{
|
2018-06-09 22:42:35 +02:00
|
|
|
if (func->fast_linked)
|
2019-08-21 22:08:45 +02:00
|
|
|
return _jit_func[(intptr_t)func->code].code;
|
2018-06-09 22:42:35 +02:00
|
|
|
else
|
|
|
|
return func->code;
|
2018-05-28 03:18:44 +02:00
|
|
|
}
|
|
|
|
|
2018-05-29 23:25:57 +02:00
|
|
|
void *JIT_get_class_ref(int index)
|
|
|
|
{
|
|
|
|
return CP->load->class_ref[index];
|
|
|
|
}
|
|
|
|
|
2018-05-28 03:18:44 +02:00
|
|
|
CLASS_CONST *JIT_get_constant(int index)
|
2012-05-23 21:26:15 +02:00
|
|
|
{
|
2018-05-28 03:18:44 +02:00
|
|
|
return &CP->load->cst[index];
|
2012-05-23 21:26:15 +02:00
|
|
|
}
|
2018-05-29 03:43:23 +02:00
|
|
|
|
|
|
|
void JIT_debug(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
2018-06-02 17:59:47 +02:00
|
|
|
|
2018-08-22 09:30:27 +02:00
|
|
|
typedef
|
|
|
|
struct {
|
|
|
|
PCODE *pc;
|
|
|
|
VALUE **psp;
|
|
|
|
PCODE code;
|
|
|
|
}
|
|
|
|
JIT_call_unknown_ERROR;
|
|
|
|
|
|
|
|
static void error_JIT_call_unknown(JIT_call_unknown_ERROR *save)
|
2018-06-22 04:47:44 +02:00
|
|
|
{
|
2018-08-22 09:30:27 +02:00
|
|
|
save->pc[1] = (PCODE)save->code;
|
|
|
|
*save->psp = SP;
|
2018-06-22 04:47:44 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 09:30:27 +02:00
|
|
|
void JIT_call_unknown(PCODE *pc, VALUE **psp)
|
2018-06-02 17:59:47 +02:00
|
|
|
{
|
2018-08-22 09:30:27 +02:00
|
|
|
JIT_call_unknown_ERROR save;
|
2018-06-02 17:59:47 +02:00
|
|
|
|
|
|
|
PC = pc;
|
2018-08-22 09:30:27 +02:00
|
|
|
SP = *psp;
|
|
|
|
|
|
|
|
save.pc = pc;
|
|
|
|
save.psp = psp;
|
|
|
|
save.code = pc[1];
|
2018-06-02 17:59:47 +02:00
|
|
|
|
|
|
|
pc[1] = 0x140B;
|
|
|
|
|
2018-08-22 09:30:27 +02:00
|
|
|
ON_ERROR_1(error_JIT_call_unknown, &save)
|
2018-06-22 04:47:44 +02:00
|
|
|
{
|
2018-09-10 20:11:59 +02:00
|
|
|
EXEC_function_loop();
|
2018-06-22 04:47:44 +02:00
|
|
|
}
|
|
|
|
END_ERROR
|
2018-08-22 09:30:27 +02:00
|
|
|
|
|
|
|
error_JIT_call_unknown(&save);
|
2018-06-02 17:59:47 +02:00
|
|
|
}
|
2018-08-18 15:28:19 +02:00
|
|
|
|
|
|
|
void JIT_load_class(CLASS *class)
|
|
|
|
{
|
|
|
|
CLASS_load(class);
|
|
|
|
}
|
2019-06-11 22:32:12 +02:00
|
|
|
|
|
|
|
void JIT_load_class_without_init(CLASS *class)
|
|
|
|
{
|
|
|
|
TRY
|
|
|
|
{
|
|
|
|
CLASS_load_without_init(class);
|
|
|
|
}
|
|
|
|
CATCH
|
|
|
|
{
|
|
|
|
class->error = FALSE;
|
|
|
|
}
|
|
|
|
END_TRY
|
|
|
|
}
|
2020-04-06 04:40:47 +02:00
|
|
|
|
|
|
|
void JIT_add_string_local(GB_STRING *str, GB_STRING val)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *add;
|
|
|
|
int len_add;
|
|
|
|
|
|
|
|
add = val.value.addr + val.value.start;
|
|
|
|
len_add = val.value.len;
|
|
|
|
len = str->value.len;
|
|
|
|
|
|
|
|
if (len_add == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (len && STRING_from_ptr(str->value.addr)->ref == 1 && str->value.start == 0)
|
|
|
|
{
|
|
|
|
str->value.addr = STRING_add(str->value.addr, add, len_add);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *str_new = STRING_new(NULL, len + len_add);
|
|
|
|
if (len) memcpy(str_new, str->value.addr + str->value.start, len);
|
|
|
|
memcpy(&str_new[len], add, len_add);
|
|
|
|
if (str->type == T_STRING)
|
|
|
|
STRING_unref(&str->value.addr);
|
|
|
|
else
|
|
|
|
str->type = T_STRING;
|
|
|
|
str->value.addr = str_new;
|
|
|
|
}
|
|
|
|
|
|
|
|
str->value.len += len_add;
|
|
|
|
|
|
|
|
if (val.type == T_STRING) STRING_unref(&val.value.addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JIT_add_string_global(char **pstr, GB_STRING val)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
int len;
|
|
|
|
char *add;
|
|
|
|
int len_add;
|
|
|
|
|
|
|
|
add = val.value.addr + val.value.start;
|
|
|
|
len_add = val.value.len;
|
|
|
|
|
|
|
|
if (len_add == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
str = *pstr;
|
|
|
|
len = STRING_length(str);
|
|
|
|
|
|
|
|
if (len && STRING_from_ptr(str)->ref == 1)
|
|
|
|
*pstr = STRING_add(str, add, len_add);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *str_new = STRING_new(NULL, len + len_add);
|
|
|
|
if (len) memcpy(str_new, str, len);
|
|
|
|
memcpy(&str_new[len], add, len_add);
|
|
|
|
STRING_unref(pstr);
|
|
|
|
*pstr = str_new;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val.type == T_STRING) STRING_unref(&val.value.addr);
|
|
|
|
}
|