Change soft-fail to use the config, rather than env
[rbx.git] / shotgun / lib / cpu_primitives.c
blob6b0ee1699c5703fdb5d15a38ed5ca7a34e0365cc
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/uio.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <errno.h>
11 #include <time.h>
12 #include <sys/time.h>
13 #include <zlib.h>
14 #include <math.h>
15 #include <glob.h>
16 #include <termios.h>
17 #include <sys/time.h>
18 #include <ev.h>
19 #include <dirent.h>
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
48 #endif
50 #if CONFIG_ENABLE_DTRACE
51 #include "shotgun/dtrace.h"
52 #endif
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); \
72 DONE(); \
73 } \
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)
89 #define PRIM_OK 1
90 #define PRIM_FAIL 0
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) {
102 int _ret = TRUE;
103 int _orig_sp;
104 OBJECT *_orig_sp_ptr;
106 _orig_sp_ptr = c->sp_ptr;
107 _orig_sp = c->sp;
108 #include "shotgun/lib/system_primitives.gen"
110 if(!_ret) {
111 c->sp_ptr = _orig_sp_ptr;
112 c->sp = _orig_sp;
114 return _ret;