mutant-melbourne 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/LICENSE +25 -0
  2. data/README.md +69 -0
  3. data/Rakefile +14 -0
  4. data/ext/melbourne/.gitignore +3 -0
  5. data/ext/melbourne/bstring-license.txt +29 -0
  6. data/ext/melbourne/bstrlib.c +2687 -0
  7. data/ext/melbourne/bstrlib.h +267 -0
  8. data/ext/melbourne/encoding_compat.cpp +188 -0
  9. data/ext/melbourne/encoding_compat.hpp +57 -0
  10. data/ext/melbourne/extconf.rb +87 -0
  11. data/ext/melbourne/grammar18.cpp +11280 -0
  12. data/ext/melbourne/grammar18.hpp +13 -0
  13. data/ext/melbourne/grammar18.y +6088 -0
  14. data/ext/melbourne/grammar19.cpp +12420 -0
  15. data/ext/melbourne/grammar19.hpp +11 -0
  16. data/ext/melbourne/grammar19.y +7113 -0
  17. data/ext/melbourne/lex.c.blt +152 -0
  18. data/ext/melbourne/lex.c.tab +136 -0
  19. data/ext/melbourne/local_state.hpp +43 -0
  20. data/ext/melbourne/melbourne.cpp +88 -0
  21. data/ext/melbourne/melbourne.hpp +19 -0
  22. data/ext/melbourne/node18.hpp +262 -0
  23. data/ext/melbourne/node19.hpp +271 -0
  24. data/ext/melbourne/node_types.rb +304 -0
  25. data/ext/melbourne/node_types18.cpp +255 -0
  26. data/ext/melbourne/node_types18.hpp +129 -0
  27. data/ext/melbourne/node_types19.cpp +249 -0
  28. data/ext/melbourne/node_types19.hpp +126 -0
  29. data/ext/melbourne/parser_state18.hpp +181 -0
  30. data/ext/melbourne/parser_state19.hpp +251 -0
  31. data/ext/melbourne/quark.cpp +42 -0
  32. data/ext/melbourne/quark.hpp +45 -0
  33. data/ext/melbourne/symbols.cpp +224 -0
  34. data/ext/melbourne/symbols.hpp +119 -0
  35. data/ext/melbourne/var_table18.cpp +83 -0
  36. data/ext/melbourne/var_table18.hpp +33 -0
  37. data/ext/melbourne/var_table19.cpp +65 -0
  38. data/ext/melbourne/var_table19.hpp +35 -0
  39. data/ext/melbourne/visitor18.cpp +963 -0
  40. data/ext/melbourne/visitor18.hpp +12 -0
  41. data/ext/melbourne/visitor19.cpp +960 -0
  42. data/ext/melbourne/visitor19.hpp +15 -0
  43. data/lib/compiler/ast/constants.rb +81 -0
  44. data/lib/compiler/ast/control_flow.rb +290 -0
  45. data/lib/compiler/ast/data.rb +14 -0
  46. data/lib/compiler/ast/definitions.rb +749 -0
  47. data/lib/compiler/ast/encoding.rb +18 -0
  48. data/lib/compiler/ast/exceptions.rb +138 -0
  49. data/lib/compiler/ast/file.rb +11 -0
  50. data/lib/compiler/ast/grapher.rb +89 -0
  51. data/lib/compiler/ast/literals.rb +207 -0
  52. data/lib/compiler/ast/node.rb +362 -0
  53. data/lib/compiler/ast/operators.rb +106 -0
  54. data/lib/compiler/ast/self.rb +15 -0
  55. data/lib/compiler/ast/sends.rb +615 -0
  56. data/lib/compiler/ast/transforms.rb +298 -0
  57. data/lib/compiler/ast/values.rb +88 -0
  58. data/lib/compiler/ast/variables.rb +351 -0
  59. data/lib/compiler/ast.rb +20 -0
  60. data/lib/compiler/locals.rb +109 -0
  61. data/lib/melbourne/processor.rb +651 -0
  62. data/lib/melbourne/version.rb +3 -0
  63. data/lib/melbourne.rb +143 -0
  64. metadata +112 -0
