Skip to content

Commit 52f64dd

Browse files
committed
Implement lexical native ref taking ops.
1 parent 228f135 commit 52f64dd

File tree

1 file changed

+131
-0
lines changed
  • src/vm/jvm/runtime/org/perl6/nqp/runtime

1 file changed

+131
-0
lines changed

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

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
import org.perl6.nqp.sixmodel.reprs.NFA;
8888
import org.perl6.nqp.sixmodel.reprs.NFAInstance;
8989
import org.perl6.nqp.sixmodel.reprs.NFAStateInfo;
90+
import org.perl6.nqp.sixmodel.reprs.NativeRefInstanceIntLex;
91+
import org.perl6.nqp.sixmodel.reprs.NativeRefInstanceNumLex;
92+
import org.perl6.nqp.sixmodel.reprs.NativeRefInstanceStrLex;
9093
import org.perl6.nqp.sixmodel.reprs.NativeRefREPRData;
9194
import org.perl6.nqp.sixmodel.reprs.P6bigintInstance;
9295
import org.perl6.nqp.sixmodel.reprs.P6int;
@@ -1229,6 +1232,134 @@ public static String bindlex_s(String name, String value, ThreadContext tc) {
12291232
throw ExceptionHandling.dieInternal(tc, "Lexical '" + name + "' not found");
12301233
}
12311234

