Skip to content

Commit 097d396

Browse files
committed
longlit5 for the vm of indonesian beverages
1 parent 6506e8c commit 097d396

File tree

2 files changed

+60
-20
lines changed

2 files changed

+60
-20
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,8 @@ public static String cwd() {
833833
}
834834

835835
public static String chdir(String path, ThreadContext tc) {
836-
die_s("chdir is not available on JVM", tc);
837-
return null;
836+
die_s("chdir is not available on JVM", tc);
837+
return null;
838838
}
839839

840840
public static long mkdir(String path, long mode, ThreadContext tc) {
@@ -919,7 +919,7 @@ public static String gethostname(){
919919

920920
// To be removed once shell3 is adopted
921921
public static long shell1(String cmd, ThreadContext tc) {
922-
return shell3(cmd, cwd(), getenvhash(tc), tc);
922+
return shell3(cmd, cwd(), getenvhash(tc), tc);
923923
}
924924

925925
public static long shell3(String cmd, String dir, SixModelObject envObj, ThreadContext tc) {
@@ -3098,8 +3098,8 @@ public static String concat(String valA, String valB) {
30983098
}
30993099

31003100
public static String chr(long ord, ThreadContext tc) {
3101-
if (ord < 0)
3102-
throw ExceptionHandling.dieInternal(tc, "chr codepoint cannot be negative");
3101+
if (ord < 0)
3102+
throw ExceptionHandling.dieInternal(tc, "chr codepoint cannot be negative");
31033103

31043104
return (new StringBuffer()).append(Character.toChars((int)ord)).toString();
31053105
}
@@ -4855,8 +4855,9 @@ public static SixModelObject nfafromstatelist(SixModelObject states, SixModelObj
48554855
nfa.states[i][curEdge].act = act;
48564856
nfa.states[i][curEdge].to = to;
48574857

4858-
switch (act) {
4858+
switch (act & 0xff) {
48594859
case NFA.EDGE_FATE:
4860+
case NFA.EDGE_CODEPOINT_LL:
48604861
case NFA.EDGE_CODEPOINT:
48614862
case NFA.EDGE_CODEPOINT_NEG:
48624863
case NFA.EDGE_CHARCLASS:
@@ -4867,6 +4868,7 @@ public static SixModelObject nfafromstatelist(SixModelObject states, SixModelObj
48674868
case NFA.EDGE_CHARLIST_NEG:
48684869
nfa.states[i][curEdge].arg_s = edgeInfo.at_pos_boxed(tc, j + 1).get_str(tc);
48694870
break;
4871+
case NFA.EDGE_CODEPOINT_I_LL:
48704872
case NFA.EDGE_CODEPOINT_I:
48714873
case NFA.EDGE_CODEPOINT_I_NEG:
48724874
case NFA.EDGE_CHARRANGE:
@@ -4930,6 +4932,7 @@ private static int[] runNFA(ThreadContext tc, NFAInstance nfa, String target, lo
49304932
/* Allocate a "done states" array. */
49314933
int numStates = nfa.numStates;
49324934
int[] done = new int[numStates + 1];
4935+
long orig_pos = pos;
49334936

49344937
/* Clear out other re-used arrays. */
49354938
ArrayList<Integer> fates = tc.fates;
@@ -4939,6 +4942,11 @@ private static int[] runNFA(ThreadContext tc, NFAInstance nfa, String target, lo
49394942
nextst.clear();
49404943
fates.clear();
49414944

4945+
/* XXX needs to be cached, but tc breaks stage0 when I try */
4946+
long[] longlit = new long[200]; // also needs proper sizing to # of alternatives
4947+
for (int i = 0; i < 200; i++)
4948+
longlit[i] = 0;
4949+
49424950
nextst.add(1);
49434951
while (!nextst.isEmpty() && pos <= eos) {
49444952
/* Translation of:
@@ -4968,11 +4976,15 @@ private static int[] runNFA(ThreadContext tc, NFAInstance nfa, String target, lo
49684976
int act = edgeInfo[i].act;
49694977
int to = edgeInfo[i].to;
49704978

4971-
if (act == NFA.EDGE_FATE) {
4979+
if (act < 0) {
4980+
act &= 0xff;
4981+
}
4982+
else if (act == NFA.EDGE_FATE) {
49724983
/* Crossed a fate edge. Check if we already saw this, and
49734984
* if so bump the entry we already saw. */
49744985
int arg = edgeInfo[i].arg_i;
49754986
boolean foundFate = false;
4987+
arg &= 0xffffff;
49764988
for (int j = 0; j < fates.size(); j++) {
49774989
if (foundFate)
49784990
fates.set(j - 1, fates.get(j));
@@ -4982,22 +4994,34 @@ private static int[] runNFA(ThreadContext tc, NFAInstance nfa, String target, lo
49824994
prevFates--;
49834995
}
49844996
}
4997+
arg -= longlit[arg] << 24;
49854998
if (foundFate)
49864999
fates.set(fates.size() - 1, arg);
49875000
else
49885001
fates.add(arg);
5002+
continue;
49895003
}
49905004
else if (act == NFA.EDGE_EPSILON && to <= numStates && done[to] != gen) {
49915005
curst.add(to);
5006+
continue;
49925007
}
4993-
else if (pos >= eos) {
5008+
5009+
if (pos >= eos) {
49945010
/* Can't match, so drop state. */
49955011
}
49965012
else if (act == NFA.EDGE_CODEPOINT) {
49975013
char arg = (char)edgeInfo[i].arg_i;
49985014
if (target.charAt((int)pos) == arg)
49995015
nextst.add(to);
50005016
}
5017+
else if (act == NFA.EDGE_CODEPOINT_LL) {
5018+
int fate = (edgeInfo[i].act >> 8) & 0xfffff; /* act is probably signed 32 bits */
5019+
char arg = (char)edgeInfo[i].arg_i;
5020+
if (target.charAt((int)pos) == arg) {
5021+
nextst.add(to);
5022+
longlit[fate] = pos - orig_pos;
5023+
}
5024+
}
50015025
else if (act == NFA.EDGE_CODEPOINT_NEG) {
50025026
char arg = (char)edgeInfo[i].arg_i;
50035027
if (target.charAt((int)pos) != arg)
@@ -5028,6 +5052,16 @@ else if (act == NFA.EDGE_CODEPOINT_I) {
50285052
if (ord == lc_arg || ord == uc_arg)
50295053
nextst.add(to);
50305054
}
5055+
else if (act == NFA.EDGE_CODEPOINT_I_LL) {
5056+
int fate = (edgeInfo[i].act >> 8) & 0xfffff; /* act is probably signed 32 bits */
5057+
char uc_arg = edgeInfo[i].arg_uc;
5058+
char lc_arg = edgeInfo[i].arg_lc;
5059+
char ord = target.charAt((int)pos);
5060+
if (ord == lc_arg || ord == uc_arg) {
5061+
nextst.add(to);
5062+
longlit[fate] = pos - orig_pos;
5063+
}
5064+
}
50315065
else if (act == NFA.EDGE_CODEPOINT_I_NEG) {
50325066
char uc_arg = edgeInfo[i].arg_uc;
50335067
char lc_arg = edgeInfo[i].arg_lc;
@@ -5066,7 +5100,7 @@ else if (act == NFA.EDGE_CHARRANGE_NEG) {
50665100
}
50675101
}
50685102

5069-
/* strip any literal lengths, leaving only fates */
5103+
/* strip any literal lengths, leaving only fates */
50705104
int[] result = new int[fates.size()];
50715105
for (int i = 0; i < fates.size(); i++)
50725106
result[i] = fates.get(i) & 0xffffff;
@@ -5332,7 +5366,7 @@ public static long isprime_I(SixModelObject a, long certainty, ThreadContext tc)
53325366
BigInteger bi = getBI(tc, a);
53335367
if (bi.compareTo(BigInteger.valueOf(1)) <= 0) {
53345368
return 0;
5335-
}
5369+
}
53365370
return bi.isProbablePrime((int)certainty) ? 1 : 0;
53375371
}
53385372

@@ -5695,14 +5729,14 @@ public static SixModelObject jvmgetconfig(ThreadContext tc) {
56955729
SixModelObject res = hashType.st.REPR.allocate(tc, hashType.st);
56965730

56975731
try {
5698-
InputStream is = Ops.class.getResourceAsStream("/jvmconfig.properties");
5699-
Properties config = new Properties();
5700-
config.load(is);
5701-
for (String name : config.stringPropertyNames())
5702-
res.bind_key_boxed(tc, name, box_s(config.getProperty(name), strType, tc));
5703-
} catch (Throwable e) {
5704-
die_s("Failed to load config.properties", tc);
5705-
}
5732+
InputStream is = Ops.class.getResourceAsStream("/jvmconfig.properties");
5733+
Properties config = new Properties();
5734+
config.load(is);
5735+
for (String name : config.stringPropertyNames())
5736+
res.bind_key_boxed(tc, name, box_s(config.getProperty(name), strType, tc));
5737+
} catch (Throwable e) {
5738+
die_s("Failed to load config.properties", tc);
5739+
}
57065740

57075741
return res;
57085742
}

src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/NFA.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class NFA extends REPR {
2323
public static final int EDGE_GENERIC_VAR = 11;
2424
public static final int EDGE_CHARRANGE = 12;
2525
public static final int EDGE_CHARRANGE_NEG = 13;
26+
public static final int EDGE_CODEPOINT_LL = 14;
27+
public static final int EDGE_CODEPOINT_I_LL = 15;
2628

2729
public SixModelObject type_object_for(ThreadContext tc, SixModelObject HOW) {
2830
STable st = new STable(this, HOW);
@@ -69,8 +71,9 @@ public void deserialize_finish(ThreadContext tc, STable st,
6971
body.states[i][j] = new NFAStateInfo();
7072
body.states[i][j].act = (int)reader.readLong();
7173
body.states[i][j].to = (int)reader.readLong();
72-
switch (body.states[i][j].act) {
74+
switch (body.states[i][j].act & 0xff) {
7375
case EDGE_FATE:
76+
case EDGE_CODEPOINT_LL:
7477
case EDGE_CODEPOINT:
7578
case EDGE_CODEPOINT_NEG:
7679
case EDGE_CHARCLASS:
@@ -81,6 +84,7 @@ public void deserialize_finish(ThreadContext tc, STable st,
8184
case EDGE_CHARLIST_NEG:
8285
body.states[i][j].arg_s = reader.readStr();
8386
break;
87+
case EDGE_CODEPOINT_I_LL:
8488
case EDGE_CODEPOINT_I:
8589
case EDGE_CODEPOINT_I_NEG:
8690
case EDGE_CHARRANGE:
@@ -113,8 +117,9 @@ public void serialize(ThreadContext tc, SerializationWriter writer, SixModelObje
113117
for (int j = 0; j < body.states[i].length; j++) {
114118
writer.writeInt(body.states[i][j].act);
115119
writer.writeInt(body.states[i][j].to);
116-
switch (body.states[i][j].act) {
120+
switch (body.states[i][j].act & 0xff) {
117121
case EDGE_FATE:
122+
case EDGE_CODEPOINT_LL:
118123
case EDGE_CODEPOINT:
119124
case EDGE_CODEPOINT_NEG:
120125
case EDGE_CHARCLASS:
@@ -125,6 +130,7 @@ public void serialize(ThreadContext tc, SerializationWriter writer, SixModelObje
125130
case EDGE_CHARLIST_NEG:
126131
writer.writeStr(body.states[i][j].arg_s);
127132
break;
133+
case EDGE_CODEPOINT_I_LL:
128134
case EDGE_CODEPOINT_I:
129135
case EDGE_CODEPOINT_I_NEG:
130136
case EDGE_CHARRANGE:

0 commit comments

Comments
 (0)