Code Monkey home page Code Monkey logo

Comments (2)

wuyr avatar wuyr commented on September 13, 2024

I got it, when local1 value = 0, the result order is always reversed. how can i fix this?

from dexmaker.

kkoser avatar kkoser commented on September 13, 2024

Hey @wuyr sorry I'm getting back so late - I think this is working as expected. writing a comparison of compare(LT, local1, param) is the java equivalent of

if (local1 < param)
which could also be rewritten as

if (param >= local1)

I tried writing a test case for this with the local having a value of 0, and it seems to work correctly - lmk if you're seeing different, or if I'm misunderstanding your use case. Thanks!

    @Test
    public void testIntCompare() throws Exception {
        /*
         * public static bool call(int b) {
         *   return 0 < b
         * }
         */
        MethodId<?, Boolean> methodId = GENERATED.getMethod(
                TypeId.BOOLEAN, "call", TypeId.INT);
        Code code = dexMaker.declare(methodId, PUBLIC | STATIC);
        Local<Integer> localA = code.newLocal(TypeId.INT);
        Local<Integer> localB = code.getParameter(0, TypeId.INT);
        Local<Boolean> result = code.newLocal(TypeId.get(boolean.class));
        Label afterIf = new Label();
        Label ifBody = new Label();
        code.loadConstant(localA, 0);
        code.compare(Comparison.LT, ifBody, localA, localB);
        code.jump(afterIf);

        code.mark(ifBody);
        code.loadConstant(result, true);
        code.returnValue(result);

        code.mark(afterIf);
        code.loadConstant(result, false);
        code.returnValue(result);
        Method method = getMethod();


        assertEquals(true, method.invoke(null, 5));
        assertEquals(false, method.invoke(null, -5));
        assertEquals(false, method.invoke(null, 0));
    }```

from dexmaker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.