21 #include "shotgun/lib/shotgun.h"
22 #include "shotgun/lib/cpu.h"
23 #include "shotgun/lib/module.h"
24 #include "shotgun/lib/methctx.h"
25 #include "shotgun/lib/class.h"
26 #include "shotgun/lib/string.h"
27 #include "shotgun/lib/hash.h"
28 #include "shotgun/lib/lookuptable.h"
29 #include "shotgun/lib/symbol.h"
30 #include "shotgun/lib/object.h"
31 #include "shotgun/lib/bignum.h"
32 #include "shotgun/lib/bytearray.h"
33 #include "shotgun/lib/tuple.h"
34 #include "shotgun/lib/regexp.h"
35 #include "shotgun/lib/machine.h"
36 #include "shotgun/lib/grammar.h"
37 #include "shotgun/lib/subtend.h"
38 #include "shotgun/lib/subtend/nmc.h"
39 #include "shotgun/lib/fixnum.h"
40 #include "shotgun/lib/list.h"
41 #include "shotgun/lib/io.h"
42 #include "shotgun/lib/subtend/ffi.h"
43 #include "shotgun/lib/environment.h"
45 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
46 # define HAVE_STRUCT_TM_TM_GMTOFF
47 # define HAVE_STRUCT_TM_TM_ZONE
50 #if CONFIG_ENABLE_DTRACE
51 #include "shotgun/dtrace.h"
54 extern char **environ
;
56 OBJECT
math_sqrt(STATE
, OBJECT a
);
57 int _object_stores_bytes(OBJECT self
);
59 #define STATIC_SIZE 100
61 #define MAX_STRFTIME_OUTPUT 1024
63 #define ZLIB_CHUNK_SIZE 512
65 // defines a required arity for a primitive
66 // return true because we want other handler code to ignore it
67 // this is because it is raised directly in the primitive as an exception
68 #define ARITY(required) { \
69 native_int req = (required); \
70 if(req >= 0 && req != msg->args) { \
71 cpu_raise_arg_error(state, c, msg->args, req); \
76 // for primitive protection
77 #define GUARD(predicate_expression) if( ! (predicate_expression) ) { FAIL(); }
78 // popping with type checking -- a predicate function must be specified
79 // i.e. if type is STRING then STRING_P must be specified
80 #define POP(var, type) var = stack_pop(); GUARD( type##_P(var) )
81 // raise an exception of the specified type and msg
82 #define RAISE(exc_class, msg) ({ \
83 OBJECT _cls = rbs_const_get(state, BASIC_CLASS(object), exc_class); \
84 GUARD(CLASS_P(_cls)); \
85 cpu_raise_exception(state, c, cpu_new_exception(state, c, _cls, msg)); \
87 #define RAISE_FROM_ERRNO(msg) cpu_raise_from_errno(state, c, msg)
92 #define RET(val) ({ stack_push(val); return PRIM_OK; })
93 #define DONE() return PRIM_OK;
94 #define FAIL() return PRIM_FAIL;
97 void ffi_call(STATE
, cpu c
, OBJECT ptr
);
99 #include "shotgun/lib/primitive_implementation.gen"
101 int cpu_perform_system_primitive(STATE
, cpu c
, int prim
, const struct message
*msg
) {
104 OBJECT
*_orig_sp_ptr
;
106 _orig_sp_ptr
= c
->sp_ptr
;
108 #include "shotgun/lib/system_primitives.gen"
111 c
->sp_ptr
= _orig_sp_ptr
;