Enable passing of arguments to the polyglot engine#10
Conversation
|
Is Env per-language? |
|
The |
|
Ehm, I don't see how that could be working. To be able to construct a global object, I need to have the language initialized, no? So, I would propose: Builder builder = PolyglotEngine.newBuilder();
builder.setArguments(Language1.class, args1);
builder.setArguments(Language2.class, args2);And then, the following would provide me with the correct protected VM createContext(final Env env) {
String[] args = env.getArguments();I need the arguments in |
|
This is now implemented in the last commit. |
There was a problem hiding this comment.
Alas, I don't think people should reference the implementation class of a language. They certainly don't have to do so now. Probably the language should be identified by a MIME type.
There was a problem hiding this comment.
Ok, used the MIME type. What's the reason for this? Potential class loading issues or something? Intuitively, I would assume that this kind of interaction still happens in tightly bound places, like a main method or something similar. You envision a more dynamic and modular use case?
|
Isn't the actual problem here that you can't get global symbol values back out without wrapper? |
2c6db24 to
d94f404
Compare
|
I think there are two separate concepts here:
So, I would argue we need this second way for implementation-level purpose only to pass data to a language implementation. Unifying these two ways does not seem the right solution for me, because this weakens the nice semantic properties we got for interop. |
|
@smarr: Good point. I was thinking that perhaps one might want to pass something else than a |
|
hm, yeah, I was only briefly thinking of other things than strings. Perhaps it should be just |
|
Right, this is the kind of discussion that lead me to believe there shouldn't be any generic setArguments. The languages may have different needs and it should be up to them to decide what data and in what format they want. I've created #11 to demonstrate how (simple) it feel to access array of parameters in current API. |
|
Ok, well, so there is at least one lesson we should learn from this. The current API is absolutely not discoverable, and the implementation is way to involved to get any idea of intentions. I am really suffering over here :( In your version #11, making the jump from |
|
I have a bug in codesnippets that I will fix on Monday. Then we will see... Right. The trick isn't easy to discover and that's the reason it took me so long and I had to test it first. |
|
Taking Andreas' comment into account, I generalized the String[] to an Object. Benefits of this vs. the Java Interop based approach:
|
|
Object == the JVM style of typing things. I don't like it. I've closed the #10 request, because I realized that in this case we don't want to wrap Java types into TruffleObject. Thus we need different method. Rather than setArguments, I'd however prefer: Builder Builder.config(String mimeType, String key, Object value);
Map<String,Object> Env.getConfig();I think this would work for your usecase as well and gives languages a chance to expose just names, not real objects. |
|
@jtulach I added the change to have the API structure like this: Builder Builder.config(String mimeType, String key, Object value);
Map<String,Object> Env.getConfig(); // can be called from createContext(), value is not wrappedAt the other languages (@woess, @ansalond, @eregon, @chrisseaton, @lukasstadler, @chumer), does this look useful/sufficient to you? |
|
We should improve our workflow. I've just added implementation of my request too: jtulach@32d4240 |
There was a problem hiding this comment.
Isn't this broken? I am getting exceptions from here. I suggest to use my version of the test - it uses just public methods.
There was a problem hiding this comment.
ok, will change the test. Do you have any strong opinions on the Map<> vs. List<> difference between my and your implementation?
|
Hm, ok, since I started the pull request, I assumed it to be my responsibility to fix the issues. |
03fe3f9 to
c837c70
Compare
There was a problem hiding this comment.
I don't think there is any use for two levels of the map. Just merge values for all mimetypes of a language together into one map.
|
For documentation: some discussion on the relationship between MIME types and config options: jtulach@32d4240#commitcomment-15653479 |
|
Ok, the latest change merges the per-mime-type options to per-language options from the view of the languages. Anything else left to do before a merge can be done? (at some point, I'll rebase the change set again on master) |
|
If you could use the codesnippet tag to enrich Javadoc of the two new methods with real sample, it would be great. Then I am ready to merge. |
|
Hm, perhaps this is me being lazy, but code examples for getter/setter methods? I mean, the javadoc references the two elements that belong together, which is very helpful. Don't know but code example feel too much here. |
|
OK. I'll do it myself and merge. |
|
Here is the state I am OK with: jtulach@f4756bf - can you pull the changeset and push it into your repository so we can reuse this pull request or shall I start a new one? |
This change allows to pass an array of strings to the polyglot engine and retrieve it in the enviroment object. Signed-off-by: Stefan Marr <git@stefan-marr.de>
Signed-off-by: Stefan Marr <git@stefan-marr.de>
Not sure what the technical reason is, perhaps to avoid class loading issues? These things seem still to be tightly coupled. Signed-off-by: Stefan Marr <git@stefan-marr.de>
This enables the languages to use for instance configuration objects and other structured data to represent initialization information. Signed-off-by: Stefan Marr <git@stefan-marr.de>
This allows the languages to structure their configuration based on different keys in a map. Signed-off-by: Stefan Marr <git@stefan-marr.de>
Adopted from jtulach@32d4240 Signed-off-by: Stefan Marr <git@stefan-marr.de>
Signed-off-by: Stefan Marr <git@stefan-marr.de>
Signed-off-by: Stefan Marr <git@stefan-marr.de>
Based on comments by @jtulach. Signed-off-by: Stefan Marr <git@stefan-marr.de>
This change merges the configuration options per language. Thus, if a language is associated with multiple mime types, it will see a merged map of configurations from these mime types. Signed-off-by: Stefan Marr <git@stefan-marr.de>
…eter use-case that initiated introduction of the config and getConfig methods.
2fe28bf to
752a346
Compare
Signed-off-by: Stefan Marr <git@stefan-marr.de>
…ngine Enable passing of arguments to the polyglot engine
…truffle:RelativeAndGlobalMX to master * commit 'f91c754ade0e67b399c5fb8bad3a09839ca7496e': If the local, relative mx can't be found, use the one from global PATH
Add compile file only method
* add matrix for building both 11 and 17 * fix matrix syntax * setup jdk * override jdk with labs jdk * fix zip paths and JAVA_HOME
Backport: Allow custom constructors for arrays and enums
This change allows to pass an array of strings to the polyglot engine and retrieve it in the environment object.
The goal is to provide a straight-forward way to pass implementation-level arguments, as the typically come from the command line to the
PolyglotEngineand the languages.At the moment, we need to jump through many many hoops.
To realize the same effect, in a language-specific way, it seems we need to do roughly the following:
we need some wrapper class to be able to get to the value later on in the language:
we need to pass the arguments to the engine. In the case of SOM, I need these arguments when creating the language context, because the context contains the object system, which depends on the source to be used. And, might also have instruments that need to be configured from the very start.
I believe, the whole notion of global TruffleObjects does not apply here because these arguments are strictly at the implementation level and not language-level objects. But even if there are arguments that become visible to the language, it is the languages job to figure that out and do the necessary wrapping.
in the
TruffleLanguage.createContext(...)method, I need to do this:All this is non-trivial for a very basic use case that any practical language would want to support: take some parameters to control its initialization process/startup.
With the provided patch, all this shrinks to:
I hope this is compelling enough for inclusion. I know the API should be minimal, but this is a super basic use case, and while there might be static-state solutions that are shorter than this, I believe we should provide an API that allows users to do 'the right thing' easily.
I am not entirely sure about my patch thought. The whole code based involved here is extremely complex and rather hard to comprehend. I mean, it adds about 40 lines of code for something very very trivial: another field + getter. I did not expect that much change for this simple feature.