rubinius-melbourne 1.2.1.0 → 2.0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,267 +0,0 @@
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
@@ -1,136 +0,0 @@
1
- /* C code produced by gperf version 2.7.2 */
2
- /* Command-line: gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' ./keywords */
3
- struct kwtable {
4
- int id[2];
5
- enum lex_state_e state;
6
- char name[16];
7
- };
8
-
9
- #define TOTAL_KEYWORDS 40
10
- #define MIN_WORD_LENGTH 2
11
- #define MAX_WORD_LENGTH 8
12
- #define MIN_HASH_VALUE 6
13
- #define MAX_HASH_VALUE 55
14
- /* maximum key range = 50, duplicates = 0 */
15
-
16
- #ifdef __GNUC__
17
- __inline
18
- #else
19
- #ifdef __cplusplus
20
- inline
21
- #endif
22
- #endif
23
- static unsigned int
24
- hash (register const char *str, register unsigned int len)
25
- {
26
- static const unsigned char asso_values[] =
27
- {
28
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
29
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
30
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
31
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
32
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
33
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
34
- 56, 56, 56, 11, 56, 56, 36, 56, 1, 37,
35
- 31, 1, 56, 56, 56, 56, 29, 56, 1, 56,
36
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
37
- 56, 56, 56, 56, 56, 1, 56, 32, 1, 2,
38
- 1, 1, 4, 23, 56, 17, 56, 20, 9, 2,
39
- 9, 26, 14, 56, 5, 1, 1, 16, 56, 21,
40
- 20, 9, 56, 56, 56, 56, 56, 56, 56, 56,
41
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
42
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
43
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
44
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
45
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
46
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
47
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
48
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
49
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
50
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
51
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
52
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
53
- 56, 56, 56, 56, 56, 56
54
- };
55
- register int hval = len;
56
-
57
- switch (hval)
58
- {
59
- default:
60
- case 3:
61
- hval += asso_values[(unsigned char)str[2]];
62
- case 2:
63
- case 1:
64
- hval += asso_values[(unsigned char)str[0]];
65
- break;
66
- }
67
- return hval + asso_values[(unsigned char)str[len - 1]];
68
- }
69
-
70
- #ifdef __GNUC__
71
- __inline
72
- #endif
73
- const struct kwtable *
74
- mel_reserved_word (register const char *str, register unsigned int len)
75
- {
76
- static const struct kwtable wordlist[] =
77
- {
78
- {{0, 0}}, {{0, 0}}, {{0, 0}}, {{0, 0}}, {{0, 0}}, {{0, 0}},
79
- {{kEND, kEND}, EXPR_END, "end"},
80
- {{kELSE, kELSE}, EXPR_BEG, "else"},
81
- {{kCASE, kCASE}, EXPR_BEG, "case"},
82
- {{kENSURE, kENSURE}, EXPR_BEG, "ensure"},
83
- {{kMODULE, kMODULE}, EXPR_BEG, "module"},
84
- {{kELSIF, kELSIF}, EXPR_BEG, "elsif"},
85
- {{kDEF, kDEF}, EXPR_FNAME, "def"},
86
- {{kRESCUE, kRESCUE_MOD}, EXPR_MID, "rescue"},
87
- {{kNOT, kNOT}, EXPR_BEG, "not"},
88
- {{kTHEN, kTHEN}, EXPR_BEG, "then"},
89
- {{kYIELD, kYIELD}, EXPR_ARG, "yield"},
90
- {{kFOR, kFOR}, EXPR_BEG, "for"},
91
- {{kSELF, kSELF}, EXPR_END, "self"},
92
- {{kFALSE, kFALSE}, EXPR_END, "false"},
93
- {{kRETRY, kRETRY}, EXPR_END, "retry"},
94
- {{kRETURN, kRETURN}, EXPR_MID, "return"},
95
- {{kTRUE, kTRUE}, EXPR_END, "true"},
96
- {{kIF, kIF_MOD}, EXPR_BEG, "if"},
97
- {{kDEFINED, kDEFINED}, EXPR_ARG, "defined?"},
98
- {{kSUPER, kSUPER}, EXPR_ARG, "super"},
99
- {{kUNDEF, kUNDEF}, EXPR_FNAME, "undef"},
100
- {{kBREAK, kBREAK}, EXPR_MID, "break"},
101
- {{kIN, kIN}, EXPR_BEG, "in"},
102
- {{kDO, kDO}, EXPR_BEG, "do"},
103
- {{kNIL, kNIL}, EXPR_END, "nil"},
104
- {{kUNTIL, kUNTIL_MOD}, EXPR_BEG, "until"},
105
- {{kUNLESS, kUNLESS_MOD}, EXPR_BEG, "unless"},
106
- {{kOR, kOR}, EXPR_BEG, "or"},
107
- {{kNEXT, kNEXT}, EXPR_MID, "next"},
108
- {{kWHEN, kWHEN}, EXPR_BEG, "when"},
109
- {{kREDO, kREDO}, EXPR_END, "redo"},
110
- {{kAND, kAND}, EXPR_BEG, "and"},
111
- {{kBEGIN, kBEGIN}, EXPR_BEG, "begin"},
112
- {{k__LINE__, k__LINE__}, EXPR_END, "__LINE__"},
113
- {{kCLASS, kCLASS}, EXPR_CLASS, "class"},
114
- {{k__FILE__, k__FILE__}, EXPR_END, "__FILE__"},
115
- {{klEND, klEND}, EXPR_END, "END"},
116
- {{klBEGIN, klBEGIN}, EXPR_END, "BEGIN"},
117
- {{kWHILE, kWHILE_MOD}, EXPR_BEG, "while"},
118
- {{0, 0}}, {{0, 0}}, {{0, 0}}, {{0, 0}}, {{0, 0}},
119
- {{0, 0}}, {{0, 0}}, {{0, 0}}, {{0, 0}}, {{0, 0}},
120
- {{kALIAS, kALIAS}, EXPR_FNAME, "alias"}
121
- };
122
-
123
- if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
124
- {
125
- register int key = hash (str, len);
126
-
127
- if (key <= MAX_HASH_VALUE && key >= 0)
128
- {
129
- register const char *s = wordlist[key].name;
130
-
131
- if (*str == *s && !strcmp (str + 1, s + 1))
132
- return &wordlist[key];
133
- }
134
- }
135
- return 0;
136
- }
@@ -1,41 +0,0 @@
1
- #ifndef MEL_LOCALSTATE_HPP
2
- #define MEL_LOCALSTATE_HPP
3
-
4
- #include "var_table.hpp"
5
-
6
- namespace MELBOURNE {
7
- struct LocalState {
8
- LocalState* prev;
9
- var_table local_vars;
10
- var_table block_vars;
11
-
12
- LocalState(LocalState* prev)
13
- : prev(prev)
14
- , local_vars(var_table_create())
15
- , block_vars(0)
16
- {}
17
-
18
- ~LocalState() {
19
- var_table_destroy(local_vars);
20
- if(block_vars) {
21
- var_table_destroy(block_vars);
22
- }
23
- }
24
-
25
- bool blocks_p() {
26
- return block_vars != NULL;
27
- }
28
-
29
- static LocalState* push(LocalState* cur) {
30
- return new LocalState(cur);
31
- }
32
-
33
- static LocalState* pop(LocalState* cur) {
34
- LocalState* tmp = cur->prev;
35
- delete cur;
36
- return tmp;
37
- }
38
- };
39
- };
40
-
41
- #endif
@@ -1,43 +0,0 @@
1
- #include "namespace.h"
2
- #include "quark.hpp"
3
- #include "parser_state.hpp"
4
-
5
- #include <string.h>
6
- #include <stdlib.h>
7
-
8
- using namespace MELBOURNE;
9
-
10
- quark MELBOURNE::quark_from_string(rb_parser_state* parser_state, const char* str) {
11
- if (str == NULL) {
12
- return QUARK_NOT_FOUND;
13
- }
14
-
15
- /* attempt to find it in our cache */
16
- quark_map::iterator it = quark_indexes->find(str);
17
- if (it != quark_indexes->end()) {
18
- return it->second;
19
- }
20
-
21
- /* otherwise, we need to duplicate and store the string */
22
- const char* new_quark = strdup(str);
23
- quarks->push_back(new_quark);
24
- size_t index = quarks->size() - 1;
25
- quark_indexes->insert(quark_map::value_type(new_quark,index));
26
- return index;
27
- }
28
-
29
- const char* MELBOURNE::quark_to_string(rb_parser_state* parser_state, quark q) {
30
- if (q >= quarks->size())
31
- return NULL;
32
- return quarks->at(q);
33
- }
34
-
35
- void MELBOURNE::quark_cleanup(rb_parser_state* parser_state) {
36
- delete quark_indexes;
37
-
38
- for (quark_vector::iterator it = quarks->begin(); it != quarks->end(); ++it) {
39
- free((char *)*it);
40
- }
41
-
42
- delete quarks;
43
- }