-
Notifications
You must be signed in to change notification settings - Fork 145
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
Better support for calling frege from java #20
Comments
This is now far easier with the new runtime system, as it is possible to pass in values where lazy values are expected. OTOH, lazy arguments appear as Lazy or Object, hence it is easily possible to pass objects of the wrong type. |
New syntax to
The syntax goes like:
X, Y and Z must be types (or type applications) that result in a native type. The compiler outputs
where Note that the braces must be written, otherwise the lexer will insert extra semicolons into your java. The compiler does only check the syntax and that there is at most one such definition, and that the given types are of kind *. It does not interpret the java code in any way. If you want to use that code from inside frege, you need to provide further native method definitions. But note that you cannot refererence the module class as native data type, because it doesn't exist yet at compile time! (You can, however, use static methods.) For an example, see tests/comp/Issue20.fr |
This is really nice and exciting! This feature allows Frege modules to be used in places where non-anonymous Java classes are expected, for example, a Java servlet class in I have few questions:
module foo.Foo where
native """
@MyAnnotation1
@MyAnnotation2
public static class Bar extends AnotherJavaClass implements AnotherJavaInterface {
// constructors and methods
}
/**
* You could even have some standalone methods
*/
public static int foo(int n) { return n + 1; }
"""
-- My other Frege functions
f x = ...
main = ... Maybe in the distant future :), we could even provide an option to specify the language so that the compilers that are interested in one particular language native code can ignore others. Ideally I would like Frege to be completely independent/isolated from runtime dependency (currently Java, especially core Java types that Frege depend on) as much as possible as it allows targeting other runtimes easily. module foo.Foo where
native """java
public static class MyJavaClass {}
"""
native """javascript
function foo() {}
"""
|
Hi Marimuthu,
module where { and the second one with a closing brace. |
Excellent! Thanks Ingo! |
Objective
Given a symbol table (either created through compilation or reconstructed from class-Files) and a set of function and variable names, it should be possible to derive a Java class with the following properties:
N
, the class contains a method that returns the evaluated and possibly un-boxed value of a fully satisfied function call or just the value in caseN
is not a function.The support will remain limited, however. For, suppose we have
we must insist on getting java.rt.FV (frege values) as arguments. This is because we could not possibly create an overloaded java method, that covers all (infinite many) possibilities. And even if we restricted ourselves to do overloading for "well known" types only, like Int, Long, String, Bool, Char, Double, Float we still had to create 8^k overloaded methods, where k is the arity of the method.
To supplement this, there should also be utility functions for common tasks like converting a list to Iterable or vice versa. Also, for handling of IO and ST values.
Implementation details
I suggest first writing a command line tool that can work independently of the compiler. This will be valuable in any case, as someone might decide to use a library from java despite the devolper did not anticipate this and the source code is not available.
If the need arises, we can create syntax like
The text was updated successfully, but these errors were encountered: