     stdin = -> "\n"
     class_args = [ fname ]
     exec_finish_cb = ->
+         root.rs = null
          console.log 'Done'
     compile_finished_cb  = ->
+        root.rs = null
         if msg.length ==0
             root.exec stdout, stdin, cname, class_args, exec_finish_cb
     root.compile stdout, fname, compile_finished_cb

root.preload = ->
    load_mini_rt()
    init_editor()
    $('#run_btn').click (e) ->
        compileAndRun()
        e.preventDefault()

$(document).ready ->
    root.preload()


root.saveFile = (fname,contents) ->
    contents += '\n' unless contents[contents.length-1] == '\n'

    start_compile=(new Date()).getTime()
    jvm.set_classpath '/home/doppio/vendor/classes/', './:/home/doppio'
    user_input = (resume) -> resume ''

    rs = new runtime.RuntimeState(stdout, user_input, root.bs_cl)
    root.rs = rs
    args = [ fname ]
    my_cb = (success) ->
        end_compile=(new Date()).getTime()
        root.rs = null
        console.log "javac took a total of #{end_compile-start_compile}ms."
        if success
            $('#messages').text 'Compilation complete'
        else
            $('#messages').text ''
        finish_cb()
    useECJ = true
    if useECJ
        jvm.system_properties['jdt.compiler.useSingleThread'] = true
        #Could play with -noExit too
        jvm.run_class rs, 'org/eclipse/jdt/internal/compiler/batch/Main', args, my_cb
    else 
        jvm.run_class rs, 'classes/util/Javac', args, my_cb
    return

root.exec = (stdout,stdin, class_name,class_args, finish_cb) ->
    $('#messages').text "Running #{class_name}"
    rs = new runtime.RuntimeState(stdout, stdin, root.bs_cl)
    jvm.run_class(rs, class_name, class_args, finish_cb)
    $('#messages').text ''
    return
