konpeito 0.2.3 → 0.2.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/lib/konpeito/codegen/cruby_backend.rb +7 -0
- data/lib/konpeito/codegen/jvm_generator.rb +160 -40
- data/lib/konpeito/codegen/llvm_generator.rb +236 -58
- data/lib/konpeito/hir/builder.rb +61 -27
- data/lib/konpeito/hir/nodes.rb +2 -0
- data/lib/konpeito/version.rb +1 -1
- data/tools/konpeito-asm/build.sh +1 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KHash.java +12 -0
- data/tools/konpeito-asm/src/konpeito/runtime/KMatchData.java +50 -1
- data/tools/konpeito-asm/src/konpeito/runtime/RubyDispatch.java +721 -8
- metadata +1 -20
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KArray.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KCompression.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KConditionVariable.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KCrypto.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KFiber.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KFile.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KHTTP.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KHash.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KJSON$Parser.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KJSON.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KMatchData.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KMath.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KRactor.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KRactorPort.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KRubyException.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KSizedQueue.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KThread.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KTime.class +0 -0
- data/tools/konpeito-asm/runtime-classes/konpeito/runtime/RubyDispatch.class +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
package konpeito.runtime;
|
|
2
2
|
|
|
3
|
+
import java.util.Map;
|
|
4
|
+
import java.util.LinkedHashMap;
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* KMatchData - Ruby MatchData implementation for JVM backend.
|
|
5
8
|
*
|
|
@@ -8,18 +11,46 @@ package konpeito.runtime;
|
|
|
8
11
|
public class KMatchData {
|
|
9
12
|
private final KArray<String> groups;
|
|
10
13
|
private final String inputString;
|
|
14
|
+
private final int matchStart;
|
|
15
|
+
private final int matchEnd;
|
|
16
|
+
private final Map<String, String> namedGroups;
|
|
11
17
|
|
|
12
18
|
public KMatchData(KArray<String> groups, String inputString) {
|
|
13
19
|
this.groups = groups;
|
|
14
20
|
this.inputString = inputString;
|
|
21
|
+
this.matchStart = 0;
|
|
22
|
+
this.matchEnd = groups.isEmpty() ? 0 : (groups.get(0) != null ? groups.get(0).length() : 0);
|
|
23
|
+
this.namedGroups = new LinkedHashMap<>();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public KMatchData(KArray<String> groups, String inputString, int matchStart, int matchEnd) {
|
|
27
|
+
this.groups = groups;
|
|
28
|
+
this.inputString = inputString;
|
|
29
|
+
this.matchStart = matchStart;
|
|
30
|
+
this.matchEnd = matchEnd;
|
|
31
|
+
this.namedGroups = new LinkedHashMap<>();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public KMatchData(KArray<String> groups, String inputString, int matchStart, int matchEnd, Map<String, String> namedGroups) {
|
|
35
|
+
this.groups = groups;
|
|
36
|
+
this.inputString = inputString;
|
|
37
|
+
this.matchStart = matchStart;
|
|
38
|
+
this.matchEnd = matchEnd;
|
|
39
|
+
this.namedGroups = namedGroups != null ? namedGroups : new LinkedHashMap<>();
|
|
15
40
|
}
|
|
16
41
|
|
|
17
42
|
/** MatchData#[](index) — returns the nth match group (0 = full match) */
|
|
18
43
|
public Object get(int index) {
|
|
44
|
+
if (index < 0) index = groups.size() + index;
|
|
19
45
|
if (index < 0 || index >= groups.size()) return null;
|
|
20
46
|
return groups.get(index);
|
|
21
47
|
}
|
|
22
48
|
|
|
49
|
+
/** MatchData#[](name) — returns a named capture group */
|
|
50
|
+
public Object getByName(String name) {
|
|
51
|
+
return namedGroups.get(name);
|
|
52
|
+
}
|
|
53
|
+
|
|
23
54
|
/** MatchData#to_s — returns the entire matched string (group 0) */
|
|
24
55
|
public String toString() {
|
|
25
56
|
if (groups.isEmpty()) return "";
|
|
@@ -46,7 +77,25 @@ public class KMatchData {
|
|
|
46
77
|
}
|
|
47
78
|
|
|
48
79
|
/** MatchData#pre_match — returns the string before the match */
|
|
49
|
-
|
|
80
|
+
public String pre_match() {
|
|
81
|
+
if (matchStart <= 0) return "";
|
|
82
|
+
return inputString.substring(0, matchStart);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** MatchData#post_match — returns the string after the match */
|
|
86
|
+
public String post_match() {
|
|
87
|
+
if (matchEnd >= inputString.length()) return "";
|
|
88
|
+
return inputString.substring(matchEnd);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** MatchData#named_captures — returns a Hash of named captures */
|
|
92
|
+
public KHash<Object, Object> named_captures() {
|
|
93
|
+
KHash<Object, Object> result = new KHash<>();
|
|
94
|
+
for (Map.Entry<String, String> entry : namedGroups.entrySet()) {
|
|
95
|
+
result.put(entry.getKey(), entry.getValue());
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
50
99
|
|
|
51
100
|
/** MatchData#class */
|
|
52
101
|
public String k_class() {
|