portable_mruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +195 -0
  3. data/exe/portable-mruby +6 -0
  4. data/lib/portable_mruby/binary_manager.rb +225 -0
  5. data/lib/portable_mruby/builder.rb +97 -0
  6. data/lib/portable_mruby/bytecode_compiler.rb +19 -0
  7. data/lib/portable_mruby/c_generator.rb +94 -0
  8. data/lib/portable_mruby/cli.rb +136 -0
  9. data/lib/portable_mruby/version.rb +6 -0
  10. data/lib/portable_mruby.rb +15 -0
  11. data/vendor/mruby/bin/mrbc.com +0 -0
  12. data/vendor/mruby/include/mrbconf.h +230 -0
  13. data/vendor/mruby/include/mruby/array.h +303 -0
  14. data/vendor/mruby/include/mruby/boxing_nan.h +169 -0
  15. data/vendor/mruby/include/mruby/boxing_no.h +59 -0
  16. data/vendor/mruby/include/mruby/boxing_word.h +251 -0
  17. data/vendor/mruby/include/mruby/class.h +104 -0
  18. data/vendor/mruby/include/mruby/common.h +118 -0
  19. data/vendor/mruby/include/mruby/compile.h +185 -0
  20. data/vendor/mruby/include/mruby/data.h +76 -0
  21. data/vendor/mruby/include/mruby/debug.h +75 -0
  22. data/vendor/mruby/include/mruby/dump.h +159 -0
  23. data/vendor/mruby/include/mruby/endian.h +44 -0
  24. data/vendor/mruby/include/mruby/error.h +132 -0
  25. data/vendor/mruby/include/mruby/gc.h +72 -0
  26. data/vendor/mruby/include/mruby/gems/mruby-dir/include/dir_hal.h +79 -0
  27. data/vendor/mruby/include/mruby/gems/mruby-io/include/io_hal.h +451 -0
  28. data/vendor/mruby/include/mruby/gems/mruby-io/include/mruby/ext/io.h +76 -0
  29. data/vendor/mruby/include/mruby/gems/mruby-socket/include/socket_hal.h +83 -0
  30. data/vendor/mruby/include/mruby/gems/mruby-time/include/mruby/time.h +27 -0
  31. data/vendor/mruby/include/mruby/hash.h +234 -0
  32. data/vendor/mruby/include/mruby/internal.h +274 -0
  33. data/vendor/mruby/include/mruby/irep.h +142 -0
  34. data/vendor/mruby/include/mruby/istruct.h +50 -0
  35. data/vendor/mruby/include/mruby/khash.h +455 -0
  36. data/vendor/mruby/include/mruby/mempool.h +19 -0
  37. data/vendor/mruby/include/mruby/numeric.h +174 -0
  38. data/vendor/mruby/include/mruby/object.h +45 -0
  39. data/vendor/mruby/include/mruby/opcode.h +69 -0
  40. data/vendor/mruby/include/mruby/ops.h +120 -0
  41. data/vendor/mruby/include/mruby/presym/disable.h +72 -0
  42. data/vendor/mruby/include/mruby/presym/enable.h +39 -0
  43. data/vendor/mruby/include/mruby/presym/id.h +1423 -0
  44. data/vendor/mruby/include/mruby/presym/scanning.h +81 -0
  45. data/vendor/mruby/include/mruby/presym/table.h +2847 -0
  46. data/vendor/mruby/include/mruby/presym.h +41 -0
  47. data/vendor/mruby/include/mruby/proc.h +186 -0
  48. data/vendor/mruby/include/mruby/range.h +77 -0
  49. data/vendor/mruby/include/mruby/re.h +16 -0
  50. data/vendor/mruby/include/mruby/string.h +428 -0
  51. data/vendor/mruby/include/mruby/throw.h +57 -0
  52. data/vendor/mruby/include/mruby/value.h +471 -0
  53. data/vendor/mruby/include/mruby/variable.h +108 -0
  54. data/vendor/mruby/include/mruby/version.h +143 -0
  55. data/vendor/mruby/include/mruby.h +1614 -0
  56. data/vendor/mruby/lib/libmruby.a +0 -0
  57. metadata +102 -0
