Révision 2123
tmp/org.txm.ocaml.core/src/org/txm/ocaml/core/OcamlScriptEngine.java (revision 2123) | ||
---|---|---|
1 |
package org.txm.ocaml.core; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.HashMap; |
|
7 |
|
|
8 |
import javax.script.ScriptContext; |
|
9 |
import javax.script.ScriptEngineManager; |
|
10 |
import javax.script.ScriptException; |
|
11 |
|
|
12 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
13 |
import org.eclipse.core.runtime.IStatus; |
|
14 |
import org.eclipse.core.runtime.Status; |
|
15 |
import org.ocamljava.runtime.support.scripting.OCamlContext; |
|
16 |
import org.txm.core.engines.ScriptEngine; |
|
17 |
import org.txm.utils.io.IOUtils; |
|
18 |
|
|
19 |
public class OcamlScriptEngine extends ScriptEngine { |
|
20 |
|
|
21 |
public OcamlScriptEngine() { |
|
22 |
super("ml"); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public boolean isRunning() { |
|
27 |
return true; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public boolean initialize() throws Exception { |
|
32 |
return true; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public boolean start(IProgressMonitor monitor) throws Exception { |
|
37 |
return true; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public boolean stop() throws Exception { |
|
42 |
return true; |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public IStatus executeScript(File script, HashMap<String, Object> env) { |
|
47 |
String cmd; |
|
48 |
try { |
|
49 |
cmd = IOUtils.getText(script, "UTF-8"); |
|
50 |
return executeText(cmd, env); |
|
51 |
} catch (IOException e) { |
|
52 |
e.printStackTrace(); |
|
53 |
return Status.CANCEL_STATUS; |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public IStatus executeText(String cmd, HashMap<String, Object> env) { |
|
59 |
|
|
60 |
final ScriptEngineManager manager = new ScriptEngineManager(); |
|
61 |
final javax.script.ScriptEngine engine = manager.getEngineByName("OCaml"); |
|
62 |
final ScriptContext ctxt = new OCamlContext(); |
|
63 |
ctxt.getBindings(ScriptContext.ENGINE_SCOPE).put("env", env); |
|
64 |
try { |
|
65 |
engine.eval(cmd, ctxt); |
|
66 |
return Status.OK_STATUS; |
|
67 |
} catch (ScriptException e) { |
|
68 |
// TODO Auto-generated catch block |
|
69 |
e.printStackTrace(); |
|
70 |
return Status.CANCEL_STATUS; |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
private static IStatus run(ArrayList<String> cmd, HashMap<String, Object> env) { |
|
75 |
return Status.OK_STATUS; |
|
76 |
} |
|
77 |
|
|
78 |
public static void main(String args[]) { |
|
79 |
ArrayList<String> cmd = new ArrayList<String>(); |
|
80 |
run(cmd, null); |
|
81 |
} |
|
82 |
} |
|
0 | 83 |
tmp/org.txm.ocaml.core/src/org/txm/ocaml/core/SimpleInterpreted.java (revision 2123) | ||
---|---|---|
1 |
package org.txm.ocaml.core; |
|
2 |
import javax.script.*; |
|
3 |
import org.ocamljava.runtime.support.scripting.OCamlContext; |
|
4 |
import org.ocamljava.runtime.support.scripting.OCamlScriptEngine; |
|
5 |
import org.ocamljava.runtime.support.scripting.OCamlScriptEngineFactory; |
|
6 |
|
|
7 |
public final class SimpleInterpreted { |
|
8 |
|
|
9 |
private static final String SCRIPT = |
|
10 |
"external get_binding : string -> 'a = \"script_get_binding\";;\n" + |
|
11 |
"let n = Int32.to_int (get_binding \"repetitions\");;\n" + |
|
12 |
"let s : string = get_binding \"message\";;\n" + |
|
13 |
"for i = 1 to n do print_endline s done;;\n"; |
|
14 |
|
|
15 |
public static void main(final String[] args) throws Throwable { |
|
16 |
final ScriptEngineManager manager = new ScriptEngineManager(); |
|
17 |
final ScriptEngine engine = manager.getEngineByName("OCaml"); |
|
18 |
final ScriptContext ctxt = new OCamlContext(); |
|
19 |
ctxt.getBindings(ScriptContext.ENGINE_SCOPE).put("repetitions", 3); |
|
20 |
ctxt.getBindings(ScriptContext.ENGINE_SCOPE).put("message", "hello!!!"); |
|
21 |
engine.eval(SCRIPT, ctxt); |
|
22 |
} |
|
23 |
} |
|
0 | 24 |
tmp/org.txm.ocaml.core/build.properties (revision 2123) | ||
---|---|---|
1 |
output.. = bin/ |
|
2 |
bin.includes = META-INF/,\ |
|
3 |
plugin.xml,\ |
|
4 |
.,\ |
|
5 |
lib/ocamlrun-scripting.jar,\ |
|
6 |
lib/ocaml-lib-files.jar |
|
7 |
jars.compile.order = |
|
8 |
source.. = src/ |
|
0 | 9 |
tmp/org.txm.ocaml.core/plugin.xml (revision 2123) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
<extension |
|
5 |
point="org.txm.core.engines.ScriptEngine"> |
|
6 |
<ScriptEngine |
|
7 |
class="org.txm.ocaml.core.OcamlScriptEngine" |
|
8 |
name="ml"> |
|
9 |
</ScriptEngine> |
|
10 |
</extension> |
|
11 |
|
|
12 |
</plugin> |
|
0 | 13 |
tmp/org.txm.ocaml.core/.settings/org.eclipse.jdt.core.prefs (revision 2123) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.7 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.7 |
|
0 | 8 |
tmp/org.txm.ocaml.core/.classpath (revision 2123) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry exported="true" kind="lib" path="lib/ocaml-lib-files.jar"/> |
|
4 |
<classpathentry exported="true" kind="lib" path="lib/ocamlrun-scripting.jar"/> |
|
5 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> |
|
6 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> |
|
7 |
<accessrules> |
|
8 |
<accessrule kind="accessible" pattern="**"/> |
|
9 |
</accessrules> |
|
10 |
</classpathentry> |
|
11 |
<classpathentry kind="src" path="src"/> |
|
12 |
<classpathentry kind="output" path="bin"/> |
|
13 |
</classpath> |
|
0 | 14 |
tmp/org.txm.ocaml.core/META-INF/MANIFEST.MF (revision 2123) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: Ocaml |
|
4 |
Bundle-SymbolicName: org.txm.ocaml.core;singleton:=true |
|
5 |
Bundle-Version: 2.0 |
|
6 |
Automatic-Module-Name: org.txm.libs.ocaml |
|
7 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 |
|
8 |
Export-Package: ., |
|
9 |
org.ocamljava.runtime, |
|
10 |
org.ocamljava.runtime.annotations.markers, |
|
11 |
org.ocamljava.runtime.annotations.parameters, |
|
12 |
org.ocamljava.runtime.annotations.primitives, |
|
13 |
org.ocamljava.runtime.context, |
|
14 |
org.ocamljava.runtime.gui, |
|
15 |
org.ocamljava.runtime.kernel, |
|
16 |
org.ocamljava.runtime.parameters, |
|
17 |
org.ocamljava.runtime.primitives.externallibs.zip, |
|
18 |
org.ocamljava.runtime.primitives.javalibs.concurrent, |
|
19 |
org.ocamljava.runtime.primitives.javalibs.javabase, |
|
20 |
org.ocamljava.runtime.primitives.otherlibs.bigarray, |
|
21 |
org.ocamljava.runtime.primitives.otherlibs.graph, |
|
22 |
org.ocamljava.runtime.primitives.otherlibs.num, |
|
23 |
org.ocamljava.runtime.primitives.otherlibs.str, |
|
24 |
org.ocamljava.runtime.primitives.otherlibs.systhreads, |
|
25 |
org.ocamljava.runtime.primitives.otherlibs.threads, |
|
26 |
org.ocamljava.runtime.primitives.otherlibs.unix, |
|
27 |
org.ocamljava.runtime.primitives.stdlib, |
|
28 |
org.ocamljava.runtime.support.applet, |
|
29 |
org.ocamljava.runtime.support.scripting, |
|
30 |
org.ocamljava.runtime.support.servlet, |
|
31 |
org.ocamljava.runtime.support.toplevel, |
|
32 |
org.ocamljava.runtime.util, |
|
33 |
org.ocamljava.runtime.values, |
|
34 |
org.ocamljava.runtime.wrappers, |
|
35 |
org.txm.ocaml.core |
|
36 |
Require-Bundle: org.txm.core, |
|
37 |
org.eclipse.core.runtime |
|
38 |
Bundle-ClassPath: ., |
|
39 |
lib/ocamlrun-scripting.jar, |
|
40 |
lib/ocaml-lib-files.jar |
|
0 | 41 |
tmp/org.txm.ocaml.core/.project (revision 2123) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.ocaml.core</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
tmp/org.txm.ocaml.core/lib/README (revision 2123) | ||
---|---|---|
1 |
add ocaml-lib-files.jar file -> ~50mo |
|
0 | 2 |
Formats disponibles : Unified diff