package hypernova;

import java.util.Map.Entry;
import com.google.common.primitives.Doubles;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Map;
import java.util.HashMap;
import java.io.InputStream;

import clojure.lang.RT;
import clojure.lang.Var;
import clojure.lang.Binding;
import clojure.lang.Compiler;
import clojure.lang.Symbol;
import clojure.lang.PersistentHashMap;
import clojure.lang.Associative;
import clojure.lang.Namespace;

import org.apache.log4j.Logger;

public class ActivityRuntime {
    private static Logger log = Logger.getLogger("ActivityRuntime");

    private Symbol CLOJURE_MAIN;
    private Var REQUIRE;

    private Symbol API;
    private Var API_LOADER;

    private static ActivityRuntime INSTANCE = null;

    private ActivityRuntime() throws Exception {
	CLOJURE_MAIN = Symbol.intern("clojure.main");
	REQUIRE = RT.var("clojure.core", "require");
	API = Symbol.intern("hypernova.activities.api");

	REQUIRE.invoke(CLOJURE_MAIN);
	REQUIRE.invoke(API);

	API_LOADER = RT.var("hypernova.activities.api", "loader");
    }

    public static ActivityRuntime get() {
	if(INSTANCE == null) {
	    try {
		INSTANCE = new ActivityRuntime();
	    } catch (Exception ex) {
		System.out.println("baddness! " + ex);
		System.exit(1);
	    }
	}

	return INSTANCE;
    }

    public void execute(Activity activity, Double x, Double y) {
	try {
	    Object result = API_LOADER.applyTo(RT.seq(RT.vector(activity.getScript(), x, y)));
	    System.out.println("result: " + result);
	} catch (Exception ex) {
	    System.out.println("something went poorly: " + ex);
	    System.exit(1);
	}
    }
}

@@ -1629,11 +1629,393 @@
 %09%7D%0A    %7D
+%0A%0A    public void startRepl() %7B%0A        log.info(%22Starting a REPL%22);%0A        new Thread() %7B%0A            @Override%0A            public void run() %7B%0A                try %7B%0A                    clojure.lang.Repl.main(new String%5B0%5D);%0A                %7D catch (Exception e) %7B%0A                    log.warn(%22REPL threw exception %22 + e);%0A                %7D%0A            %7D%0A        %7D.start();%0A    %7D
 %0A%7D%0A

Add a startRepl() method to ActivityRuntime.