Skip to content

Commit 97b92eb

Browse files
Julius Bierbaumliketechnik
authored andcommitted
feat(op-codes): ifcmp for references and integers
1 parent c5456bd commit 97b92eb

File tree

1 file changed

+284
-1
lines changed

1 file changed

+284
-1
lines changed

src/executor/op_code.rs

Lines changed: 284 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,290 @@ got: {:?}",
11711171

11721172
Update::None
11731173
},
1174-
1174+
Self::IfacmpNe(size, direction) => {
1175+
let op2: Option<Rc<dyn ClassInstance>> = frame
1176+
.operand_stack
1177+
.pop()
1178+
.unwrap()
1179+
.try_into()
1180+
.unwrap();
1181+
let op1: Option<Rc<dyn ClassInstance>> = frame
1182+
.operand_stack
1183+
.pop()
1184+
.unwrap()
1185+
.try_into()
1186+
.unwrap();
1187+
match(op1, op2) {
1188+
(Some(_), None) | (None, Some(_)) => Update::GoTo(*size, *direction),
1189+
(None, None) => Update::None,
1190+
(Some(op1), Some(op2)) => {
1191+
if !Rc::<dyn ClassInstance>::ptr_eq(&op1, &op2) {
1192+
Update::GoTo(*size, *direction)
1193+
}
1194+
else {
1195+
Update::None
1196+
}
1197+
}
1198+
}
1199+
}
1200+
Self::IfacmpEq(size, direction) => {
1201+
let op2: Option<Rc<dyn ClassInstance>> = frame
1202+
.operand_stack
1203+
.pop()
1204+
.unwrap()
1205+
.try_into()
1206+
.unwrap();
1207+
let op1: Option<Rc<dyn ClassInstance>> = frame
1208+
.operand_stack
1209+
.pop()
1210+
.unwrap()
1211+
.try_into()
1212+
.unwrap();
1213+
match(op1, op2) {
1214+
(Some(_), None) | (None, Some(_)) => Update::None,
1215+
(None, None) => Update::GoTo(*size, *direction),
1216+
(Some(op1), Some(op2)) => {
1217+
if Rc::<dyn ClassInstance>::ptr_eq(&op1, &op2) {
1218+
Update::GoTo(*size, *direction)
1219+
}
1220+
else {
1221+
Update::None
1222+
}
1223+
}
1224+
}
1225+
}
1226+
Self::IficmpEq(size, direction) => {
1227+
let op2 = frame
1228+
.operand_stack
1229+
.pop()
1230+
.unwrap()
1231+
.as_computation_int()
1232+
.unwrap();
1233+
let op1 = frame
1234+
.operand_stack
1235+
.pop()
1236+
.unwrap()
1237+
.as_computation_int()
1238+
.unwrap();
1239+
if op1 == op2 {
1240+
Update::GoTo(*size, *direction)
1241+
}
1242+
else {
1243+
Update::None
1244+
}
1245+
}
1246+
Self::IficmpNe(size, direction) => {
1247+
let op2 = frame
1248+
.operand_stack
1249+
.pop()
1250+
.unwrap()
1251+
.as_computation_int()
1252+
.unwrap();
1253+
let op1 = frame
1254+
.operand_stack
1255+
.pop()
1256+
.unwrap()
1257+
.as_computation_int()
1258+
.unwrap();
1259+
if op1 != op2 {
1260+
Update::GoTo(*size, *direction)
1261+
}
1262+
else {
1263+
Update::None
1264+
}
1265+
}
1266+
Self::IficmpLt(size, direction) => {
1267+
let op2 = frame
1268+
.operand_stack
1269+
.pop()
1270+
.unwrap()
1271+
.as_computation_int()
1272+
.unwrap();
1273+
let op1 = frame
1274+
.operand_stack
1275+
.pop()
1276+
.unwrap()
1277+
.as_computation_int()
1278+
.unwrap();
1279+
if op1 < op2 {
1280+
Update::GoTo(*size, *direction)
1281+
}
1282+
else {
1283+
Update::None
1284+
}
1285+
}
1286+
Self::IficmpGt(size, direction) => {
1287+
let op2 = frame
1288+
.operand_stack
1289+
.pop()
1290+
.unwrap()
1291+
.as_computation_int()
1292+
.unwrap();
1293+
let op1 = frame
1294+
.operand_stack
1295+
.pop()
1296+
.unwrap()
1297+
.as_computation_int()
1298+
.unwrap();
1299+
if op1 > op2 {
1300+
Update::GoTo(*size, *direction)
1301+
}
1302+
else {
1303+
Update::None
1304+
}
1305+
}
1306+
Self::IficmpLe(size, direction) => {
1307+
let op2 = frame
1308+
.operand_stack
1309+
.pop()
1310+
.unwrap()
1311+
.as_computation_int()
1312+
.unwrap();
1313+
let op1 = frame
1314+
.operand_stack
1315+
.pop()
1316+
.unwrap()
1317+
.as_computation_int()
1318+
.unwrap();
1319+
if op1 <= op2 {
1320+
Update::GoTo(*size, *direction)
1321+
}
1322+
else {
1323+
Update::None
1324+
}
1325+
}
1326+
Self::IficmpGe(size, direction) => {
1327+
let op2 = frame
1328+
.operand_stack
1329+
.pop()
1330+
.unwrap()
1331+
.as_computation_int()
1332+
.unwrap();
1333+
let op1 = frame
1334+
.operand_stack
1335+
.pop()
1336+
.unwrap()
1337+
.as_computation_int()
1338+
.unwrap();
1339+
if op1 >= op2 {
1340+
Update::GoTo(*size, *direction)
1341+
}
1342+
else {
1343+
Update::None
1344+
}
1345+
}
1346+
Self::IfEq(size, direction) => {
1347+
let op1 = frame
1348+
.operand_stack
1349+
.pop()
1350+
.unwrap()
1351+
.as_computation_int()
1352+
.unwrap();
1353+
if op1 == 0 {
1354+
Update::GoTo(*size, *direction)
1355+
}
1356+
else {
1357+
Update::None
1358+
}
1359+
}
1360+
Self::IfNe(size, direction) => {
1361+
let op1 = frame
1362+
.operand_stack
1363+
.pop()
1364+
.unwrap()
1365+
.as_computation_int()
1366+
.unwrap();
1367+
if op1 != 0 {
1368+
Update::GoTo(*size, *direction)
1369+
}
1370+
else {
1371+
Update::None
1372+
}
1373+
}
1374+
Self::IfLt(size, direction) => {
1375+
let op1 = frame
1376+
.operand_stack
1377+
.pop()
1378+
.unwrap()
1379+
.as_computation_int()
1380+
.unwrap();
1381+
if op1 < 0 {
1382+
Update::GoTo(*size, *direction)
1383+
}
1384+
else {
1385+
Update::None
1386+
}
1387+
}
1388+
Self::IfGt(size, direction) => {
1389+
let op1 = frame
1390+
.operand_stack
1391+
.pop()
1392+
.unwrap()
1393+
.as_computation_int()
1394+
.unwrap();
1395+
if op1 > 0 {
1396+
Update::GoTo(*size, *direction)
1397+
}
1398+
else {
1399+
Update::None
1400+
}
1401+
}
1402+
Self::IfLe(size, direction) => {
1403+
let op1 = frame
1404+
.operand_stack
1405+
.pop()
1406+
.unwrap()
1407+
.as_computation_int()
1408+
.unwrap();
1409+
if op1 <= 0 {
1410+
Update::GoTo(*size, *direction)
1411+
}
1412+
else {
1413+
Update::None
1414+
}
1415+
}
1416+
Self::IfGe(size, direction) => {
1417+
let op1 = frame
1418+
.operand_stack
1419+
.pop()
1420+
.unwrap()
1421+
.as_computation_int()
1422+
.unwrap();
1423+
if op1 >= 0 {
1424+
Update::GoTo(*size, *direction)
1425+
}
1426+
else {
1427+
Update::None
1428+
}
1429+
}
1430+
Self::IfNonNull(size, direction) => {
1431+
let op1: Option<Rc<dyn ClassInstance>> = frame
1432+
.operand_stack
1433+
.pop()
1434+
.unwrap()
1435+
.try_into()
1436+
.unwrap();
1437+
if op1.is_some() {
1438+
Update::GoTo(*size, *direction)
1439+
}
1440+
else {
1441+
Update::None
1442+
}
1443+
}
1444+
Self::IfNull(size, direction) => {
1445+
let op1: Option<Rc<dyn ClassInstance>> = frame
1446+
.operand_stack
1447+
.pop()
1448+
.unwrap()
1449+
.try_into()
1450+
.unwrap();
1451+
if op1.is_none() {
1452+
Update::GoTo(*size, *direction)
1453+
}
1454+
else {
1455+
Update::None
1456+
}
1457+
}
11751458
Self::Iinc { index, constant } => {
11761459
let op1 = frame.local_variables.get(*index);
11771460
let op1 = match op1 {

0 commit comments

Comments
 (0)