OSDN Git Service

ifstatement add nop instruction to differ with clause selector for JUMPIF instruction...
authoroysheng <33340252+oysheng@users.noreply.github.com>
Tue, 9 Oct 2018 02:29:58 +0000 (10:29 +0800)
committerPaladz <yzhu101@uottawa.ca>
Tue, 9 Oct 2018 02:29:58 +0000 (10:29 +0800)
compiler/builder.go
compiler/compile.go
compiler/compile_test.go

index b00d4ec..b3a2c94 100644 (file)
@@ -154,6 +154,10 @@ func (b *builder) addCat(stk stack, desc string) stack {
        return b.add("CAT", stk.dropN(2).add(desc))
 }
 
+func (b *builder) addNop(stk stack) stack {
+       return b.add("NOP", stk)
+}
+
 func (b *builder) opcodes() string {
        var ops []string
        for _, item := range b.items {
index 5a98641..5cefdba 100644 (file)
@@ -377,6 +377,9 @@ func compileStatement(b *builder, stk stack, contract *Contract, env *environ, c
                conditionExpr := stk.str
                stk = b.addNot(stk, fmt.Sprintf("!%s", conditionExpr))
 
+               // add nop instruction to differ with clause selector for JUMPIF instruction
+               stk = b.addNop(stk)
+
                // add label
                var label string
                if len(stmt.body.falseBody) != 0 {
index 5360de8..71e994a 100644 (file)
@@ -74,17 +74,17 @@ func TestCompile(t *testing.T) {
                {
                        "TestSigIf",
                        equitytest.TestSigIf,
-                       "53797b879169765379a091641b00000052795279a0696320000000765279a069",
+                       "53797b879169765379a09161641c00000052795279a0696321000000765279a069",
                },
                {
                        "TestIfAndMultiClause",
                        equitytest.TestIfAndMultiClause,
-                       "7b641e0000007087916976547aa0916419000000765379a06963230000007b7bae7cac",
+                       "7b641f0000007087916976547aa09161641a000000765379a06963240000007b7bae7cac",
                },
                {
                        "TestIfNesting",
                        equitytest.TestIfNesting,
-                       "7b644200000054795279879169765579a091643300000052795479a0916427000000765379a069527955798791696338000000765479a06953797b879163590000007654798791695279a0916456000000527978a0697d8791",
+                       "7b644400000054795279879169765579a09161643500000052795479a091616429000000765379a06952795579879169633a000000765479a06953797b8791635c0000007654798791695279a091616459000000527978a0697d8791",
                },
                {
                        "TestConstantMath",