         :io.put_chars(:standard_error, message)
       end
     end
+
+    {:module, ^name, binary, _} = Module.create(name, module_body, Macro.Env.location(__ENV__))
+    [{'#{name}.beam', binary}]
+  end
+
+  defp main_body_for(:elixir) do
+    quote do
+      case :application.ensure_all_started(:elixir) do
+        {:ok, _} ->
+          load_config(@config)
+          start_app(@app)
+          args = Enum.map(args, &List.to_string(&1))
+          Kernel.CLI.run fn _ -> @module.main(args) end, true
+        _ ->
+          :io.put_chars :standard_error, "Elixir is not available, aborting.\n"
+          :erlang.halt(1)
+      end
+    end
+  end
+
+  defp main_body_for(:erlang) do
+    quote do
+      load_config(@config)
+      start_app(@app)
+      @module.main(args)
+    end
   end
 end

        case :application.ensure_all_started(app) do
          {:ok, _} -> :ok
          {:error, {app, reason}} ->
            io_error ["Could not start application #{app}: ",
                                              :io_lib.format('~p~n', [reason])]
            :erlang.halt(1)
        end
      end

      @config unquote(config)
      @app unquote(app)

      def main(args) do
        unquote(main_body_for(language))
      end

      defp load_config(config) do
