wasm 0.0.1 → 0.0.2

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 (47) hide show
  1. checksums.yaml +5 -5
  2. data/assets/mruby/include/mrbconf.h +143 -0
  3. data/assets/mruby/include/mruby.h +1284 -0
  4. data/assets/mruby/include/mruby/array.h +279 -0
  5. data/assets/mruby/include/mruby/boxing_nan.h +102 -0
  6. data/assets/mruby/include/mruby/boxing_no.h +56 -0
  7. data/assets/mruby/include/mruby/boxing_word.h +136 -0
  8. data/assets/mruby/include/mruby/class.h +94 -0
  9. data/assets/mruby/include/mruby/common.h +72 -0
  10. data/assets/mruby/include/mruby/compile.h +194 -0
  11. data/assets/mruby/include/mruby/data.h +75 -0
  12. data/assets/mruby/include/mruby/debug.h +66 -0
  13. data/assets/mruby/include/mruby/dump.h +196 -0
  14. data/assets/mruby/include/mruby/error.h +75 -0
  15. data/assets/mruby/include/mruby/gc.h +91 -0
  16. data/assets/mruby/include/mruby/hash.h +182 -0
  17. data/assets/mruby/include/mruby/irep.h +62 -0
  18. data/assets/mruby/include/mruby/istruct.h +47 -0
  19. data/assets/mruby/include/mruby/khash.h +274 -0
  20. data/assets/mruby/include/mruby/numeric.h +161 -0
  21. data/assets/mruby/include/mruby/object.h +45 -0
  22. data/assets/mruby/include/mruby/opcode.h +161 -0
  23. data/assets/mruby/include/mruby/proc.h +131 -0
  24. data/assets/mruby/include/mruby/range.h +49 -0
  25. data/assets/mruby/include/mruby/re.h +16 -0
  26. data/assets/mruby/include/mruby/string.h +440 -0
  27. data/assets/mruby/include/mruby/throw.h +55 -0
  28. data/assets/mruby/include/mruby/value.h +309 -0
  29. data/assets/mruby/include/mruby/variable.h +138 -0
  30. data/assets/mruby/include/mruby/version.h +110 -0
  31. data/assets/mruby/libmruby.a +0 -0
  32. data/assets/mruby_init.c +16 -0
  33. data/assets/template.html +17 -0
  34. data/bin/ruby-wasm +150 -0
  35. data/build_config.rb +13 -0
  36. data/lib/wasm.rb +0 -5
  37. data/lib/wasm/version.rb +4 -2
  38. metadata +46 -65
  39. data/.gitignore +0 -9
  40. data/.travis.yml +0 -5
  41. data/Gemfile +0 -4
  42. data/LICENSE.txt +0 -21
  43. data/README.md +0 -40
  44. data/Rakefile +0 -10
  45. data/bin/console +0 -14
  46. data/bin/setup +0 -8
  47. data/wasm.gemspec +0 -26
