Skip to content

Commit

Permalink
om:type -> om:term, bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Mar 3, 2016
1 parent 6eebeb8 commit c7a5a3b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
17 changes: 12 additions & 5 deletions src/om.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ stop(_) -> ok.
modes() -> ["erased","girard","hurkens","normal","setoids"].
mode(S) -> application:set_env(om,mode,S).
mode() -> application:get_env(om,mode,"erased").
init([]) -> {ok, {{one_for_one, 5, 10}, []}}.
type(F) -> T = string:tokens(F,"/"), P = string:join(rev(tl(rev(T))),"/"), type(P,lists:last(T)).
type(P,F) -> case parse(P,F) of {[],error} -> parse([],F); {[],[]} -> {[],error}; {[],[X]} -> X end.
init([]) -> mode("normal"), {ok, {{one_for_one, 5, 10}, []}}.
term(F) -> T = string:tokens(F,"/"), P = string:join(rev(tl(rev(T))),"/"), term(P,lists:last(T)).
term(P,F) -> case parse(P,F) of {[],error} -> parse([],F); {[],[]} -> {[],error}; {[],[X]} -> X end.
parse(P,F) -> try om_parse:expr(P,read(P,string:join(["priv",mode(),P,F],"/")),[]) catch E:R ->
% io:format("ERROR: file: ~tp~n~tp~n",[erlang:get_stacktrace(),R]),
{[],error} end.
str(P,F) -> om_tok:tokens(P,unicode:characters_to_binary(F),0,{1,[]},[]).
a(F) -> {[],[X]} = om_parse:expr([],om_tok:tokens([],unicode:characters_to_binary(F),0,{1,[]},[]),[]), X.
read(P,F) -> om_tok:tokens(P,file(F),0,{1,[]},[]).
file(F) -> {ok,Bin} = read_file(F), Bin.
all() -> lists:flatten([ begin om:mode(M), om:scan() end || M <- modes() ]).
scan() -> Res = [ {element(1,show(F))/=[],F} || F <- filelib:wildcard(string:join(["priv",mode(),"**","*"],"/")), filelib:is_dir(F) /= true ],
error("Tests: ~tp~n",[Res]),
Expand All @@ -32,7 +31,7 @@ scan() -> Res = [ {element(1,show(F))/=[],F} || F <- filelib:wildcard(strin
true -> error("PASSED~n",[]);
false -> error("FAILED~n",[]) end,
Res.
show(F) -> T = string:substr(string:tokens(F,"/"),3), Type = type(string:join(T,"/")),
show(F) -> T = string:substr(string:tokens(F,"/"),3), Type = term(string:join(T,"/")),
error("~n===[ File: ~ts ]==========~nCat: ~tsTerm: ~100tp~n",[F,file(F),size(term_to_binary(Type))]), Type.


Expand All @@ -47,3 +46,11 @@ read_file(F) -> file:read_file(F).
atom(X) -> list_to_atom(X).
last(X) -> lists:last(X).


file(F) -> Raw = case file:read_file(F) of
{ok,Bin} -> Bin;
{error,_} -> mad(F) end.

mad(F) -> case mad_repl:load_file(F) of
{ok,Bin} -> Bin;
{error,_} -> <<>> end.
2 changes: 1 addition & 1 deletion src/om_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ subst(X,N,EP,Else) -> Else.

test() -> lists:all(fun assert/1,lists:seq(1,10)).

assert(1) -> freeIn({var,{'Head',0}},om:type("List/Cons")) == true;
assert(1) -> freeIn({var,{'Head',0}},om:term("List/Cons")) == true;
assert(_) -> true.

4 changes: 2 additions & 2 deletions src/om_extract.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ extract(X) -> Last = om:last(string:tokens(X,"/")),
++ [ begin Name = string:join([Last,F],"/"),
mad:info("Ctor: ~tp~n",[Name]),
om:show(string:join([X,F],"/")),
Erased = case om:mode() of "erased" -> om:type(Name);
_ -> erasure(F,om:type(Name),1) end,
Erased = case om:mode() of "erased" -> om:term(Name);
_ -> erasure(F,om:term(Name),1) end,
mad:info("Erased: ~tp~n",[Erased]),
Extract = extract(F,Erased,1),
mad:info("Tree: ~tp~n",[Extract]),
Expand Down
4 changes: 2 additions & 2 deletions src/om_parse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

expr(P,[], Acc) -> rewind(Acc,[],[]);
expr(P,[close |T], Acc) -> {T1,Acc1} = rewind(Acc, T,[]), expr(P,T1,Acc1);
expr(P,[{remote,{X,L}} |T], Acc) -> expr(P,T,[ret(om:type(X,L))|Acc]);
expr(P,[{remote,L} |T], Acc) -> expr(P,T,[om:type(L)|Acc]);
expr(P,[{remote,{X,L}} |T], Acc) -> expr(P,T,[ret(om:term([],L))|Acc]);
expr(P,[{remote,L} |T], Acc) -> expr(P,T,[om:term(L)|Acc]);
expr(P,[{star,I} |T], Acc) -> expr(P,T,[{star,I}|Acc]);
expr(P,[{N,X}|T], [{typevar,Y}| Acc]) -> expr(P,T,[{N,X},{typevar,Y}|Acc]);
expr(P,[{N,X}|T], [{C,Y}| Acc]) -> expr(P,T,[{app,{{C,Y},{N,X}}}|Acc]);
Expand Down

0 comments on commit c7a5a3b

Please sign in to comment.