Added spec:commit task to commit changes to spec/ruby sources.
[rbx.git] / shotgun / lib / subtend / nmethod.c
blob657d27ada63ab025d959e4efd59d4c7944855a73
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) {
10 OBJECT sys, nm;
11 native_method *sys_nm;
13 /* TODO: raise an exception. */
14 if(args > 40) {
15 return Qnil;
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);
24 sys_nm->entry = func;
25 sys_nm->args = args;
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);
35 return nm;