Changeset 62
- Timestamp:
- 07/13/09 05:34:59 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
-
compiler.erl (modified) (2 diffs)
-
compiler_test.erl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/compiler.erl
r61 r62 25 25 compile (Notify, Watcher, _, Modules) -> 26 26 notify_totals (Modules, Notify), 27 {Processed, _} = dict: fold (fun process/3, {Modules, Notify}, Modules), 27 Init = {Modules, Notify, []}, 28 {Processed, _, Binaries} = dict: fold (fun process/3, Init, Modules), 29 notify_binaries (Binaries, Notify), 28 30 loop (Notify, Watcher, Processed). 29 31 30 process (File, found, {Modules, Notify }) ->32 process (File, found, {Modules, Notify, Binaries}) -> 31 33 Result = modules: compile (File), 32 34 notify_result (Result, Notify), 33 35 New_modules = dict: store (File, Result, Modules), 34 36 notify_totals (New_modules, Notify), 35 {New_modules, Notify}; 37 New_binaries = binaries (Result, Binaries), 38 {New_modules, Notify, New_binaries}; 36 39 process (_, _, Acc) -> 37 40 Acc. … … 57 60 notify_result ({error, Errors, Warnings},Notify) -> 58 61 Notify ({Errors, Warnings}). 62 63 binaries (_, errors) -> 64 errors; 65 binaries ({ok, _, B, _}, Bs) -> 66 [B | Bs]; 67 binaries ({error, _, _}, _) -> 68 errors. 69 70 notify_binaries (errors, _) -> 71 pass; 72 notify_binaries (Bs, Notify) when is_list (Bs) -> 73 Notify ({binaries, Bs}). -
trunk/src/compiler_test.erl
r61 r62 5 5 -module (compiler_test). 6 6 -test (exports). 7 -export ([compiles_and_reports_progress/0]). 7 -export ([compiles_and_reports_progress_warnings_and_errors/0]). 8 -export ([provides_binaries_when_all_compiled/0]). 8 9 -include_lib("stdlib/include/ms_transform.hrl"). 9 10 10 compiles_and_reports_progress () -> 11 %% dbg:tracer(), 12 %% dbg:p(new,c), 13 %% dbg:tpl(compiler, dbg:fun2ms(fun(_)->return_trace() end)), 14 %% dbg:tpl(modules, dbg:fun2ms(fun(_)->return_trace() end)), 11 compiles_and_reports_progress_warnings_and_errors () -> 15 12 Compiler = spawn_link (compiler, init, [notify_me (), "fix"]), 16 13 Ms = receive_all (), 17 14 Compiler ! stop, 18 15 ok = check (Ms, unknown). 16 17 provides_binaries_when_all_compiled () -> 18 F = fun provides_binaries_when_all_compiled/2, 19 ok = fixtures: use_tree (good_erl_tree (), F). 20 21 provides_binaries_when_all_compiled (Root, _) -> 22 Compiler = spawn_link (compiler, init, [notify_me (), Root]), 23 Ms = receive_all (), 24 Compiler ! stop, 25 ok = check (Ms, unknown), 26 {binaries, Bs} = lists: last (Ms), 27 Chunks = [ beam_lib: chunks (B, [exports]) || B <- Bs], 28 Modules = [M || {ok, {M, [{exports, [_, _, {run, 0}]}]}} <- Chunks], 29 [gdbye, hello] = lists: sort (Modules), 30 ok. 31 32 %% stops 33 34 %% empty tree 35 19 36 20 37 check ([{Total, 0, 0} | _] = Xs, unknown) -> … … 29 46 when M2 == M1+1, N2 == N1 -> 30 47 check ([X | Xs], Total); 31 check ([{Total, Total, N}], Total) when N =< Total -> 48 check ([{Total, Total, N}], Total) when N < Total -> 49 ok; 50 check ([{Total, Total, Total}, {binaries, _}], Total) -> 32 51 ok. 52 53 good_erl_tree () -> 54 [{file, "hello.erl", "-module(hello). -export([run/0]). run()->hello."}, 55 {file, "gdbye.erl", "-module(gdbye). -export([run/0]). run()->gdbye."}]. 33 56 34 57 notify_me () ->
Note: See TracChangeset
for help on using the changeset viewer.