@@ -0,0 +1,196 @@
1
+ /*
2
+ ** mruby/dump.h - mruby binary dumper (mrbc binary format)
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_DUMP_H
8
+ #define MRUBY_DUMP_H
9
+
10
+ #include <mruby.h>
11
+ #include <mruby/irep.h>
12
+ #include "common.h"
13
+
14
+ /**
15
+ * Dumping compiled mruby script.
16
+ */
17
+ MRB_BEGIN_DECL
18
+
19
+ #define DUMP_DEBUG_INFO 1
20
+ #define DUMP_ENDIAN_BIG 2
21
+ #define DUMP_ENDIAN_LIL 4
22
+ #define DUMP_ENDIAN_NAT 6
23
+ #define DUMP_ENDIAN_MASK 6
24
+
25
+ int mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size);
26
+ #ifndef MRB_DISABLE_STDIO
27
+ int mrb_dump_irep_binary(mrb_state*, mrb_irep*, uint8_t, FILE*);
28
+ int mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep*, uint8_t flags, FILE *f, const char *initname);
29
+ mrb_irep *mrb_read_irep_file(mrb_state*, FILE*);
30
+ MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*);
31
+ MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrbc_context*);
32
+ #endif
33
+ MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
34
+
35
+ /* dump/load error code
36
+ *
37
+ * NOTE: MRB_DUMP_GENERAL_FAILURE is caused by
38
+ * unspecified issues like malloc failed.
39
+ */
40
+ #define MRB_DUMP_OK 0
41
+ #define MRB_DUMP_GENERAL_FAILURE (-1)
42
+ #define MRB_DUMP_WRITE_FAULT (-2)
43
+ #define MRB_DUMP_READ_FAULT (-3)
44
+ #define MRB_DUMP_CRC_ERROR (-4)
45
+ #define MRB_DUMP_INVALID_FILE_HEADER (-5)
46
+ #define MRB_DUMP_INVALID_IREP (-6)
47
+ #define MRB_DUMP_INVALID_ARGUMENT (-7)
48
+
49
+ /* null symbol length */
50
+ #define MRB_DUMP_NULL_SYM_LEN 0xFFFF
51
+
52
+ /* Rite Binary File header */
53
+ #define RITE_BINARY_IDENT "RITE"
54
+ #define RITE_BINARY_IDENT_LIL "ETIR"
55
+ #define RITE_BINARY_FORMAT_VER "0004"
56
+ #define RITE_COMPILER_NAME "MATZ"
57
+ #define RITE_COMPILER_VERSION "0000"
58
+
59
+ #define RITE_VM_VER "0000"
60
+
61
+ #define RITE_BINARY_EOF "END\0"
62
+ #define RITE_SECTION_IREP_IDENT "IREP"
63
+ #define RITE_SECTION_LINENO_IDENT "LINE"
64
+ #define RITE_SECTION_DEBUG_IDENT "DBG\0"
65
+ #define RITE_SECTION_LV_IDENT "LVAR"
66
+
67
+ #define MRB_DUMP_DEFAULT_STR_LEN 128
68
+ #define MRB_DUMP_ALIGNMENT sizeof(uint32_t)
69
+
70
+ /* binary header */
71
+ struct rite_binary_header {
72
+ uint8_t binary_ident[4]; /* Binary Identifier */
73
+ uint8_t binary_version[4]; /* Binary Format Version */
74
+ uint8_t binary_crc[2]; /* Binary CRC */
75
+ uint8_t binary_size[4]; /* Binary Size */
76
+ uint8_t compiler_name[4]; /* Compiler name */
77
+ uint8_t compiler_version[4];
78
+ };
79
+
80
+ /* section header */
81
+ #define RITE_SECTION_HEADER \
82
+ uint8_t section_ident[4]; \
83
+ uint8_t section_size[4]
84
+
85
+ struct rite_section_header {
86
+ RITE_SECTION_HEADER;
87
+ };
88
+
89
+ struct rite_section_irep_header {
90
+ RITE_SECTION_HEADER;
91
+
92
+ uint8_t rite_version[4]; /* Rite Instruction Specification Version */
93
+ };
94
+
95
+ struct rite_section_lineno_header {
96
+ RITE_SECTION_HEADER;
97
+ };
98
+
99
+ struct rite_section_debug_header {
100
+ RITE_SECTION_HEADER;
101
+ };
102
+
103
+ struct rite_section_lv_header {
104
+ RITE_SECTION_HEADER;
105
+ };
106
+
107
+ #define RITE_LV_NULL_MARK UINT16_MAX
108
+
109
+ struct rite_binary_footer {
110
+ RITE_SECTION_HEADER;
111
+ };
112
+
113
+ static inline int
114
+ bigendian_p()
115
+ {
116
+ int i;
117
+ char *p;
118
+
119
+ i = 1;
120
+ p = (char*)&i;
121
+ return p[0]?0:1;
122
+ }
123
+
124
+ static inline size_t
125
+ uint8_to_bin(uint8_t s, uint8_t *bin)
126
+ {
127
+ *bin = s;
128
+ return sizeof(uint8_t);
129
+ }
130
+
131
+ static inline size_t
132
+ uint16_to_bin(uint16_t s, uint8_t *bin)
133
+ {
134
+ *bin++ = (s >> 8) & 0xff;
135
+ *bin = s & 0xff;
136
+ return sizeof(uint16_t);
137
+ }
138
+
139
+ static inline size_t
140
+ uint32_to_bin(uint32_t l, uint8_t *bin)
141
+ {
142
+ *bin++ = (l >> 24) & 0xff;
143
+ *bin++ = (l >> 16) & 0xff;
144
+ *bin++ = (l >> 8) & 0xff;
145
+ *bin = l & 0xff;
146
+ return sizeof(uint32_t);
147
+ }
148
+
149
+ static inline size_t
150
+ uint32l_to_bin(uint32_t l, uint8_t *bin)
151
+ {
152
+ bin[3] = (l >> 24) & 0xff;
153
+ bin[2] = (l >> 16) & 0xff;
154
+ bin[1] = (l >> 8) & 0xff;
155
+ bin[0] = l & 0xff;
156
+ return sizeof(uint32_t);
157
+ }
158
+
159
+ static inline uint32_t
160
+ bin_to_uint32(const uint8_t *bin)
161
+ {
162
+ return (uint32_t)bin[0] << 24 |
163
+ (uint32_t)bin[1] << 16 |
164
+ (uint32_t)bin[2] << 8 |
165
+ (uint32_t)bin[3];
166
+ }
167
+
168
+ static inline uint32_t
169
+ bin_to_uint32l(const uint8_t *bin)
170
+ {
171
+ return (uint32_t)bin[3] << 24 |
172
+ (uint32_t)bin[2] << 16 |
173
+ (uint32_t)bin[1] << 8 |
174
+ (uint32_t)bin[0];
175
+ }
176
+
177
+ static inline uint16_t
178
+ bin_to_uint16(const uint8_t *bin)
179
+ {
180
+ return (uint16_t)bin[0] << 8 |
181
+ (uint16_t)bin[1];
182
+ }
183
+
184
+ static inline uint8_t
185
+ bin_to_uint8(const uint8_t *bin)
186
+ {
187
+ return (uint8_t)bin[0];
188
+ }
189
+
190
+ MRB_END_DECL
191
+
192
+ /** @internal crc.c */
193
+ uint16_t
194
+ calc_crc_16_ccitt(const uint8_t *src, size_t nbytes, uint16_t crc);
195
+
196
+ #endif /* MRUBY_DUMP_H */
@@ -0,0 +1,75 @@
1
+ /*
2
+ ** mruby/error.h - Exception class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_ERROR_H
8
+ #define MRUBY_ERROR_H
9
+
10
+ #include "common.h"
11
+
12
+ /**
13
+ * MRuby error handling.
14
+ */
15
+ MRB_BEGIN_DECL
16
+
17
+ struct RException {
18
+ MRB_OBJECT_HEADER;
19
+ struct iv_tbl *iv;
20
+ };
21
+
22
+ #define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
23
+
24
+ MRB_API void mrb_sys_fail(mrb_state *mrb, const char *mesg);
25
+ MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
26
+ #define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
27
+ MRB_API mrb_value mrb_make_exception(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
28
+ MRB_API mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
29
+ MRB_API mrb_value mrb_get_backtrace(mrb_state *mrb);
30
+ MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...);
31
+
32
+ /* declaration for fail method */
33
+ MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value);
34
+
35
+ struct RBreak {
36
+ MRB_OBJECT_HEADER;
37
+ struct RProc *proc;
38
+ mrb_value val;
39
+ };
40
+
41
+ /**
42
+ * Protect
43
+ *
44
+ * @mrbgem mruby-error
45
+ */
46
+ MRB_API mrb_value mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state);
47
+
48
+ /**
49
+ * Ensure
50
+ *
51
+ * @mrbgem mruby-error
52
+ */
53
+ MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
54
+ mrb_func_t ensure, mrb_value e_data);
55
+
56
+ /**
57
+ * Rescue
58
+ *
59
+ * @mrbgem mruby-error
60
+ */
61
+ MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
62
+ mrb_func_t rescue, mrb_value r_data);
63
+
64
+ /**
65
+ * Rescue exception
66
+ *
67
+ * @mrbgem mruby-error
68
+ */
69
+ MRB_API mrb_value mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
70
+ mrb_func_t rescue, mrb_value r_data,
71
+ mrb_int len, struct RClass **classes);
72
+
73
+ MRB_END_DECL
74
+
75
+ #endif /* MRUBY_ERROR_H */
@@ -0,0 +1,91 @@
1
+ /*
2
+ ** mruby/gc.h - garbage collector for mruby
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_GC_H
8
+ #define MRUBY_GC_H
9
+
10
+ #include "common.h"
11
+
12
+ /**
13
+ * Uncommon memory management stuffs.
14
+ */
15
+ MRB_BEGIN_DECL
16
+
17
+
18
+ struct mrb_state;
19
+
20
+ #define MRB_EACH_OBJ_OK 0
21
+ #define MRB_EACH_OBJ_BREAK 1
22
+ typedef int (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data);
23
+ void mrb_objspace_each_objects(struct mrb_state *mrb, mrb_each_object_callback *callback, void *data);
24
+ MRB_API void mrb_free_context(struct mrb_state *mrb, struct mrb_context *c);
25
+
26
+ #ifndef MRB_GC_ARENA_SIZE
27
+ #define MRB_GC_ARENA_SIZE 100
28
+ #endif
29
+
30
+ typedef enum {
31
+ MRB_GC_STATE_ROOT = 0,
32
+ MRB_GC_STATE_MARK,
33
+ MRB_GC_STATE_SWEEP
34
+ } mrb_gc_state;
35
+
36
+ /* Disable MSVC warning "C4200: nonstandard extension used: zero-sized array
37
+ * in struct/union" when in C++ mode */
38
+ #ifdef _MSC_VER
39
+ #pragma warning(push)
40
+ #pragma warning(disable : 4200)
41
+ #endif
42
+
43
+ typedef struct mrb_heap_page {
44
+ struct RBasic *freelist;
45
+ struct mrb_heap_page *prev;
46
+ struct mrb_heap_page *next;
47
+ struct mrb_heap_page *free_next;
48
+ struct mrb_heap_page *free_prev;
49
+ mrb_bool old:1;
50
+ void *objects[];
51
+ } mrb_heap_page;
52
+
53
+ #ifdef _MSC_VER
54
+ #pragma warning(pop)
55
+ #endif
56
+
57
+ typedef struct mrb_gc {
58
+ mrb_heap_page *heaps; /* heaps for GC */
59
+ mrb_heap_page *sweeps;
60
+ mrb_heap_page *free_heaps;
61
+ size_t live; /* count of live objects */
62
+ #ifdef MRB_GC_FIXED_ARENA
63
+ struct RBasic *arena[MRB_GC_ARENA_SIZE]; /* GC protection array */
64
+ #else
65
+ struct RBasic **arena; /* GC protection array */
66
+ int arena_capa;
67
+ #endif
68
+ int arena_idx;
69
+
70
+ mrb_gc_state state; /* state of gc */
71
+ int current_white_part; /* make white object by white_part */
72
+ struct RBasic *gray_list; /* list of gray objects to be traversed incrementally */
73
+ struct RBasic *atomic_gray_list; /* list of objects to be traversed atomically */
74
+ size_t live_after_mark;
75
+ size_t threshold;
76
+ int interval_ratio;
77
+ int step_ratio;
78
+ mrb_bool iterating :1;
79
+ mrb_bool disabled :1;
80
+ mrb_bool full :1;
81
+ mrb_bool generational :1;
82
+ mrb_bool out_of_memory :1;
83
+ size_t majorgc_old_threshold;
84
+ } mrb_gc;
85
+
86
+ MRB_API mrb_bool
87
+ mrb_object_dead_p(struct mrb_state *mrb, struct RBasic *object);
88
+
89
+ MRB_END_DECL
90
+
91
+ #endif /* MRUBY_GC_H */
@@ -0,0 +1,182 @@
1
+ /*
2
+ ** mruby/hash.h - Hash class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_HASH_H
8
+ #define MRUBY_HASH_H
9
+
10
+ #include "common.h"
11
+ #include <mruby/khash.h>
12
+
13
+ /**
14
+ * Hash class
15
+ */
16
+ MRB_BEGIN_DECL
17
+
18
+ struct RHash {
19
+ MRB_OBJECT_HEADER;
20
+ struct iv_tbl *iv;
21
+ struct kh_ht *ht;
22
+ };
23
+
24
+ #define mrb_hash_ptr(v) ((struct RHash*)(mrb_ptr(v)))
25
+ #define mrb_hash_value(p) mrb_obj_value((void*)(p))
26
+
27
+ MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int);
28
+
29
+ /*
30
+ * Initializes a new hash.
31
+ *
32
+ * Equivalent to:
33
+ *
34
+ * Hash.new
35
+ *
36
+ * @param mrb The mruby state reference.
37
+ * @return The initialized hash.
38
+ */
39
+ MRB_API mrb_value mrb_hash_new(mrb_state *mrb);
40
+
41
+ /*
42
+ * Sets a keys and values to hashes.
43
+ *
44
+ * Equivalent to:
45
+ *
46
+ * hash[key] = val
47
+ *
48
+ * @param mrb The mruby state reference.
49
+ * @param hash The target hash.
50
+ * @param key The key to set.
51
+ * @param val The value to set.
52
+ * @return The value.
53
+ */
54
+ MRB_API void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val);
55
+
56
+ /*
57
+ * Gets a value from a key. If the key is not found, the default of the
58
+ * hash is used.
59
+ *
60
+ * Equivalent to:
61
+ *
62
+ * hash[key]
63
+ *
64
+ * @param mrb The mruby state reference.
65
+ * @param hash The target hash.
66
+ * @param key The key to get.
67
+ * @return The found value.
68
+ */
69
+ MRB_API mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
70
+
71
+ /*
72
+ * Gets a value from a key. If the key is not found, the default parameter is
73
+ * used.
74
+ *
75
+ * Equivalent to:
76
+ *
77
+ * hash.hash_key?(key) ? hash[key] : def
78
+ *
79
+ * @param mrb The mruby state reference.
80
+ * @param hash The target hash.
81
+ * @param key The key to get.
82
+ * @param def The default value.
83
+ * @return The found value.
84
+ */
85
+ MRB_API mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def);
86
+
87
+ /*
88
+ * Deletes hash key and value pair.
89
+ *
90
+ * Equivalent to:
91
+ *
92
+ * hash.delete(key)
93
+ *
94
+ * @param mrb The mruby state reference.
95
+ * @param hash The target hash.
96
+ * @param key The key to delete.
97
+ * @return The deleted value.
98
+ */
99
+ MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key);
100
+
101
+ /*
102
+ * Gets an array of keys.
103
+ *
104
+ * Equivalent to:
105
+ *
106
+ * hash.keys
107
+ *
108
+ * @param mrb The mruby state reference.
109
+ * @param hash The target hash.
110
+ * @return An array with the keys of the hash.
111
+ */
112
+ MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash);
113
+ MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
114
+
115
+ /*
116
+ * Check if the hash is empty
117
+ *
118
+ * Equivalent to:
119
+ *
120
+ * hash.empty?
121
+ *
122
+ * @param mrb The mruby state reference.
123
+ * @param self The target hash.
124
+ * @return True if the hash is empty, false otherwise.
125
+ */
126
+ MRB_API mrb_value mrb_hash_empty_p(mrb_state *mrb, mrb_value self);
127
+
128
+ /*
129
+ * Gets an array of values.
130
+ *
131
+ * Equivalent to:
132
+ *
133
+ * hash.values
134
+ *
135
+ * @param mrb The mruby state reference.
136
+ * @param hash The target hash.
137
+ * @return An array with the values of the hash.
138
+ */
139
+ MRB_API mrb_value mrb_hash_values(mrb_state *mrb, mrb_value hash);
140
+
141
+ /*
142
+ * Clears the hash.
143
+ *
144
+ * Equivalent to:
145
+ *
146
+ * hash.clear
147
+ *
148
+ * @param mrb The mruby state reference.
149
+ * @param hash The target hash.
150
+ * @return The hash
151
+ */
152
+ MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
153
+
154
+ /* declaration of struct kh_ht */
155
+ /* be careful when you touch the internal */
156
+ typedef struct {
157
+ mrb_value v;
158
+ mrb_int n;
159
+ } mrb_hash_value;
160
+
161
+ KHASH_DECLARE(ht, mrb_value, mrb_hash_value, TRUE)
162
+
163
+ /* RHASH_TBL allocates st_table if not available. */
164
+ #define RHASH(obj) ((struct RHash*)(mrb_ptr(obj)))
165
+ #define RHASH_TBL(h) (RHASH(h)->ht)
166
+ #define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern_lit(mrb, "ifnone"))
167
+ #define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h)
168
+ MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);
169
+
170
+ #define MRB_HASH_DEFAULT 1
171
+ #define MRB_HASH_PROC_DEFAULT 2
172
+ #define MRB_RHASH_DEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_DEFAULT)
173
+ #define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT)
174
+
175
+ /* GC functions */
176
+ void mrb_gc_mark_hash(mrb_state*, struct RHash*);
177
+ size_t mrb_gc_mark_hash_size(mrb_state*, struct RHash*);
178
+ void mrb_gc_free_hash(mrb_state*, struct RHash*);
179
+
180
+ MRB_END_DECL
181
+
182
+ #endif /* MRUBY_HASH_H */