Skip to content

Commit

Permalink
Move code server to erlang source so we can bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Apr 23, 2012
1 parent 0e97683 commit b73fb76
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 76 deletions.
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ DIALYZER_WARNINGS = -Wunmatched_returns -Werror_handling \

ERL = erl -I include -noshell -pa ebin

EBIN_DIR=ebin
EXBIN_DIR=exbin
TEST_DIR=test
INCLUDE_DIR=include

TEST_SOURCE_DIR=$(TEST_DIR)/erlang
TEST_EBIN_DIR=$(TEST_DIR)/ebin

ERLC=erlc -I $(INCLUDE_DIR) -W0
ERL=erl -I $(INCLUDE_DIR) -noshell -pa $(EBIN_DIR)

# Variable definition expanded when it's declared
APP := elixir

Expand Down Expand Up @@ -47,7 +58,13 @@ docs: deps compile
test: test_erlang test_elixir

test_erlang: deps compile
@ $(REBAR) skip_deps=true eunit
@ echo "==> erlang (eunit)"
@ mkdir -p $(TEST_EBIN_DIR)
@ # Compile test files
@ $(ERLC) -o $(TEST_EBIN_DIR) $(TEST_SOURCE_DIR)/*.erl
@ # Look and execute each file
time $(ERL) $(TEST_EBIN_DIR) -pa exbin -s test_helper test -s erlang halt
@ echo

test_elixir: deps compile
@ echo "==> elixir (exunit)"
Expand Down
2 changes: 1 addition & 1 deletion bin/elixir
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ readlink_f () {

SELF=`readlink_f $0`
SCRIPT_PATH=`dirname $SELF`
erl -pa $SCRIPT_PATH/../ebin $SCRIPT_PATH/../exbin -noshell -noinput $ELIXIR_ERL_OPTS -s elixir start -extra "$@"
erl -pa $SCRIPT_PATH/../ebin $SCRIPT_PATH/../exbin -noshell -noinput $ELIXIR_ERL_OPTS -s elixir start_cli -extra "$@"
2 changes: 1 addition & 1 deletion bin/elixir.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ echo ** Options given after the .exs file or -- are passed down to the executed
echo.
echo ** Options can be passed to the erlang runtime using ELIXIR_ERL_OPTS.
:run
erl -pa %~dp0\..\ebin %~dp0\..\exbin -noshell -noinput %ELIXIR_ERL_OPTS% -s elixir start -extra %*
erl -pa %~dp0\..\ebin %~dp0\..\exbin -noshell -noinput %ELIXIR_ERL_OPTS% -s elixir start_cli -extra %*
51 changes: 0 additions & 51 deletions lib/elixir/server.ex

This file was deleted.

12 changes: 1 addition & 11 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
%% configure testing
{eunit_opts, []}.

%% configure compilation
{erl_opts, [
warn_unused_vars,
Expand All @@ -21,21 +18,14 @@
no_debug_info
]}.

%% enable verbos for yecc
%% enable verbose for yecc
{yrl_opts, [
{report, true},
{verbose, false}
]}.

%% enable verbose for Leex
{xrl_opts, [
{report, true},
{verbose, false}
]}.

{xref_checks, [undefined_function_calls]}.
{lib_dirs, ["exbin"]}.

{clean_files, ["exbin/"]}.

%% TODO: prepare scripts which should be
Expand Down
4 changes: 2 additions & 2 deletions src/elixir.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-module(elixir).
-behaviour(application).
-export([start/0, start_app/0,
-export([start_cli/0, start_app/0,
scope_for_eval/1, eval/2, eval/3, eval/4,
eval_quoted/2, eval_quoted/3, eval_quoted/4,
eval_forms/3]).
Expand Down Expand Up @@ -35,7 +35,7 @@ start_app() ->

% Boot and process given options. Invoked by Elixir's script.

start() ->
start_cli() ->
start_app(),
'__MAIN__.Elixir.CLI':process_argv(init:get_plain_arguments()).

Expand Down
57 changes: 57 additions & 0 deletions src/elixir_code_server.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-module(elixir_code_server).
-export([start_link/0, init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
-behavior(gen_server).
-record(elixir_code_server, {
argv=[],
loaded=[],
at_exit=[],
compiler_options=[]
}).

start_link() ->
{ ok, _ } = gen_server:start_link({local, elixir_code_server}, ?MODULE, [], []).

init(_args) ->
{ ok, #elixir_code_server{} }.

handle_call({loaded, Path}, _From, Config) ->
{ reply, ok, Config#elixir_code_server{loaded=[Path|Config#elixir_code_server.loaded]} };

handle_call({at_exit, AtExit}, _From, Config) ->
{ reply, ok, Config#elixir_code_server{at_exit=[AtExit|Config#elixir_code_server.at_exit]} };

handle_call({argv, Argv}, _From, Config) ->
{ reply, ok, Config#elixir_code_server{argv=Argv} };

handle_call({compiler_options, Options}, _From, Config) ->
{ reply, ok, Config#elixir_code_server{compiler_options=Options} };

handle_call(loaded, _From, Config) ->
{ reply, Config#elixir_code_server.loaded, Config };

handle_call(at_exit, _From, Config) ->
{ reply, Config#elixir_code_server.at_exit, Config };

handle_call(argv, _From, Config) ->
{ reply, Config#elixir_code_server.argv, Config };

handle_call(compiler_options, _From, Config) ->
{ reply, Config#elixir_code_server.compiler_options, Config };

handle_call(_Request, _From, Config) ->
{ reply, undef, Config }.

handle_cast(_Request, Config) ->
{ noreply, Config }.

handle_info(_Request, Config) ->
{ noreply, Config }.

terminate(Reason, Config) ->
io:format("[FATAL] ~p crashed:\n~p~n", [?MODULE, Reason]),
io:format("[FATAL] ~p snapshot:\n~p~n", [?MODULE, Config]),
ok.

code_change(_Old, Config, _Extra) ->
{ ok, Config }.
8 changes: 3 additions & 5 deletions src/elixir_compiler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ get_opt(Key, Dict) ->
end.

get_opts() ->
try
gen_server:call(elixir_code_server, compiler_options)
catch
exit:{ noproc, _ } -> [{internal,true}]
end.
gen_server:call(elixir_code_server, compiler_options).

%% Compile a file, return a tuple of module names and binaries.

Expand Down Expand Up @@ -120,6 +116,8 @@ module(Forms, Filename, Options, Callback) ->
%% Invoked from the Makefile.

core() ->
elixir:start_app(),
gen_server:call(elixir_code_server, { compiler_options, [{internal,true}] }),
[core_file(File) || File <- core_main()],
AllLists = [filelib:wildcard(Wildcard) || Wildcard <- core_list()],
Files = lists:append(AllLists) -- core_main(),
Expand Down
2 changes: 1 addition & 1 deletion src/elixir_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ init(Args) ->
Supervisors = [
{
elixir_code_server_sup,
{ '__MAIN__.Elixir.Server', start_link, Args },
{ elixir_code_server, start_link, Args },

permanent, % Restart = permanent | transient | temporary
2000, % Shutdown = brutal_kill | int() >= 0 | infinity
Expand Down
2 changes: 1 addition & 1 deletion test/elixir/module_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ defmodule ModuleTest do
end

test :reserved_attributes do
assert_equal {:behavior,[:gen_server]}, :lists.keyfind(:behavior, 1, Elixir.Server.__info__(:attributes))
assert_equal {:behavior,[:gen_server]}, :lists.keyfind(:behavior, 1, ExUnit.Server.__info__(:attributes))
end

test :registered_attributes do
Expand Down
4 changes: 2 additions & 2 deletions test/erlang/test_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
-export([test/0, run_and_remove/2, throw_elixir/1, throw_erlang/1]).

test() ->
elixir:start(),
elixir:start_app(),
eunit:test([
atom_test,
conditionals_test,
erlang_call_test,
function_test,
match_test,
namespace_test,
module_test,
operators_test,
record_test,
string_test,
Expand Down

0 comments on commit b73fb76

Please sign in to comment.