New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Support for native calls in flix. #428
Conversation
This allows users to call constructors, methods and fields by using unsafe native new/method/field. Currently an overloaded native method cannot be called in flix. Discussions about this can be found at flix#410 Tests has been added for this feature.
…rent time setting
…ved because date is too machine sensetive.
Great! I will take a look soon. Good points about the unsupported features. |
val name = method.getName | ||
val descriptor = asm.Type.getMethodDescriptor(method) | ||
// If the method is static, use INVOKESTATIC otherwise use INVOKEVIRTUAL | ||
val invokeCode = if (Modifier.isStatic(method.getModifiers)) INVOKESTATIC else INVOKEVIRTUAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us call this invokeInsn
,
// Native Static Field // | ||
///////////////////////////////////////////////////////////////////////////// | ||
@test | ||
def nativeCall04: Bool = assertEq!(unsafe native field java.lang.Character.BYTES, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nativeField01
// Native Constructor // | ||
///////////////////////////////////////////////////////////////////////////// | ||
@test | ||
def nativeCall01: Bool = assertEq!(unsafe native new java.lang.String(), "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nativeNew01 or nativeConstructor01
// Native Static Methods // | ||
///////////////////////////////////////////////////////////////////////////// | ||
@test | ||
def nativeCall08: Bool = assertEq!(unsafe native method java.lang.Integer.bitCount(2), 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nativeMethod01
The code looks good to me, modulo a few renamings of test cases. As for your comments: |
Can you post the exception or describe how it fails? If you think the bug is outside your code, you can open a new ticket.
I don't understand. Do you mean functions that "return"
I created #429.
Good point. I created #430. |
I fixed everything in your review. |
I think it is a type/boxing issue. I would expect that I wonder what would be a good solution to this. |
If a method has a void return type then push the unit value on the stack. |
When a void method is called, we put a Unit object on top of the stack. A test case for this feature has been added.
Apart from discussions in #410 there are couple of other issues:
def f: Bool = unsafe native field java.lang.Boolean.TRUE
fails at invoking inLinker.scala
def f: Bool = let x = unsafe native new java.util.BitSet(); unsafe native method java.util.BitSet.set(x, 1); true
I also tried
let y = unsafe native method java.util.BitSet.set(x, 1);
but this tries to pop an object off the stack so this fails._
in it fails at parsing stage