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.
- data/LICENSE +25 -0
- data/README.md +69 -0
- data/Rakefile +14 -0
- data/ext/melbourne/.gitignore +3 -0
- data/ext/melbourne/bstring-license.txt +29 -0
- data/ext/melbourne/bstrlib.c +2687 -0
- data/ext/melbourne/bstrlib.h +267 -0
- data/ext/melbourne/encoding_compat.cpp +188 -0
- data/ext/melbourne/encoding_compat.hpp +57 -0
- data/ext/melbourne/extconf.rb +87 -0
- data/ext/melbourne/grammar18.cpp +11280 -0
- data/ext/melbourne/grammar18.hpp +13 -0
- data/ext/melbourne/grammar18.y +6088 -0
- data/ext/melbourne/grammar19.cpp +12420 -0
- data/ext/melbourne/grammar19.hpp +11 -0
- data/ext/melbourne/grammar19.y +7113 -0
- data/ext/melbourne/lex.c.blt +152 -0
- data/ext/melbourne/lex.c.tab +136 -0
- data/ext/melbourne/local_state.hpp +43 -0
- data/ext/melbourne/melbourne.cpp +88 -0
- data/ext/melbourne/melbourne.hpp +19 -0
- data/ext/melbourne/node18.hpp +262 -0
- data/ext/melbourne/node19.hpp +271 -0
- data/ext/melbourne/node_types.rb +304 -0
- data/ext/melbourne/node_types18.cpp +255 -0
- data/ext/melbourne/node_types18.hpp +129 -0
- data/ext/melbourne/node_types19.cpp +249 -0
- data/ext/melbourne/node_types19.hpp +126 -0
- data/ext/melbourne/parser_state18.hpp +181 -0
- data/ext/melbourne/parser_state19.hpp +251 -0
- data/ext/melbourne/quark.cpp +42 -0
- data/ext/melbourne/quark.hpp +45 -0
- data/ext/melbourne/symbols.cpp +224 -0
- data/ext/melbourne/symbols.hpp +119 -0
- data/ext/melbourne/var_table18.cpp +83 -0
- data/ext/melbourne/var_table18.hpp +33 -0
- data/ext/melbourne/var_table19.cpp +65 -0
- data/ext/melbourne/var_table19.hpp +35 -0
- data/ext/melbourne/visitor18.cpp +963 -0
- data/ext/melbourne/visitor18.hpp +12 -0
- data/ext/melbourne/visitor19.cpp +960 -0
- data/ext/melbourne/visitor19.hpp +15 -0
- data/lib/compiler/ast/constants.rb +81 -0
- data/lib/compiler/ast/control_flow.rb +290 -0
- data/lib/compiler/ast/data.rb +14 -0
- data/lib/compiler/ast/definitions.rb +749 -0
- data/lib/compiler/ast/encoding.rb +18 -0
- data/lib/compiler/ast/exceptions.rb +138 -0
- data/lib/compiler/ast/file.rb +11 -0
- data/lib/compiler/ast/grapher.rb +89 -0
- data/lib/compiler/ast/literals.rb +207 -0
- data/lib/compiler/ast/node.rb +362 -0
- data/lib/compiler/ast/operators.rb +106 -0
- data/lib/compiler/ast/self.rb +15 -0
- data/lib/compiler/ast/sends.rb +615 -0
- data/lib/compiler/ast/transforms.rb +298 -0
- data/lib/compiler/ast/values.rb +88 -0
- data/lib/compiler/ast/variables.rb +351 -0
- data/lib/compiler/ast.rb +20 -0
- data/lib/compiler/locals.rb +109 -0
- data/lib/melbourne/processor.rb +651 -0
- data/lib/melbourne/version.rb +3 -0
- data/lib/melbourne.rb +143 -0
- metadata +112 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
#include <vector>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <assert.h>
|
4
|
+
|
5
|
+
#include "melbourne.hpp"
|
6
|
+
#include "var_table18.hpp"
|
7
|
+
|
8
|
+
namespace melbourne {
|
9
|
+
|
10
|
+
namespace grammar18 {
|
11
|
+
|
12
|
+
struct var_table_t {
|
13
|
+
struct var_table_t *next;
|
14
|
+
std::vector<quark> *quarks;
|
15
|
+
};
|
16
|
+
|
17
|
+
var_table var_table_create() {
|
18
|
+
var_table vt = ALLOC(struct var_table_t);
|
19
|
+
vt->quarks = new std::vector<quark>();
|
20
|
+
vt->next = NULL;
|
21
|
+
return vt;
|
22
|
+
}
|
23
|
+
|
24
|
+
void var_table_destroy(var_table vt) {
|
25
|
+
while (vt) {
|
26
|
+
var_table cur = vt;
|
27
|
+
delete cur->quarks;
|
28
|
+
vt = vt->next;
|
29
|
+
free(cur);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
var_table var_table_push(var_table cur) {
|
34
|
+
var_table vt = var_table_create();
|
35
|
+
vt->next = cur;
|
36
|
+
return vt;
|
37
|
+
}
|
38
|
+
|
39
|
+
var_table var_table_pop(var_table cur) {
|
40
|
+
var_table nw = NULL;
|
41
|
+
|
42
|
+
if(cur) {
|
43
|
+
delete cur->quarks;
|
44
|
+
nw = cur->next;
|
45
|
+
free(cur);
|
46
|
+
}
|
47
|
+
return nw;
|
48
|
+
}
|
49
|
+
|
50
|
+
int var_table_find(const var_table tbl, const quark needle) {
|
51
|
+
for(size_t i = 0; i < tbl->quarks->size(); i++) {
|
52
|
+
if(tbl->quarks->at(i) == needle) return (int)i;
|
53
|
+
}
|
54
|
+
return -1;
|
55
|
+
}
|
56
|
+
|
57
|
+
int var_table_find_chained(const var_table tbl, const quark needle) {
|
58
|
+
for(size_t i = 0; i < tbl->quarks->size(); i++) {
|
59
|
+
if(tbl->quarks->at(i) == needle) return (int)i;
|
60
|
+
}
|
61
|
+
|
62
|
+
if(tbl->next) {
|
63
|
+
return var_table_find_chained(tbl->next, needle);
|
64
|
+
}
|
65
|
+
return -1;
|
66
|
+
}
|
67
|
+
|
68
|
+
int var_table_add(var_table tbl, const quark item) {
|
69
|
+
tbl->quarks->push_back(item);
|
70
|
+
return (int)tbl->quarks->size();
|
71
|
+
}
|
72
|
+
|
73
|
+
int var_table_size(const var_table tbl)
|
74
|
+
{
|
75
|
+
return (int)tbl->quarks->size();
|
76
|
+
}
|
77
|
+
|
78
|
+
quark var_table_get(const var_table tbl, const int index)
|
79
|
+
{
|
80
|
+
return tbl->quarks->at(index);
|
81
|
+
}
|
82
|
+
};
|
83
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#ifndef MEL_VAR_TABLE18_HPP
|
2
|
+
#define MEL_VAR_TABLE18_HPP
|
3
|
+
|
4
|
+
#include "quark.hpp"
|
5
|
+
|
6
|
+
#ifdef __cplusplus
|
7
|
+
extern "C" {
|
8
|
+
#endif
|
9
|
+
|
10
|
+
|
11
|
+
namespace melbourne {
|
12
|
+
namespace grammar18 {
|
13
|
+
struct var_table_t;
|
14
|
+
typedef struct var_table_t *var_table;
|
15
|
+
|
16
|
+
var_table var_table_create();
|
17
|
+
void var_table_destroy(var_table vt);
|
18
|
+
var_table var_table_push(var_table cur);
|
19
|
+
var_table var_table_pop(var_table cur);
|
20
|
+
int var_table_find(const var_table tbl, const quark needle);
|
21
|
+
int var_table_find_chained(const var_table tbl, const quark needle);
|
22
|
+
|
23
|
+
int var_table_add(var_table tbl, const quark item);
|
24
|
+
int var_table_size(const var_table tbl);
|
25
|
+
quark var_table_get(const var_table tbl, const int index);
|
26
|
+
};
|
27
|
+
};
|
28
|
+
|
29
|
+
#ifdef __cplusplus
|
30
|
+
} /* extern "C" { */
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#endif
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#include "melbourne.hpp"
|
2
|
+
#include "var_table19.hpp"
|
3
|
+
|
4
|
+
namespace melbourne {
|
5
|
+
namespace grammar19 {
|
6
|
+
int vtable_size(const struct vtable* tbl) {
|
7
|
+
if(tbl) {
|
8
|
+
return tbl->pos;
|
9
|
+
} else {
|
10
|
+
return 0;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
struct vtable* vtable_alloc(struct vtable *prev) {
|
15
|
+
struct vtable *tbl = ALLOC(struct vtable);
|
16
|
+
tbl->pos = 0;
|
17
|
+
tbl->capa = 8;
|
18
|
+
tbl->tbl = ALLOC_N(ID, tbl->capa);
|
19
|
+
tbl->prev = prev;
|
20
|
+
return tbl;
|
21
|
+
}
|
22
|
+
|
23
|
+
void vtable_free(struct vtable* tbl) {
|
24
|
+
if(tbl) {
|
25
|
+
if(tbl->tbl) {
|
26
|
+
xfree(tbl->tbl);
|
27
|
+
}
|
28
|
+
xfree(tbl);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
void vtable_add(struct vtable* tbl, ID id) {
|
33
|
+
if(!tbl) {
|
34
|
+
rb_bug("vtable_add: vtable is not allocated (%p)", (void *)tbl);
|
35
|
+
}
|
36
|
+
|
37
|
+
if(tbl->pos == tbl->capa) {
|
38
|
+
tbl->capa = tbl->capa * 2;
|
39
|
+
REALLOC_N(tbl->tbl, ID, tbl->capa);
|
40
|
+
}
|
41
|
+
tbl->tbl[tbl->pos++] = id;
|
42
|
+
}
|
43
|
+
|
44
|
+
bool vtable_included(const struct vtable* tbl, ID id) {
|
45
|
+
if(tbl) {
|
46
|
+
for(int i = 0; i < tbl->pos; i++) {
|
47
|
+
if(tbl->tbl[i] == id) {
|
48
|
+
return true;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
return false;
|
53
|
+
}
|
54
|
+
|
55
|
+
void local_vars_free(struct local_vars* vars) {
|
56
|
+
struct local_vars* prev;
|
57
|
+
for(struct local_vars* local = vars; local; local = prev) {
|
58
|
+
if(local->args) xfree(local->args);
|
59
|
+
if(local->vars) xfree(local->vars);
|
60
|
+
prev = local->prev;
|
61
|
+
xfree(local);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
};
|
65
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#ifndef MEL_VAR_TABLE19_HPP
|
2
|
+
#define MEL_VAR_TABLE19_HPP
|
3
|
+
|
4
|
+
// We must use MRI's xfree for ALLOC'd memory.
|
5
|
+
#ifdef RUBINIUS
|
6
|
+
#undef xfree
|
7
|
+
#define xfree free
|
8
|
+
#endif
|
9
|
+
|
10
|
+
namespace melbourne {
|
11
|
+
namespace grammar19 {
|
12
|
+
struct vtable {
|
13
|
+
ID *tbl;
|
14
|
+
int pos;
|
15
|
+
int capa;
|
16
|
+
struct vtable *prev;
|
17
|
+
};
|
18
|
+
|
19
|
+
struct local_vars {
|
20
|
+
struct vtable *args;
|
21
|
+
struct vtable *vars;
|
22
|
+
struct local_vars *prev;
|
23
|
+
};
|
24
|
+
|
25
|
+
int vtable_size(const struct vtable* tbl);
|
26
|
+
struct vtable* vtable_alloc(struct vtable *prev);
|
27
|
+
void vtable_free(struct vtable* tbl);
|
28
|
+
void vtable_add(struct vtable* tbl, ID id);
|
29
|
+
bool vtable_included(const struct vtable* tbl, ID id);
|
30
|
+
|
31
|
+
void local_vars_free(struct local_vars* vars);
|
32
|
+
};
|
33
|
+
};
|
34
|
+
|
35
|
+
#endif
|