1 #include "shotgun/lib/shotgun.h"
2 #include "shotgun/lib/symbol.h"
3 #include "shotgun/lib/object.h"
4 #include "shotgun/lib/subtend/nmethod.h"
5 #include "shotgun/lib/subtend/ffi.h"
7 #include "shotgun/lib/primitive_indexes.h"
9 OBJECT
nmethod_new(STATE
, OBJECT mod
, const char *file
, const char *name
, void *func
, int args
) {
11 native_method
*sys_nm
;
13 /* TODO: raise an exception. */
18 sys
= object_memory_new_object_mature(state
->om
, BASIC_CLASS(data
),
19 BYTES2FIELDS(sizeof(native_method
)));
20 object_make_byte_storage(state
, sys
);
22 sys_nm
= (native_method
*)BYTES_OF(sys
);
27 nm
= nmethod_allocate(state
);
28 cmethod_set_primitive(nm
, I2N(CPU_PRIMITIVE_NMETHOD_CALL
));
29 cmethod_set_required(nm
, I2N(args
));
30 cmethod_set_serial(nm
, I2N(0));
31 cmethod_set_name(nm
, symtbl_lookup_cstr(state
, state
->global
->symbols
, name
));
32 cmethod_set_file(nm
, symtbl_lookup_cstr(state
, state
->global
->symbols
, file
));
33 nmethod_set_data(nm
, sys
);