@@ -0,0 +1,41 @@
1
+ /**
2
+ ** @file mruby/presym.h - Preallocated Symbols
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_PRESYM_H
8
+ #define MRUBY_PRESYM_H
9
+
10
+ #if defined(MRB_NO_PRESYM)
11
+ # include <mruby/presym/disable.h>
12
+ #elif !defined(MRB_PRESYM_SCANNING)
13
+ # include <mruby/presym/enable.h>
14
+ #endif
15
+
16
+ /*
17
+ * Where `mrb_intern_lit` is allowed for symbol interning, it is directly
18
+ * replaced by the symbol ID if presym is enabled by using the following
19
+ * macros.
20
+ *
21
+ * MRB_OPSYM(xor) //=> ^ (Operator)
22
+ * MRB_GVSYM(xor) //=> $xor (Global Variable)
23
+ * MRB_CVSYM(xor) //=> @@xor (Class Variable)
24
+ * MRB_IVSYM(xor) //=> @xor (Instance Variable)
25
+ * MRB_SYM_B(xor) //=> xor! (Method with Bang)
26
+ * MRB_SYM_Q(xor) //=> xor? (Method with Question mark)
27
+ * MRB_SYM_E(xor) //=> xor= (Method with Equal)
28
+ * MRB_SYM(xor) //=> xor (Word characters)
29
+ *
30
+ * For `MRB_OPSYM`, specify the names corresponding to operators (see
31
+ * `MRuby::Presym::OPERATORS` in `lib/mruby/presym.rb` for the names that
32
+ * can be specified for it). Other than that, describe only word characters
33
+ * excluding leading and ending punctuation.
34
+ *
35
+ * These macros are expanded to `mrb_intern_lit` if presym is disabled,
36
+ * therefore the mruby state variable is required. The above macros can be
37
+ * used when the variable name is `mrb`. If you want to use other variable
38
+ * names, you need to use macros with `_2` suffix, such as `MRB_SYM_2`.
39
+ */
40
+
41
+ #endif /* MRUBY_PRESYM_H */
@@ -0,0 +1,186 @@
1
+ /**
2
+ ** @file mruby/proc.h - Proc class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_PROC_H
8
+ #define MRUBY_PROC_H
9
+
10
+ #include "common.h"
11
+ #include <mruby/irep.h>
12
+ #include <string.h>
13
+
14
+ /**
15
+ * Proc class
16
+ */
17
+ MRB_BEGIN_DECL
18
+
19
+ /*
20
+ * env object (for internal used)
21
+ *
22
+ * - don't create multiple envs on one ci.
23
+ * - don't share a env to different ci.
24
+ * - don't attach a closed env to any ci.
25
+ */
26
+ struct REnv {
27
+ MRB_OBJECT_HEADER;
28
+ mrb_value *stack;
29
+ struct mrb_context *cxt; /* if not null, it means that the stack is shared with the call frame */
30
+ mrb_sym mid;
31
+ };
32
+
33
+ /* flags (20bits): 1(ZERO):1(separate module):2(visibility):8(cioff/bidx):8(stack_len) */
34
+ #define MRB_ENV_SET_LEN(e,len) ((e)->flags = (((e)->flags & ~0xff)|((unsigned int)(len) & 0xff)))
35
+ #define MRB_ENV_LEN(e) ((mrb_int)((e)->flags & 0xff))
36
+ #define MRB_ENV_CLOSE(e) ((e)->cxt = NULL)
37
+ #define MRB_ENV_ONSTACK_P(e) ((e)->cxt != NULL)
38
+ #define MRB_ENV_BIDX(e) (((e)->flags >> 8) & 0xff)
39
+ #define MRB_ENV_SET_BIDX(e,idx) ((e)->flags = (((e)->flags & ~(0xff<<8))|((unsigned int)(idx) & 0xff)<<8))
40
+ #define MRB_ENV_SET_VISIBILITY(e, vis) MRB_FLAGS_SET((e)->flags, 16, 2, vis)
41
+ #define MRB_ENV_VISIBILITY(e) MRB_FLAGS_GET((e)->flags, 16, 2)
42
+ #define MRB_ENV_VISIBILITY_BREAK_P(e) MRB_FLAG_CHECK((e)->flags, 18)
43
+ #define MRB_ENV_COPY_FLAGS_FROM_CI(e, ci) MRB_FLAGS_SET((e)->flags, 16, 3, (ci)->vis)
44
+
45
+ /*
46
+ * Returns TRUE on success.
47
+ * If the function fails:
48
+ * * Returns FALSE if noraise is TRUE.
49
+ * * Raises a NoMemoryError exception if noraise is FALSE.
50
+ */
51
+ mrb_bool mrb_env_unshare(mrb_state*, struct REnv*, mrb_bool noraise);
52
+
53
+ struct RProc {
54
+ MRB_OBJECT_HEADER;
55
+ union {
56
+ const mrb_irep *irep;
57
+ mrb_func_t func;
58
+ mrb_sym mid;
59
+ } body;
60
+ const struct RProc *upper;
61
+ union {
62
+ struct RClass *target_class;
63
+ struct REnv *env;
64
+ } e;
65
+ };
66
+
67
+ /* aspec access */
68
+ #define MRB_ASPEC_REQ(a) (((a) >> 18) & 0x1f)
69
+ #define MRB_ASPEC_OPT(a) (((a) >> 13) & 0x1f)
70
+ #define MRB_ASPEC_REST(a) (((a) >> 12) & 0x1)
71
+ #define MRB_ASPEC_POST(a) (((a) >> 7) & 0x1f)
72
+ #define MRB_ASPEC_KEY(a) (((a) >> 2) & 0x1f)
73
+ #define MRB_ASPEC_KDICT(a) (((a) >> 1) & 0x1)
74
+ #define MRB_ASPEC_BLOCK(a) ((a) & 1)
75
+
76
+ #define MRB_PROC_CFUNC_FL 128
77
+ #define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC_FL) != 0)
78
+ #define MRB_PROC_CFUNC(p) (p)->body.func
79
+ #define MRB_PROC_STRICT 256
80
+ #define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0)
81
+ #define MRB_PROC_ORPHAN 512
82
+ #define MRB_PROC_ORPHAN_P(p) (((p)->flags & MRB_PROC_ORPHAN) != 0)
83
+ #define MRB_PROC_ENVSET 1024
84
+ #define MRB_PROC_ENV_P(p) (((p)->flags & MRB_PROC_ENVSET) != 0)
85
+ #define MRB_PROC_ENV(p) (MRB_PROC_ENV_P(p) ? (p)->e.env : NULL)
86
+ #define MRB_PROC_TARGET_CLASS(p) (MRB_PROC_ENV_P(p) ? (p)->e.env->c : (p)->e.target_class)
87
+ #define MRB_PROC_SET_TARGET_CLASS(p,tc) do {\
88
+ if (MRB_PROC_ENV_P(p)) {\
89
+ (p)->e.env->c = (tc);\
90
+ mrb_field_write_barrier(mrb, (struct RBasic*)(p)->e.env, (struct RBasic*)(tc));\
91
+ }\
92
+ else {\
93
+ (p)->e.target_class = (tc);\
94
+ mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)(tc));\
95
+ }\
96
+ } while (0)
97
+ #define MRB_PROC_SCOPE 2048
98
+ #define MRB_PROC_SCOPE_P(p) (((p)->flags & MRB_PROC_SCOPE) != 0)
99
+ #define MRB_PROC_NOARG 4096 /* for MRB_PROC_CFUNC_FL, it would be something like MRB_ARGS_NONE() or MRB_METHOD_NOARG_FL */
100
+ #define MRB_PROC_NOARG_P(p) (((p)->flags & MRB_PROC_NOARG) != 0)
101
+ #define MRB_PROC_ALIAS 8192
102
+ #define MRB_PROC_ALIAS_P(p) (((p)->flags & MRB_PROC_ALIAS) != 0)
103
+
104
+ #define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v)))
105
+
106
+ struct RProc *mrb_proc_new(mrb_state*, const mrb_irep*);
107
+ MRB_API struct RProc *mrb_proc_new_cfunc(mrb_state*, mrb_func_t);
108
+ MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals);
109
+
110
+ /* following functions are defined in mruby-proc-ext so please include it when using */
111
+ MRB_API struct RProc *mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t func, mrb_int argc, const mrb_value *argv);
112
+ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
113
+ /* old name */
114
+ #define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx)
115
+
116
+ #define MRB_METHOD_FUNC_FL 8
117
+ #define MRB_METHOD_NOARG_FL 4
118
+ #define MRB_METHOD_PUBLIC_FL 0
119
+ #define MRB_METHOD_PRIVATE_FL 1
120
+ #define MRB_METHOD_PROTECTED_FL 2
121
+ #define MRB_METHOD_VDEFAULT_FL 3
122
+ #define MRB_METHOD_VISIBILITY_MASK 3
123
+
124
+ #define MRB_METHOD_FUNC_P(m) ((m).flags&MRB_METHOD_FUNC_FL)
125
+ #define MRB_METHOD_NOARG_P(m) (((m).flags&MRB_METHOD_NOARG_FL)?1:0)
126
+ #define MRB_METHOD_FUNC(m) ((m).as.func)
127
+ #define MRB_METHOD_NOARG_SET(m) do{(m).flags|=MRB_METHOD_NOARG_FL;}while(0)
128
+ #define MRB_METHOD_FROM_FUNC(m,fn) do{(m).flags=MRB_METHOD_FUNC_FL;(m).as.func=(fn);}while(0)
129
+ #define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).as.proc=(pr);}while(0)
130
+ #define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
131
+ #define MRB_METHOD_PROC(m) ((m).as.proc)
132
+ #define MRB_METHOD_UNDEF_P(m) ((m).as.proc==NULL)
133
+ #define MRB_METHOD_VISIBILITY(m) ((m).flags & MRB_METHOD_VISIBILITY_MASK)
134
+ #define MRB_SET_VISIBILITY_FLAGS(f,v) ((f)=(((f)&~MRB_METHOD_VISIBILITY_MASK)|(v)))
135
+ #define MRB_METHOD_SET_VISIBILITY(m,v) MRB_SET_VISIBILITY_FLAGS((m).flags,(v))
136
+
137
+ #define MRB_METHOD_CFUNC_P(m) (MRB_METHOD_FUNC_P(m) || (MRB_METHOD_PROC(m)?(MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m))):FALSE))
138
+ /* use MRB_METHOD_CFUNC(m) only when MRB_METHOD_CFUNC_P(m) is true */
139
+ #define MRB_METHOD_CFUNC(m) (MRB_METHOD_FUNC_P(m)?MRB_METHOD_FUNC(m):MRB_PROC_CFUNC(MRB_METHOD_PROC(m)))
140
+
141
+ MRB_API mrb_value mrb_load_proc(mrb_state *mrb, const struct RProc *proc);
142
+
143
+ /**
144
+ * It can be used to isolate top-level scopes referenced by blocks generated by
145
+ * `mrb_load_string_cxt()` or similar called before entering the mruby VM (e.g. from `main()`).
146
+ * In that case, the `ci` parameter should be `mrb->c->cibase`.
147
+ *
148
+ * #include <mruby.h>
149
+ * #include <mruby/compile.h>
150
+ * #include <mruby/proc.h>
151
+ *
152
+ * int
153
+ * main(int argc, char **argv)
154
+ * {
155
+ * mrb_state *mrb;
156
+ * mrb_ccontext *cxt;
157
+ * mrb_value blk, ret;
158
+ *
159
+ * mrb = mrb_open();
160
+ * cxt = mrb_ccontext_new(mrb);
161
+ * blk = mrb_load_string_cxt(mrb, "x, y, z = 1, 2, 3; proc { [x, y, z] }", cxt);
162
+ * mrb_vm_ci_env_clear(mrb, mrb->c->cibase);
163
+ * mrb_load_string_cxt(mrb, "x, y, z = 4, 5, 6", cxt);
164
+ * ret = mrb_funcall(mrb, blk, "call", 0);
165
+ * mrb_p(mrb, ret); // => [1, 2, 3]
166
+ * // => [4, 5, 6] if `mrb_vm_ci_env_clear()` is commented out
167
+ * mrb_ccontext_free(mrb, cxt);
168
+ * mrb_close(mrb);
169
+ *
170
+ * return 0;
171
+ * }
172
+ *
173
+ * The top-level local variable names stored in `mrb_ccontext` are retained.
174
+ * Use also `mrb_ccontext_cleanup_local_variables()` at the same time, if necessary.
175
+ */
176
+ MRB_API void mrb_vm_ci_env_clear(mrb_state *mrb, mrb_callinfo *ci);
177
+
178
+ void mrb_vm_ci_proc_set(mrb_callinfo *ci, const struct RProc *p);
179
+ struct RClass * mrb_vm_ci_target_class(const mrb_callinfo *ci);
180
+ void mrb_vm_ci_target_class_set(mrb_callinfo *ci, struct RClass *tc);
181
+ struct REnv * mrb_vm_ci_env(const mrb_callinfo *ci);
182
+ void mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e);
183
+
184
+ MRB_END_DECL
185
+
186
+ #endif /* MRUBY_PROC_H */
@@ -0,0 +1,77 @@
1
+ /**
2
+ ** @file mruby/range.h - Range class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_RANGE_H
8
+ #define MRUBY_RANGE_H
9
+
10
+ #include "common.h"
11
+
12
+ /**
13
+ * Range class
14
+ */
15
+ MRB_BEGIN_DECL
16
+
17
+ #if defined(MRB_NAN_BOXING) && defined(MRB_64BIT) || defined(MRB_WORD_BOXING)
18
+ # define MRB_RANGE_EMBED
19
+ #endif
20
+
21
+ #ifdef MRB_RANGE_EMBED
22
+ struct RRange {
23
+ MRB_OBJECT_HEADER;
24
+ mrb_value beg;
25
+ mrb_value end;
26
+ mrb_bool excl;
27
+ };
28
+ # define mrb_gc_free_range(mrb, p) ((void)0)
29
+ # define RANGE_BEG(p) ((p)->beg)
30
+ # define RANGE_END(p) ((p)->end)
31
+ #else
32
+ typedef struct mrb_range_edges {
33
+ mrb_value beg;
34
+ mrb_value end;
35
+ } mrb_range_edges;
36
+ struct RRange {
37
+ MRB_OBJECT_HEADER;
38
+ mrb_range_edges *edges;
39
+ mrb_bool excl;
40
+ };
41
+ # define mrb_gc_free_range(mrb, p) mrb_free(mrb, (p)->edges)
42
+ # define RANGE_BEG(p) ((p)->edges->beg)
43
+ # define RANGE_END(p) ((p)->edges->end)
44
+ #endif
45
+
46
+ #define mrb_range_beg(mrb, r) RANGE_BEG(mrb_range_ptr(mrb, r))
47
+ #define mrb_range_end(mrb, r) RANGE_END(mrb_range_ptr(mrb, r))
48
+ #define mrb_range_excl_p(mrb, r) RANGE_EXCL(mrb_range_ptr(mrb, r))
49
+ #define mrb_range_raw_ptr(r) ((struct RRange*)mrb_ptr(r))
50
+ #define mrb_range_value(p) mrb_obj_value((void*)(p))
51
+ #define RANGE_EXCL(p) ((p)->excl)
52
+
53
+ MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value range);
54
+
55
+ /*
56
+ * Initializes a Range.
57
+ *
58
+ * If the third parameter is FALSE then it includes the last value in the range.
59
+ * If the third parameter is TRUE then it excludes the last value in the range.
60
+ *
61
+ * @param start the beginning value.
62
+ * @param end the ending value.
63
+ * @param exclude represents the inclusion or exclusion of the last value.
64
+ */
65
+ MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end, mrb_bool exclude);
66
+
67
+ enum mrb_range_beg_len {
68
+ MRB_RANGE_TYPE_MISMATCH = 0, /* (failure) not range */
69
+ MRB_RANGE_OK = 1, /* (success) range */
70
+ MRB_RANGE_OUT = 2 /* (failure) out of range */
71
+ };
72
+
73
+ MRB_API enum mrb_range_beg_len mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len, mrb_bool trunc);
74
+
75
+ MRB_END_DECL
76
+
77
+ #endif /* MRUBY_RANGE_H */
@@ -0,0 +1,16 @@
1
+ /**
2
+ ** @file mruby/re.h - Regexp class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_RE_H
8
+ #define MRUBY_RE_H
9
+
10
+ MRB_BEGIN_DECL
11
+
12
+ #define REGEXP_CLASS "Regexp"
13
+
14
+ MRB_END_DECL
15
+
16
+ #endif /* RE_H */