This commit is contained in:
@@ -59,6 +59,8 @@ public class Compilers {
|
||||
|
||||
public static Compiler transpilerFromSource(Compiler prev, Environment target, Filename compilerName, String compilerSrc) {
|
||||
var env = StdLib.apply(null);
|
||||
// var handler = new SimpleDebugHandler();
|
||||
// env.add(DebugHandler.KEY, handler);
|
||||
|
||||
var glob = Value.global(env);
|
||||
var compilerFactory = new FunctionValue[1];
|
||||
@@ -83,9 +85,19 @@ public class Compilers {
|
||||
}));
|
||||
|
||||
var compiled = JavaScript.compile(compilerName, compilerSrc, false);
|
||||
new CodeFunction(env, "intializer", compiled.body(), new Value[0][]).apply(env, Value.UNDEFINED);
|
||||
|
||||
return wrap(prev, env, target, compilerFactory[0]);
|
||||
// for (var el : compiled.all()) {
|
||||
// handler.onFunctionLoad(el.body(), el.map());
|
||||
// }
|
||||
|
||||
try {
|
||||
new CodeFunction(env, "intializer", compiled.body(), new Value[0][]).apply(env, Value.UNDEFINED);
|
||||
return wrap(prev, env, target, compilerFactory[0]);
|
||||
}
|
||||
catch (EngineException e) {
|
||||
System.out.println(Value.errorToReadable(env, e, "in transpiler initializer"));
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
|
||||
public static Compiler babelCompiler(Compiler prev, Environment target) {
|
||||
@@ -111,7 +123,7 @@ public class Compilers {
|
||||
Compiler create(Compiler prev, Environment target);
|
||||
}
|
||||
|
||||
public static Compiler chainTranspilers(Environment target, Compiler base, TranspilerFactory ...factories) {
|
||||
public static Compiler chainTranspilers(Compiler base, Environment target, TranspilerFactory ...factories) {
|
||||
var res = base;
|
||||
|
||||
for (var el : factories) {
|
||||
|
||||
@@ -6,24 +6,36 @@ import me.topchetoeu.j2s.common.Metadata;
|
||||
import me.topchetoeu.j2s.common.Reading;
|
||||
import me.topchetoeu.j2s.compilation.CompileResult;
|
||||
import me.topchetoeu.j2s.compilation.JavaScript;
|
||||
import me.topchetoeu.j2s.runtime.exceptions.EngineException;
|
||||
import me.topchetoeu.j2s.runtime.values.Value;
|
||||
import me.topchetoeu.j2s.runtime.values.functions.CodeFunction;
|
||||
|
||||
public class StdLib {
|
||||
private static final CompileResult RUNNER = JavaScript.compile(new Filename(Metadata.name(), "init.js"), Reading.resourceToString("lib/stdlib.js"), false);
|
||||
private static final CompileResult RUNNER = JavaScript.compile(
|
||||
new Filename(Metadata.name(), "init.js"),
|
||||
Reading.resourceToString("lib/stdlib.js"), false
|
||||
);
|
||||
|
||||
public static Environment apply(Environment env) {
|
||||
if (env == null) {
|
||||
env = new Environment();
|
||||
}
|
||||
public static Environment apply(Environment env, CompileResult body) {
|
||||
env = new Environment();
|
||||
|
||||
var stubEnv = new Environment();
|
||||
Value.global(stubEnv).defineOwnField(stubEnv, "target", Value.global(env));
|
||||
Value.global(stubEnv).defineOwnField(stubEnv, "primordials", Primordials.create(env));
|
||||
|
||||
var func = new CodeFunction(stubEnv, "intializer", RUNNER.body(), new Value[0][]);
|
||||
func.apply(stubEnv, Value.UNDEFINED);
|
||||
|
||||
var func = new CodeFunction(stubEnv, "intializer", body.body(), new Value[0][]);
|
||||
try {
|
||||
func.apply(stubEnv, Value.UNDEFINED);
|
||||
}
|
||||
catch (EngineException e) {
|
||||
System.out.println(Value.errorToReadable(env, e, "in environment initializer"));
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
public static Environment apply(Environment env) {
|
||||
if (env == null) env = new Environment();
|
||||
return apply(env, RUNNER);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user