|
| 1 | +#ifndef BUILTIN_H_INCLUDED |
| 2 | +#define BUILTIN_H_INCLUDED |
| 3 | + |
| 4 | +// invoke |
| 5 | + |
| 6 | +struct rb_builtin_function { |
| 7 | + // for invocation |
| 8 | + const void * const func_ptr; |
| 9 | + const int argc; |
| 10 | + |
| 11 | + // for load |
| 12 | + const int index; |
| 13 | + const char * const name; |
| 14 | + |
| 15 | + // for jit |
| 16 | + void (*compiler)(FILE *, long, unsigned, bool); |
| 17 | +}; |
| 18 | + |
| 19 | +#define RB_BUILTIN_FUNCTION(_i, _name, _fname, _arity, _compiler) {\ |
| 20 | + .name = _i < 0 ? NULL : #_name, \ |
| 21 | + .func_ptr = (void *)_fname, \ |
| 22 | + .argc = _arity, \ |
| 23 | + .index = _i, \ |
| 24 | + .compiler = _compiler, \ |
| 25 | +} |
| 26 | + |
| 27 | +void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table); |
| 28 | + |
| 29 | +#ifndef rb_execution_context_t |
| 30 | +typedef struct rb_execution_context_struct rb_execution_context_t; |
| 31 | +#define rb_execution_context_t rb_execution_context_t |
| 32 | +#endif |
| 33 | + |
| 34 | +/* The following code is generated by the following Ruby script: |
| 35 | +
|
| 36 | +typedef = proc {|i, args| |
| 37 | + "typedef VALUE (*rb_builtin_arity#{i}_function_type)(rb_execution_context_t *ec, VALUE self#{args});" |
| 38 | +} |
| 39 | +puts typedef[0, ""] |
| 40 | +(1..15).each {|i| |
| 41 | + puts typedef[i, ",\n " + (0...i).map{"VALUE"}.join(", ")] |
| 42 | +} |
| 43 | +16.times{|i| |
| 44 | + puts "static inline void rb_builtin_function_check_arity#{i}(rb_builtin_arity#{i}_function_type f){}" |
| 45 | +} |
| 46 | +*/ |
| 47 | + |
| 48 | +typedef VALUE (*rb_builtin_arity0_function_type)(rb_execution_context_t *ec, VALUE self); |
| 49 | +typedef VALUE (*rb_builtin_arity1_function_type)(rb_execution_context_t *ec, VALUE self, |
| 50 | + VALUE); |
| 51 | +typedef VALUE (*rb_builtin_arity2_function_type)(rb_execution_context_t *ec, VALUE self, |
| 52 | + VALUE, VALUE); |
| 53 | +typedef VALUE (*rb_builtin_arity3_function_type)(rb_execution_context_t *ec, VALUE self, |
| 54 | + VALUE, VALUE, VALUE); |
| 55 | +typedef VALUE (*rb_builtin_arity4_function_type)(rb_execution_context_t *ec, VALUE self, |
| 56 | + VALUE, VALUE, VALUE, VALUE); |
| 57 | +typedef VALUE (*rb_builtin_arity5_function_type)(rb_execution_context_t *ec, VALUE self, |
| 58 | + VALUE, VALUE, VALUE, VALUE, VALUE); |
| 59 | +typedef VALUE (*rb_builtin_arity6_function_type)(rb_execution_context_t *ec, VALUE self, |
| 60 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 61 | +typedef VALUE (*rb_builtin_arity7_function_type)(rb_execution_context_t *ec, VALUE self, |
| 62 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 63 | +typedef VALUE (*rb_builtin_arity8_function_type)(rb_execution_context_t *ec, VALUE self, |
| 64 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 65 | +typedef VALUE (*rb_builtin_arity9_function_type)(rb_execution_context_t *ec, VALUE self, |
| 66 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 67 | +typedef VALUE (*rb_builtin_arity10_function_type)(rb_execution_context_t *ec, VALUE self, |
| 68 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 69 | +typedef VALUE (*rb_builtin_arity11_function_type)(rb_execution_context_t *ec, VALUE self, |
| 70 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 71 | +typedef VALUE (*rb_builtin_arity12_function_type)(rb_execution_context_t *ec, VALUE self, |
| 72 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 73 | +typedef VALUE (*rb_builtin_arity13_function_type)(rb_execution_context_t *ec, VALUE self, |
| 74 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 75 | +typedef VALUE (*rb_builtin_arity14_function_type)(rb_execution_context_t *ec, VALUE self, |
| 76 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 77 | +typedef VALUE (*rb_builtin_arity15_function_type)(rb_execution_context_t *ec, VALUE self, |
| 78 | + VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE); |
| 79 | +static inline void rb_builtin_function_check_arity0(rb_builtin_arity0_function_type f){} |
| 80 | +static inline void rb_builtin_function_check_arity1(rb_builtin_arity1_function_type f){} |
| 81 | +static inline void rb_builtin_function_check_arity2(rb_builtin_arity2_function_type f){} |
| 82 | +static inline void rb_builtin_function_check_arity3(rb_builtin_arity3_function_type f){} |
| 83 | +static inline void rb_builtin_function_check_arity4(rb_builtin_arity4_function_type f){} |
| 84 | +static inline void rb_builtin_function_check_arity5(rb_builtin_arity5_function_type f){} |
| 85 | +static inline void rb_builtin_function_check_arity6(rb_builtin_arity6_function_type f){} |
| 86 | +static inline void rb_builtin_function_check_arity7(rb_builtin_arity7_function_type f){} |
| 87 | +static inline void rb_builtin_function_check_arity8(rb_builtin_arity8_function_type f){} |
| 88 | +static inline void rb_builtin_function_check_arity9(rb_builtin_arity9_function_type f){} |
| 89 | +static inline void rb_builtin_function_check_arity10(rb_builtin_arity10_function_type f){} |
| 90 | +static inline void rb_builtin_function_check_arity11(rb_builtin_arity11_function_type f){} |
| 91 | +static inline void rb_builtin_function_check_arity12(rb_builtin_arity12_function_type f){} |
| 92 | +static inline void rb_builtin_function_check_arity13(rb_builtin_arity13_function_type f){} |
| 93 | +static inline void rb_builtin_function_check_arity14(rb_builtin_arity14_function_type f){} |
| 94 | +static inline void rb_builtin_function_check_arity15(rb_builtin_arity15_function_type f){} |
| 95 | + |
| 96 | +PUREFUNC(VALUE rb_vm_lvar_exposed(rb_execution_context_t *ec, int index)); |
| 97 | +VALUE rb_vm_lvar_exposed(rb_execution_context_t *ec, int index); |
| 98 | + |
| 99 | +// __builtin_inline! |
| 100 | + |
| 101 | +PUREFUNC(static inline VALUE rb_vm_lvar(rb_execution_context_t *ec, int index)); |
| 102 | + |
| 103 | +static inline VALUE |
| 104 | +rb_vm_lvar(rb_execution_context_t *ec, int index) |
| 105 | +{ |
| 106 | +#if defined(VM_CORE_H_EC_DEFINED) && VM_CORE_H_EC_DEFINED |
| 107 | + return ec->cfp->ep[index]; |
| 108 | +#else |
| 109 | + return rb_vm_lvar_exposed(ec, index); |
| 110 | +#endif |
| 111 | +} |
| 112 | + |
| 113 | +// dump/load |
| 114 | + |
| 115 | +struct builtin_binary { |
| 116 | + const char *feature; // feature name |
| 117 | + const unsigned char *bin; // binary by ISeq#to_binary |
| 118 | + size_t bin_size; |
| 119 | +}; |
| 120 | + |
| 121 | +#endif // BUILTIN_H_INCLUDED |
0 commit comments