-
First of all, thank you for this great library. It is so much simpler than ASM and I can actually do things with it. I have 2 questions, and I hope that you will be able to help me. How do I obtain a "Variable" (I think it's not the right thing for this use-case, but I did not find an alternative) for a constant/literal value? Say if I have a boolean variable that I want to assign the expression long var2 = 1L;
boolean var3 = var2 < 4L; but I tried compiling a class with javac and I got the much simpler boolean var1 = 1L < 4L; (javac optimizes this but I tried with a more difficult expression, it still did not generate a single-use variable). And then that var3 is used in a method invocation, so there's 2 redundant variables. I would love to get to know how I could for example do a simple How do I perform logical operations? Like, how can I get a If these could be added to the wiki it would be great. Thanks again for the library. |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 23 replies
-
|
Beta Was this translation helpful? Give feedback.
-
By the way, some work is performed to reduce local variable usage already, but only for simple cases. The |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Regarding logical operations, the bitwise AND and OR seems to do the same job as logical AND and OR when used with booleans? I could not figure out what to do with labels in my procedure so I guess I could use that instead. |
Beta Was this translation helpful? Give feedback.
-
If you have an AST, generating short-circuit logic code using goto statements is typical, and javac does this too. If the Cojen/Maker library supported short-circuit operations directly, it would need do perform a bunch of reverse engineering to reconstruct an AST first. You can use the bitwise operations with boolean types, but this doesn't perform short-circuit logic, and so it's not a good substitute. |
Beta Was this translation helpful? Give feedback.
-
I honestly have no idea what short-circuit logic even is in this context. After some more tinkering I figured I could create a boolean Variable that is false to begin with, then have ifFalse for both the left-hand argument and right-hand argument (which at the point where a && or || comparison is being handled, have already been turned into boolean Variables or are boolean Objects-in the case of literals) to skip to a label which is right after a Thanks for the help. The decompiled code isn't "pretty", but it gets the work done. |
Beta Was this translation helpful? Give feedback.
-
Cojen/Maker is a great library, thanks again for making it. I'll go work on the other parts of my language (method selection-overloads and varargs can be tough, type promotion, etc.). If you use cryptocurrency, I'd love to send you a tip in the currency of your choice. As a thank you for the library and the help :) |
Beta Was this translation helpful? Give feedback.
-
Hey I ran into another issue, I hope you can help me. So I did a lot of things, and now I need to pass a lambda to a method call. The method I want to call is I've done all the LambdaMetafactory things, but when I try to invoke this method, it says I invoke it like this: I suspect that even if I get past this point I will run into other issues, due to this comment that I read in the wiki |
Beta Was this translation helpful? Give feedback.
-
The function param and the observables need to be passed as combined Object array. The varags param doesn't understand that's what you intend and so it sees the function as the first param, and the array of variables as the second param. |
Beta Was this translation helpful? Give feedback.
-
...or do you intend for the Observable... param to be varargs? In that case, you need to pass an Observable array.
|
Beta Was this translation helpful? Give feedback.
-
My suspicion was correct, the lambda method obviously does not have access to the local variables of the other method. Do you know how I would pass them? |
Beta Was this translation helpful? Give feedback.
-
Here's the ugly code to make it work manually:
|
Beta Was this translation helpful? Give feedback.
The decompiler is confused by the extra local variables that get created. It's expecting a certain pattern of stack pushes in order to re-create an inline lambda definition. As I indicated earlier, without direct stack manipulation support, extra local variables can be created.
If you take the decompiled code generated by Fernflower and manually move some code around you get this:
Then change Observable[] to varargs syntax: