mutant-melbourne 2.0.1

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 (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,152 @@
1
+ /* C code produced by gperf version 3.0.4 */
2
+ /* Command-line: gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' defs/keywords */
3
+
4
+ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
5
+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
6
+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
7
+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
8
+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
9
+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
10
+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
11
+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
12
+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
13
+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
14
+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
15
+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
16
+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
17
+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
18
+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
19
+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
20
+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
21
+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
22
+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
23
+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
24
+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
25
+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
26
+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
27
+ /* The character set is not based on ISO-646. */
28
+ error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
29
+ #endif
30
+
31
+ struct kwtable {const char *name; int id[2]; enum lex_state_e state;};
32
+ const struct kwtable *rb_reserved_word(const char *, unsigned int);
33
+ static const struct kwtable *reserved_word(const char *, unsigned int);
34
+ #define rb_reserved_word(str, len) reserved_word(str, len)
35
+ struct kwtable;
36
+
37
+ #define TOTAL_KEYWORDS 41
38
+ #define MIN_WORD_LENGTH 2
39
+ #define MAX_WORD_LENGTH 12
40
+ #define MIN_HASH_VALUE 8
41
+ #define MAX_HASH_VALUE 50
42
+ /* maximum key range = 43, duplicates = 0 */
43
+
44
+ static inline unsigned int hash(register const char* str, register unsigned int len)
45
+ {
46
+ static const unsigned char asso_values[] =
47
+ {
48
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
49
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
50
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
51
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
52
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
53
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
54
+ 51, 51, 51, 26, 51, 51, 14, 51, 16, 8,
55
+ 11, 13, 51, 51, 51, 51, 10, 51, 13, 51,
56
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
57
+ 51, 51, 51, 51, 51, 11, 51, 13, 1, 26,
58
+ 4, 1, 8, 28, 51, 23, 51, 1, 1, 27,
59
+ 5, 19, 21, 51, 8, 3, 3, 11, 51, 21,
60
+ 24, 16, 51, 51, 51, 51, 51, 51, 51, 51,
61
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
62
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
63
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
64
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
65
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
66
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
67
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
68
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
69
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
70
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
71
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
72
+ 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
73
+ 51, 51, 51, 51, 51, 51
74
+ };
75
+ register int hval = len;
76
+
77
+ switch (hval)
78
+ {
79
+ default:
80
+ hval += asso_values[(unsigned char)str[2]];
81
+ /*FALLTHROUGH*/
82
+ case 2:
83
+ case 1:
84
+ hval += asso_values[(unsigned char)str[0]];
85
+ break;
86
+ }
87
+ return hval + asso_values[(unsigned char)str[len - 1]];
88
+ }
89
+
90
+ const struct kwtable* rb_reserved_word(register const char* str, register unsigned int len)
91
+ {
92
+ static const struct kwtable wordlist[] =
93
+ {
94
+ {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
95
+ {"break", {keyword_break, keyword_break}, EXPR_MID},
96
+ {"else", {keyword_else, keyword_else}, EXPR_BEG},
97
+ {"nil", {keyword_nil, keyword_nil}, EXPR_END},
98
+ {"ensure", {keyword_ensure, keyword_ensure}, EXPR_BEG},
99
+ {"end", {keyword_end, keyword_end}, EXPR_END},
100
+ {"then", {keyword_then, keyword_then}, EXPR_BEG},
101
+ {"not", {keyword_not, keyword_not}, EXPR_ARG},
102
+ {"false", {keyword_false, keyword_false}, EXPR_END},
103
+ {"self", {keyword_self, keyword_self}, EXPR_END},
104
+ {"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
105
+ {"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
106
+ {"true", {keyword_true, keyword_true}, EXPR_END},
107
+ {"until", {keyword_until, modifier_until}, EXPR_VALUE},
108
+ {"unless", {keyword_unless, modifier_unless}, EXPR_VALUE},
109
+ {"return", {keyword_return, keyword_return}, EXPR_MID},
110
+ {"def", {keyword_def, keyword_def}, EXPR_FNAME},
111
+ {"and", {keyword_and, keyword_and}, EXPR_VALUE},
112
+ {"do", {keyword_do, keyword_do}, EXPR_BEG},
113
+ {"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
114
+ {"for", {keyword_for, keyword_for}, EXPR_VALUE},
115
+ {"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
116
+ {"or", {keyword_or, keyword_or}, EXPR_VALUE},
117
+ {"in", {keyword_in, keyword_in}, EXPR_VALUE},
118
+ {"when", {keyword_when, keyword_when}, EXPR_VALUE},
119
+ {"retry", {keyword_retry, keyword_retry}, EXPR_END},
120
+ {"if", {keyword_if, modifier_if}, EXPR_VALUE},
121
+ {"case", {keyword_case, keyword_case}, EXPR_VALUE},
122
+ {"redo", {keyword_redo, keyword_redo}, EXPR_END},
123
+ {"next", {keyword_next, keyword_next}, EXPR_MID},
124
+ {"super", {keyword_super, keyword_super}, EXPR_ARG},
125
+ {"module", {keyword_module, keyword_module}, EXPR_VALUE},
126
+ {"begin", {keyword_begin, keyword_begin}, EXPR_BEG},
127
+ {"__LINE__", {keyword__LINE__, keyword__LINE__}, EXPR_END},
128
+ {"__FILE__", {keyword__FILE__, keyword__FILE__}, EXPR_END},
129
+ {"__ENCODING__", {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END},
130
+ {"END", {keyword_END, keyword_END}, EXPR_END},
131
+ {"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
132
+ {"BEGIN", {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
133
+ {"defined?", {keyword_defined, keyword_defined}, EXPR_ARG},
134
+ {"class", {keyword_class, keyword_class}, EXPR_CLASS},
135
+ {""}, {""},
136
+ {"while", {keyword_while, modifier_while}, EXPR_VALUE}
137
+ };
138
+
139
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
140
+ {
141
+ register int key = hash(str, len);
142
+
143
+ if(key <= MAX_HASH_VALUE && key >= 0)
144
+ {
145
+ register const char *s = wordlist[key].name;
146
+
147
+ if(*str == *s && !strcmp(str + 1, s + 1))
148
+ return &wordlist[key];
149
+ }
150
+ }
151
+ return 0;
152
+ }
@@ -0,0 +1,136 @@
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
+ }
@@ -0,0 +1,43 @@
1
+ #ifndef MEL_LOCALSTATE_HPP
2
+ #define MEL_LOCALSTATE_HPP
3
+
4
+ #include "var_table18.hpp"
5
+
6
+ namespace melbourne {
7
+ namespace grammar18 {
8
+ struct LocalState {
9
+ LocalState* prev;
10
+ var_table local_vars;
11
+ var_table block_vars;
12
+
13
+ LocalState(LocalState* prev)
14
+ : prev(prev)
15
+ , local_vars(var_table_create())
16
+ , block_vars(0)
17
+ {}
18
+
19
+ ~LocalState() {
20
+ var_table_destroy(local_vars);
21
+ if(block_vars) {
22
+ var_table_destroy(block_vars);
23
+ }
24
+ }
25
+
26
+ bool blocks_p() {
27
+ return block_vars != NULL;
28
+ }
29
+
30
+ static LocalState* push(LocalState* cur) {
31
+ return new LocalState(cur);
32
+ }
33
+
34
+ static LocalState* pop(LocalState* cur) {
35
+ LocalState* tmp = cur->prev;
36
+ delete cur;
37
+ return tmp;
38
+ }
39
+ };
40
+ };
41
+ };
42
+
43
+ #endif
@@ -0,0 +1,88 @@
1
+ /* We are well-behaved citizens of the C-extension State
2
+ * so we let the C-API know this so it will not penalize
3
+ * us with unnecessary caching.
4
+ */
5
+
6
+ #include "melbourne.hpp"
7
+ #include "grammar18.hpp"
8
+ #include "grammar19.hpp"
9
+ #include "symbols.hpp"
10
+
11
+ #ifdef __cplusplus
12
+ extern "C" {
13
+ #endif
14
+
15
+ VALUE melbourne18_string_to_ast(VALUE self, VALUE source, VALUE name, VALUE line) {
16
+ StringValue(source);
17
+ StringValue(name);
18
+ bstring b_str = blk2bstr(RSTRING_PTR(source), (int)RSTRING_LEN(source));
19
+ VALUE result = melbourne::grammar18::string_to_ast(self,
20
+ RSTRING_PTR(name), b_str, FIX2INT(line));
21
+ bdestroy(b_str);
22
+
23
+ return result;
24
+ }
25
+
26
+ VALUE melbourne18_file_to_ast(VALUE self, VALUE fname, VALUE start) {
27
+ StringValue(fname);
28
+
29
+ char* c_name = RSTRING_PTR(fname);
30
+
31
+ FILE *file = fopen(c_name, "r");
32
+ if(file) {
33
+ VALUE result = melbourne::grammar18::file_to_ast(self,
34
+ RSTRING_PTR(fname), file, FIX2INT(start));
35
+ fclose(file);
36
+
37
+ return result;
38
+ } else {
39
+ rb_raise(rb_eLoadError, "%s -- %s", strerror(errno), c_name);
40
+ }
41
+ }
42
+
43
+ VALUE melbourne19_string_to_ast(VALUE self, VALUE source, VALUE name, VALUE line) {
44
+ StringValue(source);
45
+ StringValue(name);
46
+ VALUE result = melbourne::grammar19::string_to_ast(self, name, source, line);
47
+
48
+ return result;
49
+ }
50
+
51
+ VALUE melbourne19_file_to_ast(VALUE self, VALUE fname, VALUE start) {
52
+ StringValue(fname);
53
+
54
+ int fd = open(RSTRING_PTR(fname), O_RDONLY);
55
+ if(fd != -1) {
56
+ VALUE result = melbourne::grammar19::file_to_ast(self,
57
+ RSTRING_PTR(fname), fd, FIX2INT(start));
58
+ close(fd);
59
+
60
+ return result;
61
+ } else {
62
+ rb_raise(rb_eLoadError, "no such file to load -- %s", RSTRING_PTR(fname));
63
+ }
64
+ }
65
+
66
+ void Init_melbourne(void) {
67
+ VALUE rb_cMelbourne;
68
+
69
+ melbourne::init_symbols20();
70
+
71
+ #ifndef RUBINIUS
72
+ VALUE rb_mRubinius = rb_const_get(rb_cObject, rb_intern("Rubinius"));
73
+ #endif
74
+
75
+ rb_cMelbourne = rb_define_class_under(rb_mRubinius, "Melbourne", rb_cObject);
76
+ rb_define_method(rb_cMelbourne, "string_to_ast_18",
77
+ RUBY_METHOD_FUNC(melbourne18_string_to_ast), 3);
78
+ rb_define_method(rb_cMelbourne, "file_to_ast_18",
79
+ RUBY_METHOD_FUNC(melbourne18_file_to_ast), 2);
80
+ rb_define_method(rb_cMelbourne, "string_to_ast_19",
81
+ RUBY_METHOD_FUNC(melbourne19_string_to_ast), 3);
82
+ rb_define_method(rb_cMelbourne, "file_to_ast_19",
83
+ RUBY_METHOD_FUNC(melbourne19_file_to_ast), 2);
84
+ }
85
+
86
+ #ifdef __cplusplus
87
+ } /* extern "C" { */
88
+ #endif
@@ -0,0 +1,19 @@
1
+ #include <stdio.h>
2
+ #include <errno.h>
3
+ #include <ctype.h>
4
+ #include <string.h>
5
+ #include <strings.h>
6
+ #include <stdbool.h>
7
+ #include <stdint.h>
8
+ #include <assert.h>
9
+ #include <stdlib.h>
10
+ #include <unistd.h>
11
+ #include <fcntl.h>
12
+ #include <sys/types.h>
13
+ #ifdef HAVE_ALLOCA_H
14
+ #include <alloca.h>
15
+ #endif
16
+
17
+ #define RSTRING_NOT_MODIFIED 1
18
+
19
+ #include "ruby.h"