org.snapscript.compile.assemble.ApplicationCompiler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.compile.assemble;
import java.util.concurrent.atomic.AtomicReference;
import org.snapscript.core.Context;
import org.snapscript.core.ContextValidator;
import org.snapscript.core.Execution;
import org.snapscript.core.Statement;
import org.snapscript.core.link.Package;
import org.snapscript.core.link.PackageDefinition;
import org.snapscript.core.scope.Scope;
public class ApplicationCompiler {
private final AtomicReference cache;
private final Package library;
private final Context context;
public ApplicationCompiler(Context context, Package library){
this.cache = new AtomicReference();
this.library = library;
this.context = context;
}
public Execution compile(Scope scope) throws Exception{
Execution execution = cache.get();
if(execution == null) {
ContextValidator validator = context.getValidator();
PackageDefinition definition = library.create(scope); // create all types
Statement statement = definition.define(scope, null); // define tree
Execution result = statement.compile(scope, null);
validator.validate(context); // validate program
cache.set(result);
return result;
}
return execution;
}
}