@@ -0,0 +1,267 @@
1
+ /*
2
+ * This source file is part of the bstring string library. This code was
3
+ * written by Paul Hsieh in 2002-2007, and is covered by the BSD open source
4
+ * license. Refer to the accompanying documentation for details on usage and
5
+ * license.
6
+ */
7
+
8
+ /*
9
+ * bstrlib.c
10
+ *
11
+ * This file is the core module for implementing the bstring functions.
12
+ */
13
+
14
+ #ifndef BSTRLIB_INCLUDE
15
+ #define BSTRLIB_INCLUDE
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ #include <stdarg.h>
22
+ #include <string.h>
23
+ #include <limits.h>
24
+ #include <ctype.h>
25
+
26
+ #define BSTR_ERR (-1)
27
+ #define BSTR_OK (0)
28
+ #define BSTR_BS_BUFF_LENGTH_GET (0)
29
+
30
+ typedef struct tagbstring * bstring;
31
+ typedef const struct tagbstring * const_bstring;
32
+
33
+ /* Copy functions */
34
+ #define cstr2bstr bfromcstr
35
+ extern bstring bfromcstr (const char * str);
36
+ extern bstring bfromcstralloc (int mlen, const char * str);
37
+ extern bstring blk2bstr (const void * blk, int len);
38
+ extern char * bstr2cstr (const_bstring s, char z);
39
+ extern int bcstrfree (char * s);
40
+ extern bstring bstrcpy (const_bstring b1);
41
+ extern int bassign (bstring a, const_bstring b);
42
+ extern int bassignmidstr (bstring a, const_bstring b, int left, int len);
43
+ extern int bassigncstr (bstring a, const char * str);
44
+ extern int bassignblk (bstring a, const void * s, int len);
45
+
46
+ /* Destroy function */
47
+ extern int bdestroy (bstring b);
48
+
49
+ /* Space allocation hinting functions */
50
+ extern int balloc (bstring s, int len);
51
+ extern int ballocmin (bstring b, int len);
52
+
53
+ /* Substring extraction */
54
+ extern bstring bmidstr (const_bstring b, int left, int len);
55
+
56
+ /* Various standard manipulations */
57
+ extern int bconcat (bstring b0, const_bstring b1);
58
+ extern int bconchar (bstring b0, char c);
59
+ extern int bcatcstr (bstring b, const char * s);
60
+ extern int bcatblk (bstring b, const void * s, int len);
61
+ extern int binsert (bstring s1, int pos, const_bstring s2, unsigned char fill);
62
+ extern int binsertch (bstring s1, int pos, int len, unsigned char fill);
63
+ extern int breplace (bstring b1, int pos, int len, const_bstring b2, unsigned char fill);
64
+ extern int bdelete (bstring s1, int pos, int len);
65
+ extern int bsetstr (bstring b0, int pos, const_bstring b1, unsigned char fill);
66
+ extern int btrunc (bstring b, int n);
67
+
68
+ /* Scan/search functions */
69
+ extern int bstricmp (const_bstring b0, const_bstring b1);
70
+ extern int bstrnicmp (const_bstring b0, const_bstring b1, int n);
71
+ extern int biseqcaseless (const_bstring b0, const_bstring b1);
72
+ extern int bisstemeqcaselessblk (const_bstring b0, const void * blk, int len);
73
+ extern int biseq (const_bstring b0, const_bstring b1);
74
+ extern int bisstemeqblk (const_bstring b0, const void * blk, int len);
75
+ extern int biseqcstr (const_bstring b, const char * s);
76
+ extern int biseqcstrcaseless (const_bstring b, const char * s);
77
+ extern int bstrcmp (const_bstring b0, const_bstring b1);
78
+ extern int bstrncmp (const_bstring b0, const_bstring b1, int n);
79
+ extern int binstr (const_bstring s1, int pos, const_bstring s2);
80
+ extern int binstrr (const_bstring s1, int pos, const_bstring s2);
81
+ extern int binstrcaseless (const_bstring s1, int pos, const_bstring s2);
82
+ extern int binstrrcaseless (const_bstring s1, int pos, const_bstring s2);
83
+ extern int bstrchrp (const_bstring b, int c, int pos);
84
+ extern int bstrrchrp (const_bstring b, int c, int pos);
85
+ #define bstrchr(b,c) bstrchrp ((b), (c), 0)
86
+ #define bstrrchr(b,c) bstrrchrp ((b), (c), blength(b)-1)
87
+ extern int binchr (const_bstring b0, int pos, const_bstring b1);
88
+ extern int binchrr (const_bstring b0, int pos, const_bstring b1);
89
+ extern int bninchr (const_bstring b0, int pos, const_bstring b1);
90
+ extern int bninchrr (const_bstring b0, int pos, const_bstring b1);
91
+ extern int bfindreplace (bstring b, const_bstring find, const_bstring repl, int pos);
92
+ extern int bfindreplacecaseless (bstring b, const_bstring find, const_bstring repl, int pos);
93
+
94
+ /* List of string container functions */
95
+ struct bstrList {
96
+ int qty, mlen;
97
+ bstring * entry;
98
+ };
99
+ extern struct bstrList * bstrListCreate (void);
100
+ extern int bstrListDestroy (struct bstrList * sl);
101
+ extern int bstrListAlloc (struct bstrList * sl, int msz);
102
+ extern int bstrListAllocMin (struct bstrList * sl, int msz);
103
+
104
+ /* String split and join functions */
105
+ extern struct bstrList * bsplit (const_bstring str, unsigned char splitChar);
106
+ extern struct bstrList * bsplits (const_bstring str, const_bstring splitStr);
107
+ extern struct bstrList * bsplitstr (const_bstring str, const_bstring splitStr);
108
+ extern bstring bjoin (const struct bstrList * bl, const_bstring sep);
109
+ extern int bsplitcb (const_bstring str, unsigned char splitChar, int pos,
110
+ int (* cb) (void * parm, int ofs, int len), void * parm);
111
+ extern int bsplitscb (const_bstring str, const_bstring splitStr, int pos,
112
+ int (* cb) (void * parm, int ofs, int len), void * parm);
113
+ extern int bsplitstrcb (const_bstring str, const_bstring splitStr, int pos,
114
+ int (* cb) (void * parm, int ofs, int len), void * parm);
115
+
116
+ /* Miscellaneous functions */
117
+ extern int bpattern (bstring b, int len);
118
+ extern int btoupper (bstring b);
119
+ extern int btolower (bstring b);
120
+ extern int bltrimws (bstring b);
121
+ extern int brtrimws (bstring b);
122
+ extern int btrimws (bstring b);
123
+
124
+ typedef int (*bNgetc) (void *parm);
125
+ typedef size_t (* bNread) (void *buff, size_t elsize, size_t nelem, void *parm);
126
+
127
+ /* Input functions */
128
+ extern bstring bgets (bNgetc getcPtr, void * parm, char terminator);
129
+ extern bstring bread (bNread readPtr, void * parm);
130
+ extern int bgetsa (bstring b, bNgetc getcPtr, void * parm, char terminator);
131
+ extern int bassigngets (bstring b, bNgetc getcPtr, void * parm, char terminator);
132
+ extern int breada (bstring b, bNread readPtr, void * parm);
133
+
134
+ /* Stream functions */
135
+ extern struct bStream * bsopen (bNread readPtr, void * parm);
136
+ extern void * bsclose (struct bStream * s);
137
+ extern int bsbufflength (struct bStream * s, int sz);
138
+ extern int bsreadln (bstring b, struct bStream * s, char terminator);
139
+ extern int bsreadlns (bstring r, struct bStream * s, const_bstring term);
140
+ extern int bsread (bstring b, struct bStream * s, int n);
141
+ extern int bsreadlna (bstring b, struct bStream * s, char terminator);
142
+ extern int bsreadlnsa (bstring r, struct bStream * s, const_bstring term);
143
+ extern int bsreada (bstring b, struct bStream * s, int n);
144
+ extern int bsunread (struct bStream * s, const_bstring b);
145
+ extern int bspeek (bstring r, const struct bStream * s);
146
+ extern int bssplitscb (struct bStream * s, const_bstring splitStr,
147
+ int (* cb) (void * parm, int ofs, const_bstring entry), void * parm);
148
+ extern int bssplitstrcb (struct bStream * s, const_bstring splitStr,
149
+ int (* cb) (void * parm, int ofs, const_bstring entry), void * parm);
150
+ extern int bseof (const struct bStream * s);
151
+
152
+ struct tagbstring {
153
+ int mlen;
154
+ int slen;
155
+ unsigned char * data;
156
+ };
157
+
158
+ /* Accessor macros */
159
+ #define blengthe(b, e) (((b) == (void *)0 || (b)->slen < 0) ? (int)(e) : ((b)->slen))
160
+ #define blength(b) (blengthe ((b), 0))
161
+ #define bdataofse(b, o, e) (((b) == (void *)0 || (b)->data == (void*)0) ? (char *)(e) : ((char *)(b)->data) + (o))
162
+ #define bdataofs(b, o) (bdataofse ((b), (o), (void *)0))
163
+ #define bdatae(b, e) (bdataofse (b, 0, e))
164
+ #define bdata(b) (bdataofs (b, 0))
165
+ #define bchare(b, p, e) ((((unsigned)(p)) < (unsigned)blength(b)) ? ((b)->data[(p)]) : (e))
166
+ #define bchar(b, p) bchare ((b), (p), '\0')
167
+
168
+ /* Static constant string initialization macro */
169
+ #if defined(_MSC_VER) && defined(_DEBUG)
170
+ # if _MSC_VER <= 1310
171
+ # define bsStatic(q) {-32, (int) sizeof(q)-1, (unsigned char *) ("" q "")}
172
+ # endif
173
+ #endif
174
+ #ifndef bsStatic
175
+ # define bsStatic(q) {-__LINE__, (int) sizeof(q)-1, (unsigned char *) ("" q "")}
176
+ #endif
177
+
178
+ /* Static constant block parameter pair */
179
+ #define bsStaticBlkParms(q) ((void *)("" q "")), ((int) sizeof(q)-1)
180
+
181
+ /* Reference building macros */
182
+ #define cstr2tbstr btfromcstr
183
+ #define btfromcstr(t,s) { \
184
+ (t).data = (unsigned char *) (s); \
185
+ (t).slen = ((t).data) ? ((int) (strlen) ((char *)(t).data)) : 0; \
186
+ (t).mlen = -1; \
187
+ }
188
+ #define blk2tbstr(t,s,l) { \
189
+ (t).data = (unsigned char *) (s); \
190
+ (t).slen = l; \
191
+ (t).mlen = -1; \
192
+ }
193
+ #define btfromblk(t,s,l) blk2tbstr(t,s,l)
194
+ #define bmid2tbstr(t,b,p,l) { \
195
+ bstring bstrtmp_s = (b); \
196
+ if (bstrtmp_s && bstrtmp_s->data && bstrtmp_s->slen >= 0) { \
197
+ int bstrtmp_left = (p); \
198
+ int bstrtmp_len = (l); \
199
+ if (bstrtmp_left < 0) { \
200
+ bstrtmp_len += bstrtmp_left; \
201
+ bstrtmp_left = 0; \
202
+ } \
203
+ if (bstrtmp_len > bstrtmp_s->slen - bstrtmp_left) \
204
+ bstrtmp_len = bstrtmp_s->slen - bstrtmp_left; \
205
+ if (bstrtmp_len <= 0) { \
206
+ (t).data = (unsigned char *)""; \
207
+ (t).slen = 0; \
208
+ } else { \
209
+ (t).data = bstrtmp_s->data + bstrtmp_left; \
210
+ (t).slen = bstrtmp_len; \
211
+ } \
212
+ } else { \
213
+ (t).data = (unsigned char *)""; \
214
+ (t).slen = 0; \
215
+ } \
216
+ (t).mlen = -__LINE__; \
217
+ }
218
+ #define btfromblkltrimws(t,s,l) { \
219
+ int bstrtmp_idx = 0, bstrtmp_len = (l); \
220
+ unsigned char * bstrtmp_s = (s); \
221
+ if (bstrtmp_s && bstrtmp_len >= 0) { \
222
+ for (; bstrtmp_idx < bstrtmp_len; bstrtmp_idx++) { \
223
+ if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
224
+ } \
225
+ } \
226
+ (t).data = bstrtmp_s + bstrtmp_idx; \
227
+ (t).slen = bstrtmp_len - bstrtmp_idx; \
228
+ (t).mlen = -__LINE__; \
229
+ }
230
+ #define btfromblkrtrimws(t,s,l) { \
231
+ int bstrtmp_len = (l) - 1; \
232
+ unsigned char * bstrtmp_s = (s); \
233
+ if (bstrtmp_s && bstrtmp_len >= 0) { \
234
+ for (; bstrtmp_len >= 0; bstrtmp_len--) { \
235
+ if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
236
+ } \
237
+ } \
238
+ (t).data = bstrtmp_s; \
239
+ (t).slen = bstrtmp_len + 1; \
240
+ (t).mlen = -__LINE__; \
241
+ }
242
+ #define btfromblktrimws(t,s,l) { \
243
+ int bstrtmp_idx = 0, bstrtmp_len = (l) - 1; \
244
+ unsigned char * bstrtmp_s = (s); \
245
+ if (bstrtmp_s && bstrtmp_len >= 0) { \
246
+ for (; bstrtmp_idx <= bstrtmp_len; bstrtmp_idx++) { \
247
+ if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
248
+ } \
249
+ for (; bstrtmp_len >= bstrtmp_idx; bstrtmp_len--) { \
250
+ if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
251
+ } \
252
+ } \
253
+ (t).data = bstrtmp_s + bstrtmp_idx; \
254
+ (t).slen = bstrtmp_len + 1 - bstrtmp_idx; \
255
+ (t).mlen = -__LINE__; \
256
+ }
257
+
258
+ /* Write protection macros */
259
+ #define bwriteprotect(t) { if ((t).mlen >= 0) (t).mlen = -1; }
260
+ #define bwriteallow(t) { if ((t).mlen == -1) (t).mlen = (t).slen + ((t).slen == 0); }
261
+ #define biswriteprotected(t) ((t).mlen <= 0)
262
+
263
+ #ifdef __cplusplus
264
+ }
265
+ #endif
266
+
267
+ #endif
@@ -0,0 +1,188 @@
1
+ #include "encoding_compat.hpp"
2
+
3
+ extern "C" {
4
+
5
+ #ifdef HAVE_RUBY_ENCODING_H
6
+
7
+ int parser_enc_isalnum(int c, rb_encoding* enc) {
8
+ return rb_enc_isalnum(c, enc);
9
+ }
10
+
11
+ int parser_enc_isascii(int c, rb_encoding* enc) {
12
+ return rb_enc_isascii(c, enc);
13
+ }
14
+
15
+ int parser_enc_isspace(int c, rb_encoding* enc) {
16
+ return rb_enc_isspace(c, enc);
17
+ }
18
+
19
+ int parser_enc_ispunct(int c, rb_encoding* enc) {
20
+ return rb_enc_ispunct(c, enc);
21
+ }
22
+
23
+ int parser_enc_isupper(int c, rb_encoding* enc) {
24
+ return rb_enc_isupper(c, enc);
25
+ }
26
+
27
+ int parser_enc_precise_mbclen(const char* p, const char* e, rb_encoding* enc) {
28
+ return rb_enc_precise_mbclen(p, e, enc);
29
+ }
30
+
31
+ int parser_enc_codelen(int c, rb_encoding* enc) {
32
+ return rb_enc_codelen(c, enc);
33
+ }
34
+
35
+ int parser_enc_mbclen(const char* p, const char* e, rb_encoding* enc) {
36
+ return rb_enc_mbclen(p, e, enc);
37
+ }
38
+
39
+ int parser_enc_asciicompat(rb_encoding* enc) {
40
+ return rb_enc_asciicompat(enc);
41
+ }
42
+
43
+ int parser_enc_str_coderange(VALUE str) {
44
+ return rb_enc_str_coderange(str);
45
+ }
46
+
47
+ int parser_enc_find_index(const char* name) {
48
+ return rb_enc_find_index(name);
49
+ }
50
+
51
+ void parser_enc_mbcput(int c, const char* ptr, rb_encoding* enc) {
52
+ rb_enc_mbcput(c, ptr, enc);
53
+ }
54
+
55
+ const char* parser_enc_name(rb_encoding* enc) {
56
+ return rb_enc_name(enc);
57
+ }
58
+
59
+ VALUE parser_enc_str_new(const char* ptr, long len, rb_encoding* enc) {
60
+ return rb_enc_str_new(ptr, len, enc);
61
+ }
62
+
63
+ VALUE parser_enc_associate(VALUE obj, rb_encoding* enc) {
64
+ return rb_enc_associate(obj, enc);
65
+ }
66
+
67
+ rb_encoding* parser_enc_get(VALUE obj) {
68
+ return rb_enc_get(obj);
69
+ }
70
+
71
+ rb_encoding* parser_enc_compatible(VALUE str1, VALUE str2) {
72
+ return rb_enc_compatible(str1, str2);
73
+ }
74
+
75
+ rb_encoding* parser_enc_from_index(int index) {
76
+ return rb_enc_from_index(index);
77
+ }
78
+
79
+ rb_encoding* parser_utf8_encoding() {
80
+ return rb_utf8_encoding();
81
+ }
82
+
83
+ rb_encoding* parser_usascii_encoding() {
84
+ return rb_usascii_encoding();
85
+ }
86
+
87
+ rb_encoding* parser_ascii8bit_encoding() {
88
+ return rb_ascii8bit_encoding();
89
+ }
90
+
91
+ #else
92
+
93
+ int parser_enc_isalnum(int c, rb_encoding* enc) {
94
+ return isalnum(c);
95
+ }
96
+
97
+ int parser_enc_isascii(int c, rb_encoding* enc) {
98
+ return isascii(c);
99
+ }
100
+
101
+ int parser_enc_isspace(int c, rb_encoding* enc) {
102
+ return isspace(c);
103
+ }
104
+
105
+ int parser_enc_ispunct(int c, rb_encoding* enc) {
106
+ return ispunct(c);
107
+ }
108
+
109
+ int parser_enc_isupper(int c, rb_encoding* enc) {
110
+ return isupper(c);
111
+ }
112
+
113
+ int parser_enc_precise_mbclen(const char* p, const char* e, rb_encoding* enc) {
114
+ return 1;
115
+ }
116
+
117
+ int parser_enc_codelen(int c, rb_encoding* enc) {
118
+ return 1;
119
+ }
120
+
121
+ int parser_enc_mbclen(const char* p, const char* e, rb_encoding* enc) {
122
+ return 1;
123
+ }
124
+
125
+ int parser_enc_asciicompat(rb_encoding* enc) {
126
+ return 1;
127
+ }
128
+
129
+ int parser_enc_str_coderange(VALUE str) {
130
+ return ENC_CODERANGE_7BIT;
131
+ }
132
+
133
+ int parser_enc_find_index(const char* name) {
134
+ return 1;
135
+ }
136
+
137
+ void parser_enc_mbcput(int c, const char* ptr, rb_encoding* enc) {
138
+ // Do nothing
139
+ }
140
+
141
+ const char* parser_enc_name(rb_encoding* enc) {
142
+ return enc->name;
143
+ }
144
+
145
+ VALUE parser_enc_str_new(const char* ptr, long len, rb_encoding* enc) {
146
+ return rb_str_new(ptr, len);
147
+ }
148
+
149
+ VALUE parser_enc_associate(VALUE obj, rb_encoding* enc) {
150
+ return obj;
151
+ }
152
+
153
+ rb_encoding* parser_enc_get(VALUE obj) {
154
+ return parser_usascii_encoding();
155
+ }
156
+
157
+ rb_encoding* parser_enc_compatible(VALUE str1, VALUE str2) {
158
+ return parser_enc_get(str1);
159
+ }
160
+
161
+ rb_encoding* parser_enc_from_index(int index) {
162
+ return parser_usascii_encoding();
163
+ }
164
+
165
+ rb_encoding* parser_utf8_encoding() {
166
+ static rb_encoding enc = { "UTF-8" };
167
+
168
+ return &enc;
169
+ }
170
+
171
+ rb_encoding* parser_usascii_encoding() {
172
+ static rb_encoding enc = { "US-ASCII" };
173
+
174
+ return &enc;
175
+ }
176
+
177
+ rb_encoding* parser_ascii8bit_encoding() {
178
+ static rb_encoding enc = { "ASCII-8BIT" };
179
+
180
+ return &enc;
181
+ }
182
+
183
+ ID rb_intern_str(VALUE str) {
184
+ return SYM2ID(rb_funcall(str, rb_intern("to_sym"), 0));
185
+ }
186
+
187
+ #endif
188
+ }
@@ -0,0 +1,57 @@
1
+ #ifndef MEL_ENCODING_COMPAT_HPP
2
+ #define MEL_ENCODING_COMPAT_HPP
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+ #include "melbourne.hpp"
8
+
9
+ #ifdef HAVE_RUBY_ENCODING_H
10
+ #include "ruby/encoding.h"
11
+ #else
12
+
13
+ #define ENCODING_NAMELEN_MAX 63
14
+
15
+ typedef struct {
16
+ const char name[ENCODING_NAMELEN_MAX];
17
+ } rb_encoding;
18
+
19
+ #define ENC_CODERANGE_UNKNOWN 0
20
+ #define ENC_CODERANGE_7BIT 1
21
+
22
+ #define MBCLEN_CHARFOUND_P(ret) 1
23
+
24
+ #endif
25
+
26
+ int parser_enc_isalnum(int c, rb_encoding* enc);
27
+ int parser_enc_isascii(int c, rb_encoding* enc);
28
+ int parser_enc_isspace(int c, rb_encoding* enc);
29
+ int parser_enc_ispunct(int c, rb_encoding* enc);
30
+ int parser_enc_isupper(int c, rb_encoding* enc);
31
+
32
+ int parser_enc_precise_mbclen(const char* p, const char* e, rb_encoding* enc);
33
+ int parser_enc_codelen(int c, rb_encoding* enc);
34
+ int parser_enc_mbclen(const char* p, const char* e, rb_encoding* enc);
35
+ int parser_enc_asciicompat(rb_encoding* enc);
36
+ int parser_enc_str_coderange(VALUE str);
37
+ int parser_enc_find_index(const char* name);
38
+
39
+ void parser_enc_mbcput(int c, const char* ptr, rb_encoding* enc);
40
+
41
+ const char* parser_enc_name(rb_encoding* enc);
42
+
43
+ VALUE parser_enc_str_new(const char* ptr, long len, rb_encoding* enc);
44
+ VALUE parser_enc_associate(VALUE obj, rb_encoding* enc);
45
+
46
+ rb_encoding* parser_enc_get(VALUE obj);
47
+ rb_encoding* parser_enc_compatible(VALUE str1, VALUE str2);
48
+ rb_encoding* parser_enc_from_index(int index);
49
+ rb_encoding* parser_utf8_encoding();
50
+ rb_encoding* parser_usascii_encoding();
51
+ rb_encoding* parser_ascii8bit_encoding();
52
+
53
+ #ifdef __cplusplus
54
+ } /* extern "C" { */
55
+ #endif
56
+
57
+ #endif
@@ -0,0 +1,87 @@
1
+ unless(defined?(RUBY_ENGINE) and RUBY_ENGINE == 'rbx')
2
+ require 'mkmf'
3
+
4
+ def add_lib(name)
5
+ i, lib = dir_config(name)
6
+ $libs << " #{lib}/lib#{name}.a "
7
+ end
8
+
9
+ # add_lib("mquark")
10
+ # add_lib("bstring")
11
+ # add_lib("ptr_array")
12
+ # add_lib("cchash")
13
+
14
+ #have_library("bstring")
15
+ #have_library("mquark")
16
+ #have_library("ptr_array")
17
+ #have_library("cchash")
18
+
19
+ $CFLAGS += " -ggdb3"
20
+
21
+ # Courtesy of EventMachine. Thank you EventMachine and tmm1 !
22
+ case RUBY_PLATFORM
23
+ when /mswin32/, /mingw32/, /bccwin32/
24
+ check_heads(%w[windows.h winsock.h], true)
25
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
26
+
27
+ if GNU_CHAIN
28
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
29
+ else
30
+ $defs.push "-EHs"
31
+ $defs.push "-GR"
32
+ end
33
+
34
+ when /solaris/
35
+ add_define 'OS_SOLARIS8'
36
+
37
+ if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
38
+ # SUN CHAIN
39
+ add_define 'CC_SUNWspro'
40
+ $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
41
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
42
+ CONFIG['CCDLFLAGS'] = "-KPIC"
43
+ CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
44
+ else
45
+ # GNU CHAIN
46
+ # on Unix we need a g++ link, not gcc.
47
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
48
+ end
49
+
50
+ when /openbsd/
51
+ # OpenBSD branch contributed by Guillaume Sellier.
52
+
53
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
54
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
55
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
56
+
57
+ when /darwin/
58
+ # on Unix we need a g++ link, not gcc.
59
+ # Ff line contributed by Daniel Harple.
60
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
61
+
62
+ when /aix/
63
+ CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
64
+
65
+ else
66
+ # on Unix we need a g++ link, not gcc.
67
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
68
+ end
69
+
70
+ create_makefile('melbourne')
71
+
72
+ File.open("Makefile","a+") do |f|
73
+ f.puts <<END
74
+
75
+ grammar.cpp: grammar.y
76
+ bison -o grammar.cpp grammar.y
77
+ END
78
+ end
79
+ else
80
+ File.open("Makefile","w+") do |f|
81
+ f.puts <<END
82
+ all:
83
+
84
+ install:
85
+ END
86
+ end
87
+ end