Package org.jruby.ast.executable.YARVMachine

Examples of org.jruby.ast.executable.YARVMachine.Instruction


import junit.framework.TestCase;

public class YARVMachineTest extends TestCase {
    public static Instruction[] getSimpleTest(Ruby runtime) {
        return new Instruction[] {
            new Instruction(YARVInstructions.PUTSTRING, "Hello, YARV!"),    // S: "HY"
            new Instruction(YARVInstructions.DUP),                          // S: "HY", "HY"
            new Instruction(YARVInstructions.SETLOCAL, 0),                  // S: "HY"; L: "HY"
            new Instruction(YARVInstructions.GETLOCAL, 0),                  // S: "HY", "HY"
            new Instruction(YARVInstructions.POP),                          // S: "HY"
            new Instruction(YARVInstructions.SETLOCAL, 1),                  // S: ; L: "HY", "HY"
            new Instruction(YARVInstructions.PUTOBJECT, runtime.getTrue()), // S: true; L: "HY", "HY"
            new Instruction(YARVInstructions.BRANCHIF, 10),                 // S: ; L: "HY", "HY"
            new Instruction(YARVInstructions.PUTSTRING, "Wrong String"),
            new Instruction(YARVInstructions.JUMP, 11),
            new Instruction(YARVInstructions.GETLOCAL, 1),                  // S: "HY"; L: "HY", "HY"
            new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(2)), // S: "HY", 2; L: "HY", "HY"
            new Instruction(YARVInstructions.SEND, "*", 1, null, 0),           // S: "HYHY"; L: "HY", "HY"
            new Instruction(YARVInstructions.PUTNIL),                          // S: "HYHY", nil; L: "HY", "HY"
            new Instruction(YARVInstructions.SEND, "to_s", 0, null, YARVInstructions.VCALL_FLAG | YARVInstructions.FCALL_FLAG), // S: "HYHY", Object; ...
            new Instruction(YARVInstructions.SEND, "+", 1, null, 0)            // S: "HYHYObject"; L: "HY", "HY"
        };
    };
View Full Code Here


    };
   
    public static Instruction[] getFib(Ruby runtime, int n){
        return new Instruction[] {
            // local var n declared (argument)
            new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(n)), // fib index
            new Instruction(YARVInstructions.SETLOCAL, 0),
            // method begins here
            // local var i declared
            new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(0)),
            new Instruction(YARVInstructions.SETLOCAL, 1),
            // local var j declared
            new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(1)),
            new Instruction(YARVInstructions.SETLOCAL, 2),
            // local var cur declared
            new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(1)),
            new Instruction(YARVInstructions.SETLOCAL, 3),
            // while begins here, instruction 8
            new Instruction(YARVInstructions.GETLOCAL, 3),
            new Instruction(YARVInstructions.GETLOCAL, 0),
            new Instruction(YARVInstructions.SEND, "<=", 1, null, 0),
            new Instruction(YARVInstructions.BRANCHUNLESS, 25),
            // local var k declared, k = i
            new Instruction(YARVInstructions.GETLOCAL, 1),
            new Instruction(YARVInstructions.SETLOCAL, 4),
            // i = j
            new Instruction(YARVInstructions.GETLOCAL, 2),
            new Instruction(YARVInstructions.SETLOCAL, 1),
            // j = k + j
            new Instruction(YARVInstructions.GETLOCAL, 4),
            new Instruction(YARVInstructions.GETLOCAL, 2),
            new Instruction(YARVInstructions.SEND, "+", 1, null, 0),
            new Instruction(YARVInstructions.SETLOCAL, 2),
            // cur = cur + 1
            new Instruction(YARVInstructions.GETLOCAL, 3),
            new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(1)),
            new Instruction(YARVInstructions.SEND, "+", 1, null, 0),
            new Instruction(YARVInstructions.SETLOCAL, 3),
            // end while
            new Instruction(YARVInstructions.JUMP, 8),
            // return i, instruction 25
            new Instruction(YARVInstructions.GETLOCAL, 1)
        };
    };
View Full Code Here

TOP

Related Classes of org.jruby.ast.executable.YARVMachine.Instruction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.