1235+
/* Native lexical references. */
1236+
public static SixModelObject getlexref_i(ThreadContext tc, int idx) {
1237+
CallFrame cf = tc.curFrame;
1238+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.intLexRef;
1239+
if (refType == null)
1240+
throw ExceptionHandling.dieInternal(tc,
1241+
"No int lexical reference type registered for current HLL");
1242+
NativeRefInstanceIntLex ref = (NativeRefInstanceIntLex)refType.st.REPR.allocate(tc, refType.st);
1243+
ref.lexicals = cf.iLex;
1244+
ref.idx = idx;
1245+
return ref;
1246+
}
1247+
public static SixModelObject getlexref_n(ThreadContext tc, int idx) {
1248+
CallFrame cf = tc.curFrame;
1249+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.numLexRef;
1250+
if (refType == null)
1251+
throw ExceptionHandling.dieInternal(tc,
1252+
"No num lexical reference type registered for current HLL");
1253+
NativeRefInstanceNumLex ref = (NativeRefInstanceNumLex)refType.st.REPR.allocate(tc, refType.st);
1254+
ref.lexicals = cf.nLex;
1255+
ref.idx = idx;
1256+
return ref;
1257+
}
1258+
public static SixModelObject getlexref_s(ThreadContext tc, int idx) {
1259+
CallFrame cf = tc.curFrame;
1260+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.strLexRef;
1261+
if (refType == null)
1262+
throw ExceptionHandling.dieInternal(tc,
1263+
"No str lexical reference type registered for current HLL");
1264+
NativeRefInstanceStrLex ref = (NativeRefInstanceStrLex)refType.st.REPR.allocate(tc, refType.st);
1265+
ref.lexicals = cf.sLex;
1266+
ref.idx = idx;
1267+
return ref;
1268+
}
1269+
public static SixModelObject getlexref_i_si(ThreadContext tc, int idx, int si) {
1270+
CallFrame cf = tc.curFrame;
1271+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.intLexRef;
1272+
if (refType == null)
1273+
throw ExceptionHandling.dieInternal(tc,
1274+
"No int lexical reference type registered for current HLL");
1275+
while (si-- > 0)
1276+
cf = cf.outer;
1277+
NativeRefInstanceIntLex ref = (NativeRefInstanceIntLex)refType.st.REPR.allocate(tc, refType.st);
1278+
ref.lexicals = cf.iLex;
1279+
ref.idx = idx;
1280+
return ref;
1281+
}
1282+
public static SixModelObject getlexref_n_si(ThreadContext tc, int idx, int si) {
1283+
CallFrame cf = tc.curFrame;
1284+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.numLexRef;
1285+
if (refType == null)
1286+
throw ExceptionHandling.dieInternal(tc,
1287+
"No num lexical reference type registered for current HLL");
1288+
while (si-- > 0)
1289+
cf = cf.outer;
1290+
NativeRefInstanceNumLex ref = (NativeRefInstanceNumLex)refType.st.REPR.allocate(tc, refType.st);
1291+
ref.lexicals = cf.nLex;
1292+
ref.idx = idx;
1293+
return ref;
1294+
}
1295+
public static SixModelObject getlexref_s_si(ThreadContext tc, int idx, int si) {
1296+
CallFrame cf = tc.curFrame;
1297+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.strLexRef;
1298+
if (refType == null)
1299+
throw ExceptionHandling.dieInternal(tc,
1300+
"No str lexical reference type registered for current HLL");
1301+
while (si-- > 0)
1302+
cf = cf.outer;
1303+
NativeRefInstanceStrLex ref = (NativeRefInstanceStrLex)refType.st.REPR.allocate(tc, refType.st);
1304+
ref.lexicals = cf.sLex;
1305+
ref.idx = idx;
1306+
return ref;
1307+
}
1308+
public static SixModelObject getlexref_i(String name, ThreadContext tc) {
1309+
CallFrame cf = tc.curFrame;
1310+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.intLexRef;
1311+
if (refType == null)
1312+
throw ExceptionHandling.dieInternal(tc,
1313+
"No int lexical reference type registered for current HLL");
1314+
while (cf != null) {
1315+
Integer found = cf.codeRef.staticInfo.iTryGetLexicalIdx(name);
1316+
if (found != null) {
1317+
NativeRefInstanceIntLex ref = (NativeRefInstanceIntLex)refType.st.REPR.allocate(tc, refType.st);
1318+
ref.lexicals = cf.iLex;
1319+
ref.idx = (int)found;
1320+
return ref;
1321+
}
1322+
cf = cf.outer;
1323+
}
1324+
throw ExceptionHandling.dieInternal(tc, "Lexical '" + name + "' not found");
1325+
}
1326+
public static SixModelObject getlexref_n(String name, ThreadContext tc) {
1327+
CallFrame cf = tc.curFrame;
1328+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.numLexRef;
1329+
if (refType == null)
1330+
throw ExceptionHandling.dieInternal(tc,
1331+
"No num lexical reference type registered for current HLL");
1332+
while (cf != null) {
1333+
Integer found = cf.codeRef.staticInfo.nTryGetLexicalIdx(name);
1334+
if (found != null) {
1335+
NativeRefInstanceNumLex ref = (NativeRefInstanceNumLex)refType.st.REPR.allocate(tc, refType.st);
1336+
ref.lexicals = cf.nLex;
1337+
ref.idx = (int)found;
1338+
return ref;
1339+
}
1340+
cf = cf.outer;
1341+
}
1342+
throw ExceptionHandling.dieInternal(tc, "Lexical '" + name + "' not found");
1343+
}
1344+
public static SixModelObject getlexref_s(String name, ThreadContext tc) {
1345+
CallFrame cf = tc.curFrame;
1346+
SixModelObject refType = cf.codeRef.staticInfo.compUnit.hllConfig.strLexRef;
1347+
if (refType == null)
1348+
throw ExceptionHandling.dieInternal(tc,
1349+
"No str lexical reference type registered for current HLL");
1350+
while (cf != null) {
1351+
Integer found = cf.codeRef.staticInfo.sTryGetLexicalIdx(name);
1352+
if (found != null) {
1353+
NativeRefInstanceStrLex ref = (NativeRefInstanceStrLex)refType.st.REPR.allocate(tc, refType.st);
1354+
ref.lexicals = cf.sLex;
1355+
ref.idx = (int)found;
1356+
return ref;
1357+
}
1358+
cf = cf.outer;
1359+
}
1360+
throw ExceptionHandling.dieInternal(tc, "Lexical '" + name + "' not found");
1361+
}
1362+
12321363
/* Dynamic lexicals. */
12331364
public static SixModelObject bindlexdyn(SixModelObject value, String name, ThreadContext tc) {
12341365
CallFrame curFrame = tc.curFrame.caller;

0 commit comments

Comments
 (0)