ilya.chernikov
01/04/2017, 7:41 PMscript-util
as long as they are clearly marked as examples of the engines/repl/scripting usage.
So, if it is still acceptable for you, please prepare PR about resettable repl - this looks nice and useful. And JSR 223 state in the binding - if this could be done independently from the scriptdef changes - is also nice and useful, I believe. But please let the core stuff intact right now. We can discuss deeper changes there later.apatrida
01/04/2017, 7:43 PMapatrida
01/04/2017, 7:50 PMgradle-script-kotlin
uses things at a lower level than these changes, but I don’t know what list of OTHER things in the world are already starting to use scripting API'sapatrida
01/04/2017, 7:50 PMapatrida
01/04/2017, 10:20 PMapatrida
01/04/2017, 10:20 PMapatrida
01/04/2017, 10:20 PMapatrida
01/04/2017, 10:22 PMapatrida
01/04/2017, 10:37 PM// evaluate JavaScript code that defines an object with one method
engine.eval("var obj = new Object()");
engine.eval("obj.hello = function(name) { print('Hello, ' + name) }");
// expose object defined in the script to the Java application
Object obj = engine.get("obj”);
apatrida
01/04/2017, 10:38 PMapatrida
01/04/2017, 10:38 PMvar obj = …
is really a put to the binding of name obj
value …
apatrida
01/04/2017, 10:38 PMapatrida
01/04/2017, 10:38 PMapatrida
01/04/2017, 10:39 PMapatrida
01/04/2017, 10:39 PMapatrida
01/04/2017, 10:39 PMallowing them to execute a previous line is possible again, and it would only affect newer lines if they are also re-executed, so you could doin Non-REPL mode: - scripts do not accumulate, they must read/write state to somewhere made available to them if they want to pass state between evals - scripts can execute and re-execute in any order and only side effect is based on,line 1
,line 2
(again),line 1
(again),line 1
(using state from old `line 2)),line 3
(again using state from newest line 1),line 2
(using state from newest line 3). This is an easy change, but not sure would confuse people, could be REPL-PLUS mode.line 3
THREADING
mode (and how it isolates or doesn’t the bindings)
in JSR 223 specific version of Non-REPL mode:
- variables have to auto store to the binding, and auto read from the bindings, and this is where state would be storedbox. Compiling would have to know about the current state of bindings to be able to check things, (or generate a before/after scriptlet to read/write to bindings without checking and act like fake lines). Since Compileable interface doesn’t know about bindings if you do compile-only you can’t check anything exists or not, will wait for runtime errors. If you do eval only then you could type check based on current state of the bindings at compile time. Although bindings can change later to cause issues on script re-execution. so re-execution must read-var-from-state into variables => execute script and make $$result available => also write-vars-back-to-state
This could be faked with pre/post scriptlets in between lines as a quick solution:
// renders out everything currently available in the bindings
class Line_1_before: Jsr223ScriptTemplate {
val x: Int = bindings.get(“x”) ?as Int ?: throw IllegalStateException(“binding 'x: Int' is missing from current context”)
val y: Int = bindings.get(“y”) ?as String ?: throw IllegalStateException(“binding 'x: String' is missing from current context”)
}
class line_1(val line_1_before: Line_1_before): Jsr223ScriptTemplate {
// normal stuff, it would access .x and .y from the line_1_before as-if it was a previous line and would let the compiler generate errors based on what is there or not, assuming eval() without a separate compile
val z: String = expression...
}
class Line_1_after(val line_1: Line_1): Jsr223ScriptTemplate {
init {
bindings.put(“z”, line_1.z)
}
}
of course you could do it all in one class with more internal logic.ilya.chernikov
01/04/2017, 10:51 PMilya.chernikov
01/04/2017, 10:53 PMilya.chernikov
01/04/2017, 10:53 PMapatrida
01/04/2017, 10:54 PMilya.chernikov
01/04/2017, 10:55 PMapatrida
01/04/2017, 10:55 PMCompileable
separately the REPL model isn’t too far off. But with Compileable
it would break because you don’t care about order in JSR223 like we do.apatrida
01/04/2017, 10:56 PMapatrida
01/04/2017, 10:56 PMapatrida
01/04/2017, 10:57 PMapatrida
01/04/2017, 10:58 PMilya.chernikov
01/04/2017, 10:58 PMapatrida
01/04/2017, 10:59 PMapatrida
01/04/2017, 11:00 PMapatrida
01/04/2017, 11:00 PM