• R/O
  • SSH

kink: Commit

Kink runtime


Commit MetaInfo

Révision65aa5d694e7d60ad51f4b14d22165ef21ed2f277 (tree)
l'heure2020-10-25 21:07:58
Auteurmiyakawataku
Commitermiyakawataku

Message de Log

remove IfEqInsn

Change Summary

Modification

diff -r 8c12cf7d4152 -r 65aa5d694e7d src/main/java/org/kink_lang/kink/StackMachine.java
--- a/src/main/java/org/kink_lang/kink/StackMachine.java Sun Oct 25 21:03:32 2020 +0900
+++ b/src/main/java/org/kink_lang/kink/StackMachine.java Sun Oct 25 21:07:58 2020 +0900
@@ -529,7 +529,6 @@
529529 case Opcodes.SUBNUM: { insnSubNum(); return; }
530530 case Opcodes.MULNUM: { insnMulNum(); return; }
531531 case Opcodes.GOTO: { insnGoto(qinsn); return; }
532- case Opcodes.IFEQ: { insnIfEq(); return; }
533532 case Opcodes.JUMPIFNE: { insnJumpIfNe(qinsn); return; }
534533 case Opcodes.IFLT: { insnIfLt(); return; }
535534 case Opcodes.IFVEC: { insnIfVec(); return; }
@@ -930,17 +929,6 @@
930929 }
931930
932931 /**
933- * Executes IFEQ instruction.
934- */
935- private void insnIfEq() {
936- Val v2 = this.dataStack.pop();
937- Val v1 = this.dataStack.pop();
938- if (v1.equals(v2)) {
939- ++ this.programCounter;
940- }
941- }
942-
943- /**
944932 * Executes JUMPIFNE instruction.
945933 */
946934 private void insnJumpIfNe(Qinsn qinsn) {
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/main/java/org/kink_lang/kink/internal/program/wire/IfEqInsn.java
--- a/src/main/java/org/kink_lang/kink/internal/program/wire/IfEqInsn.java Sun Oct 25 21:03:32 2020 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
1-package org.kink_lang.kink.internal.program.wire;
2-
3-import java.util.Locale;
4-
5-/**
6- * IFEQ insn.
7- */
8-public class IfEqInsn extends Insn {
9-
10- /**
11- * Constructs an IFEQ insn.
12- *
13- * @param pos the pos index of the insn.
14- */
15- public IfEqInsn(int pos) {
16- super(pos);
17- }
18-
19- @Override
20- public <T> T accept(InsnVisitor<T> visitor) {
21- return visitor.visit(this);
22- }
23-
24- @Override
25- public String toString() {
26- return String.format(Locale.ROOT, "IfEqInsn(%d)", getPos());
27- }
28-
29- @Override
30- public int hashCode() {
31- return getPos();
32- }
33-
34- @Override
35- public boolean equals(Object arg) {
36- return arg == this
37- || arg instanceof IfEqInsn
38- && getPos() == ((IfEqInsn) arg).getPos();
39- }
40-
41-}
42-
43-// vim: et sw=4 sts=4 fdm=marker
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/main/java/org/kink_lang/kink/internal/program/wire/InsnVisitor.java
--- a/src/main/java/org/kink_lang/kink/internal/program/wire/InsnVisitor.java Sun Oct 25 21:03:32 2020 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/program/wire/InsnVisitor.java Sun Oct 25 21:07:58 2020 +0900
@@ -280,14 +280,6 @@
280280 public abstract T visit(GotoInsn insn);
281281
282282 /**
283- * Visits IFEQ instruction.
284- *
285- * @param insn the instruction.
286- * @return the result of the visitor.
287- */
288- public abstract T visit(IfEqInsn insn);
289-
290- /**
291283 * Visits JUMPIFNE instruction.
292284 *
293285 * @param insn the instruction.
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/main/java/org/kink_lang/kink/internal/qcode/Opcodes.java
--- a/src/main/java/org/kink_lang/kink/internal/qcode/Opcodes.java Sun Oct 25 21:03:32 2020 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/qcode/Opcodes.java Sun Oct 25 21:07:58 2020 +0900
@@ -312,22 +312,13 @@
312312 public static final int GOTO = 32;
313313
314314 /**
315- * If the top two vals are equal by Val#equals(Object), skips the next insn.
316- *
317- * <p>Operand: none.</p>
318- *
319- * <p>dataStack: [_ val1 val2] → [_].</p>
320- */
321- public static final int IFEQ = 33;
322-
323- /**
324315 * If the top val is not equal to the operand by Val#equals, jumps to the destination.
325316 *
326317 * <p>objOperand1: testval, intOperand: destination.</p>
327318 *
328319 * <p>dataStack: [_ val] → [_].</p>
329320 */
330- public static final int JUMPIFNE = 41;
321+ public static final int JUMPIFNE = 33;
331322
332323 /**
333324 * If the first int is less than the second int,
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/main/java/org/kink_lang/kink/internal/qcode/Qinsn.java
--- a/src/main/java/org/kink_lang/kink/internal/qcode/Qinsn.java Sun Oct 25 21:03:32 2020 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/qcode/Qinsn.java Sun Oct 25 21:07:58 2020 +0900
@@ -513,16 +513,6 @@
513513 }
514514
515515 /**
516- * Makes a IFEQ insn.
517- *
518- * @param pos the pos of the insn.
519- * @return IFEQ insn.
520- */
521- public static Qinsn makeIfEq(int pos) {
522- return new Qinsn(Opcodes.IFEQ, 0, null, null, pos);
523- }
524-
525- /**
526516 * Makes a JUMPIFNE insn.
527517 *
528518 * @param test the val to test equality with the top of the stack.
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/main/java/org/kink_lang/kink/internal/qcode/WireToQblockTranslator.java
--- a/src/main/java/org/kink_lang/kink/internal/qcode/WireToQblockTranslator.java Sun Oct 25 21:03:32 2020 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/qcode/WireToQblockTranslator.java Sun Oct 25 21:07:58 2020 +0900
@@ -325,12 +325,6 @@
325325 }
326326
327327 @Override
328- public Void visit(IfEqInsn insn) {
329- this.qinsns.add(Qinsn.makeIfEq(insn.getPos()));
330- return null;
331- }
332-
333- @Override
334328 public Void visit(JumpIfNeInsn insn) {
335329 int destProgramCounter = wire.getProgramCounterOf(insn.getDestLabel()).getAsInt();
336330 this.qinsns.add(Qinsn.makeJumpIfNe(insn.getTest(), destProgramCounter, insn.getPos()));
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/test/java/org/kink_lang/kink/StackMachineTest.java
--- a/src/test/java/org/kink_lang/kink/StackMachineTest.java Sun Oct 25 21:03:32 2020 +0900
+++ b/src/test/java/org/kink_lang/kink/StackMachineTest.java Sun Oct 25 21:07:58 2020 +0900
@@ -541,98 +541,6 @@
541541
542542 // }}}2
543543
544- // IFEQ {{{2
545-
546- @Test
547- public void test_run_qblock_ifeq_true_with_int() {
548- Wire wire = new Wire(List.of(
549- new ArgInsn(0, 100),
550- new KonstInsn(intHolder.of(999), 101),
551- new IfEqInsn(102),
552- new GotoInsn("ne", 103),
553- new KonstInsn(vm.str.of("ok"), 104),
554- new RetInsn(105),
555- new LabelPseudoInsn("ne"),
556- new KonstInsn(vm.str.of("bad"), 106),
557- new RetInsn(107)), 1, 0, List.of());
558- WireToQblockTranslator w2q = new WireToQblockTranslator(
559- vm, "foo.kn", "if \\0 equals 999 then return 'ok' else 'bad'", 0, 999);
560-
561- Qblock qblock = w2q.apply(wire);
562- FunVal fun = new EnclosedQblockFunVal(vm, qblock, vm.binding.newBinding());
563- FunVal caller = vm.fun.make().action(c -> c.call(fun).args(intHolder.of(999)));
564- StrVal result = (StrVal) runFun(caller);
565- assertThat(result.getString()).isEqualTo("ok");
566- }
567-
568- @Test
569- public void test_run_qblock_ifeq_false_with_int() {
570- Wire wire = new Wire(List.of(
571- new ArgInsn(0, 100),
572- new KonstInsn(intHolder.of(999), 101),
573- new IfEqInsn(102),
574- new GotoInsn("ne", 103),
575- new KonstInsn(vm.str.of("ok"), 104),
576- new RetInsn(105),
577- new LabelPseudoInsn("ne"),
578- new KonstInsn(vm.str.of("bad"), 106),
579- new RetInsn(107)), 1, 0, List.of());
580- WireToQblockTranslator w2q = new WireToQblockTranslator(
581- vm, "foo.kn", "if \\0 equals 999 then return 'ok' else 'bad'", 0, 999);
582-
583- Qblock qblock = w2q.apply(wire);
584- FunVal fun = new EnclosedQblockFunVal(vm, qblock, vm.binding.newBinding());
585- FunVal caller = vm.fun.make().action(c -> c.call(fun).args(intHolder.of(777)));
586- StrVal result = (StrVal) runFun(caller);
587- assertThat(result.getString()).isEqualTo("bad");
588- }
589-
590- @Test
591- public void test_run_qblock_ifeq_true_with_str() {
592- Wire wire = new Wire(List.of(
593- new ArgInsn(0, 100),
594- new KonstInsn(vm.str.of("foobar"), 101),
595- new IfEqInsn(102),
596- new GotoInsn("ne", 103),
597- new KonstInsn(vm.str.of("ok"), 104),
598- new RetInsn(105),
599- new LabelPseudoInsn("ne"),
600- new KonstInsn(vm.str.of("bad"), 106),
601- new RetInsn(107)), 1, 0, List.of());
602- WireToQblockTranslator w2q = new WireToQblockTranslator(
603- vm, "foo.kn", "if \\0 equals 'foobar' then return 'ok' else 'bad'", 0, 999);
604-
605- Qblock qblock = w2q.apply(wire);
606- FunVal fun = new EnclosedQblockFunVal(vm, qblock, vm.binding.newBinding());
607- FunVal caller = vm.fun.make().action(c -> c.call(fun).args(vm.str.of("foobar")));
608- StrVal result = (StrVal) runFun(caller);
609- assertThat(result.getString()).isEqualTo("ok");
610- }
611-
612- @Test
613- public void test_run_qblock_ifeq_false_with_str() {
614- Wire wire = new Wire(List.of(
615- new ArgInsn(0, 100),
616- new KonstInsn(vm.str.of("foobar"), 101),
617- new IfEqInsn(102),
618- new GotoInsn("ne", 103),
619- new KonstInsn(vm.str.of("ok"), 104),
620- new RetInsn(105),
621- new LabelPseudoInsn("ne"),
622- new KonstInsn(vm.str.of("bad"), 106),
623- new RetInsn(107)), 1, 0, List.of());
624- WireToQblockTranslator w2q = new WireToQblockTranslator(
625- vm, "foo.kn", "if \\0 equals 'foobar' then return 'ok' else 'bad'", 0, 999);
626-
627- Qblock qblock = w2q.apply(wire);
628- FunVal fun = new EnclosedQblockFunVal(vm, qblock, vm.binding.newBinding());
629- FunVal caller = vm.fun.make().action(c -> c.call(fun).args(vm.str.of("boo")));
630- StrVal result = (StrVal) runFun(caller);
631- assertThat(result.getString()).isEqualTo("bad");
632- }
633-
634- // }}}2
635-
636544 // JUMPIFNE {{{2
637545
638546 @Test
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/test/java/org/kink_lang/kink/internal/program/wire/IfEqInsnTest.java
--- a/src/test/java/org/kink_lang/kink/internal/program/wire/IfEqInsnTest.java Sun Oct 25 21:03:32 2020 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
1-package org.kink_lang.kink.internal.program.wire;
2-
3-import org.junit.jupiter.api.Test;
4-
5-import static org.assertj.core.api.Assertions.assertThat;
6-
7-import mockit.Expectations;
8-import mockit.Injectable;
9-
10-import org.kink_lang.kink.internal.test.EqualityVerifier;
11-
12-public class IfEqInsnTest {
13-
14- @Test
15- public void test_propreties() {
16- IfEqInsn insn = new IfEqInsn(42);
17- assertThat(insn.getPos()).isEqualTo(42);
18- }
19-
20- @Test
21- public void test_accept(@Injectable InsnVisitor<String> visitor) {
22- IfEqInsn inst = new IfEqInsn(42);
23- new Expectations() {{
24- visitor.visit(inst); result = "ok";
25- }};
26- assertThat(inst.accept(visitor)).isEqualTo("ok");
27- }
28-
29- @Test
30- public void test_toString() {
31- IfEqInsn insn = new IfEqInsn(42);
32- assertThat(insn.toString()).isEqualTo("IfEqInsn(42)");
33- }
34-
35- @Test
36- public void test_equality() {
37- EqualityVerifier ev = new EqualityVerifier();
38- ev.group("42", new IfEqInsn(42), new IfEqInsn(42));
39- ev.group("24", new IfEqInsn(24));
40- ev.verify();
41- }
42-
43-}
44-
45-// vim: et sw=4 sts=4 fdm=marker
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/test/java/org/kink_lang/kink/internal/qcode/QinsnTest.java
--- a/src/test/java/org/kink_lang/kink/internal/qcode/QinsnTest.java Sun Oct 25 21:03:32 2020 +0900
+++ b/src/test/java/org/kink_lang/kink/internal/qcode/QinsnTest.java Sun Oct 25 21:07:58 2020 +0900
@@ -410,13 +410,6 @@
410410 }
411411
412412 @Test
413- public void test_makeIfEq() {
414- Qinsn insn = Qinsn.makeIfEq(400);
415- assertThat(insn).isEqualTo(
416- new Qinsn(Opcodes.IFEQ, 0, null, null, 400));
417- }
418-
419- @Test
420413 public void test_makeJumpIfNe() {
421414 Qinsn insn = Qinsn.makeJumpIfNe(vm.str.of("foo"), 42, 400);
422415 assertThat(insn).isEqualTo(
diff -r 8c12cf7d4152 -r 65aa5d694e7d src/test/java/org/kink_lang/kink/internal/qcode/WireToQblockTranslatorTest.java
--- a/src/test/java/org/kink_lang/kink/internal/qcode/WireToQblockTranslatorTest.java Sun Oct 25 21:03:32 2020 +0900
+++ b/src/test/java/org/kink_lang/kink/internal/qcode/WireToQblockTranslatorTest.java Sun Oct 25 21:07:58 2020 +0900
@@ -727,38 +727,6 @@
727727
728728 // }}}1
729729
730- // IFEQ {{{1
731-
732- @Test
733- public void test_translate_ifeq() {
734- Wire wire = new Wire(List.of(
735- new KonstInsn(intHolder.of(42), 100),
736- new KonstInsn(intHolder.of(42), 101),
737- new IfEqInsn(102),
738- new GotoInsn("ne", 103),
739- new KonstInsn(vm.str.of("ok"), 104),
740- new RetInsn(105),
741- new LabelPseudoInsn("ne"),
742- new KonstInsn(vm.str.of("bad"), 106),
743- new RetInsn(107)), 1, 0, List.of());
744- WireToQblockTranslator w2q = new WireToQblockTranslator(
745- vm, "foo.kn", "if 42 == 42 then return 'ok' else 'bad'", 0, 999);
746-
747- Qblock qblock = w2q.apply(wire);
748-
749- assertThat(qblock.getQinsns()).containsExactly(
750- Qinsn.makeKonst(intHolder.of(42), 100),
751- Qinsn.makeKonst(intHolder.of(42), 101),
752- Qinsn.makeIfEq(102),
753- Qinsn.makeGoto(6, 103),
754- Qinsn.makeKonst(vm.str.of("ok"), 104),
755- Qinsn.makeRet(105),
756- Qinsn.makeKonst(vm.str.of("bad"), 106),
757- Qinsn.makeRet(107));
758- }
759-
760- // }}}1
761-
762730 // JUMPIFNE {{{1
763731
764732 @Test
Afficher sur ancien navigateur de dépôt.