Browse Source

ft: utCompileStr.erl 完善

master
SisMaker 3 years ago
parent
commit
18c45b9e1e
4 changed files with 35 additions and 86 deletions
  1. +2
    -2
      rebar.config
  2. +1
    -1
      src/comMisc/utMisc.erl
  3. +19
    -23
      src/compile/utCompileStr.erl
  4. +13
    -60
      src/dataType/eLfq.erl

+ 2
- 2
rebar.config View File

@ -4,8 +4,8 @@
{eSync, ".*", {git, "http://sismaker.tpddns.cn:53000/SisMaker/eSync.git", {branch, "master"}}}
]}.
% {pre_hooks,
% [{"", compile, "escript c_src/eNpc compile"}]}.
% {pre_hooks,
% [{"", compile, "escript c_src/eNpc compile"}]}.
%
% {post_hooks,
% [{"", clean, "escript c_src/eNpc clean"}]}.

+ 1
- 1
src/comMisc/utMisc.erl View File

@ -63,7 +63,7 @@ compile_base_data(Table, ModName, IDPoses) ->
FinalString = HeadString ++ ContentString ++ ErrorString,
%% ?PRINT("string=~s~n",[FinalString]),
try
{Mod, Code} = dynamic_compile:from_string(FinalString),
{Mod, Code} = utCompileStr:comStr(FinalString),
code:load_binary(Mod, ModNameString ++ ".erl", Code)
catch
Type:Error -> io:format("Error compiling (~p): ~p~n", [Type, Error])

+ 19
- 23
src/compile/utCompileStr.erl View File

@ -61,8 +61,8 @@ formsStr(CodeStr, CompileFormsOpts) ->
IncludePath = ["." | reverse([Dir || {i, Dir} <- CompileFormsOpts])],
case scanAndParse(CodeStr, Filename, 1, [], [], #{}, IncludePath) of
{ok, RevForms, _OutMacroDict} ->
Forms = [{attribute, 0, file, {"compiled_from_string", 0}} | reverse([{eof, 0} | RevForms])],
{ok, RevForms, _OutMacroMap} ->
Forms = reverse(RevForms),
%% note: 'binary' is forced as an implicit option, whether it is provided or not.
case compile:forms(Forms, CompileFormsOpts) of
@ -73,7 +73,7 @@ formsStr(CodeStr, CompileFormsOpts) ->
{error, [{_, Errors}], Warnings} ->
{error, Errors, Warnings};
Other ->
{error, Other, []}
{error, {bat_return, Other}}
end;
{error, Errors} ->
{error, Errors, []}
@ -98,12 +98,12 @@ scanAndParse(RemainingText, CurrFilename, CurrLine, RevForms, Errors, MacroMap,
{error, E} ->
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, [E | Errors], MacroMap, IncludeSearchPath)
end;
{macro, NLine, NRemainingText, NMacroDict} ->
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroDict, IncludeSearchPath);
{Def, NLine, NRemainingText, NMacroDict} when Def =:= def; Def =:= endif; Def =:= else;Def =:= undef; Def =:= attribute; Def =:= vsn ->
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroDict, IncludeSearchPath);
{vsn, NLine, NRemainingText, NMacroDict} ->
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroDict, IncludeSearchPath);
{macro, NLine, NRemainingText, NMacroMap} ->
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroMap, IncludeSearchPath);
{Def, NLine, NRemainingText, NMacroMap} when Def =:= def; Def =:= endif; Def =:= else;Def =:= undef; Def =:= attribute; Def =:= vsn ->
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroMap, IncludeSearchPath);
{vsn, NLine, NRemainingText, NMacroMap} ->
scanAndParse(NRemainingText, CurrFilename, NLine, RevForms, Errors, NMacroMap, IncludeSearchPath);
{Include, NLine, NRemainingText, IncludeFilename} when Include =:= include; Include =:= include_lib ->
{IncludeCurrentFile, IncludeFileRemainingTextents} =
case Include of
@ -115,17 +115,15 @@ scanAndParse(RemainingText, CurrFilename, CurrLine, RevForms, Errors, MacroMap,
%%io:format("include file ~p contents: ~n~p~nRemainingText = ~p~n", [IncludeFilename,IncludeFileRemainingTextents, RemainingText]),
%% Modify the FILE macro to reflect the filename
%%IncludeMacroDict = dict:store('FILE', {[],IncludeFilename}, MacroMap),
IncludeMacroDict = MacroMap,
IncludeMacroMap = MacroMap,
%% Process the header file (inc. any nested header files)
{ok, RevIncludeForms, IncludedMacroDict} = scanAndParse(IncludeFileRemainingTextents, IncludeCurrentFile, 1, [], Errors, IncludeMacroDict, IncludeSearchPath),
{ok, RevIncludeForms, IncludedMacroMap} = scanAndParse(IncludeFileRemainingTextents, IncludeCurrentFile, 1, [], Errors, IncludeMacroMap, IncludeSearchPath),
%io:format("include file results = ~p~n", [R]),
%% Restore the FILE macro in the NEW MacroMap (so we keep any macros defined in the header file)
%%NMacroDict = dict:store('FILE', {[],CurrFilename}, IncludedMacroDict),
NMacroDict = IncludedMacroDict,
NMacroMap = IncludedMacroMap,
%% Continue with the original file
scanAndParse(NRemainingText, CurrFilename, NLine, RevIncludeForms ++ RevForms, Errors, NMacroDict, IncludeSearchPath);
scanAndParse(NRemainingText, CurrFilename, NLine, RevIncludeForms ++ RevForms, Errors, NMacroMap, IncludeSearchPath);
{continue, Continuation} ->
scanAndParse([], CurrFilename, CurrLine, [Continuation | RevForms], Errors, MacroMap, IncludeSearchPath);
done ->
@ -138,8 +136,8 @@ scanner(Text, Line, MacroMap) ->
case preProc(Tokens, MacroMap) of
{tokens, NToks} ->
{tokens, NLine, LeftOverChars, NToks};
{macro, NMacroDict} ->
{macro, NLine, LeftOverChars, NMacroDict};
{macro, NMacroMap} ->
{macro, NLine, LeftOverChars, NMacroMap};
{include, Filename} ->
{include, NLine, LeftOverChars, Filename};
{include_lib, Filename} ->
@ -168,7 +166,7 @@ scanner(Text, Line, MacroMap) ->
case preProc(lists:reverse(lists:concat([Header, Tokens])), MacroMap) of
{tokens, NToks} -> {tokens, NLine, [], NToks};
{macro, NMacroDict} -> {macro, NLine, [], NMacroDict};
{macro, NMacroMap} -> {macro, NLine, [], NMacroMap};
{include, Filename} -> {include, NLine, [], Filename};
{include_lib, Filename} -> {include_lib, NLine, [], Filename};
Def when Def =:= def; Def =:= endif; Def =:= else; Def =:= undef; Def =:= attribute; Def =:= vsn ->
@ -253,8 +251,6 @@ preProc([{'-', _}, {atom, _, copyright}, {'(', _}, _, {')', _}, {dot, _}], _Macr
attribute;
preProc([{'-', _}, {atom, _, description}, {'(', _}, _, {')', _}, {dot, _}], _MacroMap) ->
attribute;
preProc([{'-', _}, {atom, _, module}, {'(', _}, _, {')', _}, {dot, _}], _MacroMap) ->
attribute;
preProc(Tokens, MacroMap) ->
{tokens, substMacros(Tokens, MacroMap)}.
@ -317,9 +313,9 @@ substMacrosRev([{'?', _}, {_, _, Name}, {'(', _} = Paren | Tokens], MacroMap, Re
substMacrosRev([{'?', _}, {_, _, Name} | Toks], MacroMap, RevOutToks) ->
%% This macro invocation does not have arguments.
%% Therefore the definition should not have parameters
case dict:is_key(Name, MacroMap) of
case maps:is_key(Name, MacroMap) of
true ->
{[], MacroValue} = dict:fetch(Name, MacroMap),
{[], MacroValue} = maps:get(Name, MacroMap),
%% Recursively expand any macro calls inside this macro's value
%% TODO: avoid infinite expansion due to circular references (even indirect ones)
@ -331,7 +327,7 @@ substMacrosRev([{'?', _}, {_, _, Name} | Toks], MacroMap, RevOutToks) ->
substMacrosRev([Tok | Toks], MacroMap, RevOutToks) ->
substMacrosRev(Toks, MacroMap, [Tok | RevOutToks]);
substMacrosRev([], _MacroDict, RevOutToks) -> RevOutToks.
substMacrosRev([], _MacroMap, RevOutToks) -> RevOutToks.
substMacrosArgsExpress([{var, _, ArgsName}, {')', Line} | Toks], RevArgs) ->
{Toks, reverse([ArgsName | RevArgs]), Line};

+ 13
- 60
src/dataType/eLfq.erl View File

@ -8,27 +8,16 @@
% create the queue
new/0
% delete the queue
, del/1
% Allocates more memory if necessary
, in/2 % (item) : bool
, in/3 % (prod_token, item) : bool
, ins/2 % (item_first, count) : bool
, ins/3 % (prod_token, item_first, count) : bool
% Fails if not enough memory to enqueue
, tryIn/2 % (item) : bool
, tryIn/3 % (prod_token, item) : bool
, tryIns/2 % (item_first, count) : bool
, tryIns/3 % (prod_token, item_first, count) : bool
% Attempts to dequeue from the queue (never allocates)
, tryOut/1 % (item&) : bool
, tryOut/2 % (cons_token, item&) : bool
, tryOuts/2 % (item_first, max) : size_t
, tryOuts/3 % (cons_token, item_first, max) : size_t
% If you happen to know which producer you want to dequeue from
, tryOutByProd/2 % (prod_token, item&) : bool
, tryOutsByProd/3 % (prod_token, item_first, max) : size_t
% A not-necessarily-accurate count of the total number of elements
, size/1
@ -50,66 +39,30 @@ init() ->
end,
erlang:load_nif(SoName, 0).
-spec new() -> {ok, QueueRef :: reference()} | badarg | {error, Reason :: binary()}.
-spec new() -> {ok, QueueRef :: reference()} | error.
new() ->
?NotLoaded.
-spec in(QueueRef :: reference(), Data :: any()) -> true | {error, Reason :: binary()}.
in(_QueueRef, _Data) ->
-spec del(QueueRef :: reference()) -> ok.
del(_QueueRef) ->
?NotLoaded.
-spec in(QueueRef :: reference(), ProdToken :: any(), Data :: any()) -> true | {error, Reason :: binary()}.
in(_QueueRef, _ProdToken, _Data) ->
-spec in(QueueRef :: reference(), Data :: any()) -> true | false.
in(_QueueRef, _Data) ->
?NotLoaded.
-spec ins(QueueRef :: reference(), DataList :: [any()]) -> true | {error, Reason :: binary()}.
-spec ins(QueueRef :: reference(), DataList :: [any()]) -> true | false.
ins(_QueueRef, _DataList) ->
?NotLoaded.
-spec ins(QueueRef :: reference(), ProdToken :: any(), DataList :: [any()]) -> true | {error, Reason :: binary()}.
ins(_QueueRef, _ProdToken, _DataList) ->
?NotLoaded.
-spec tryIn(QueueRef :: reference(), Data :: any()) -> true | {error, Reason :: binary()}.
tryIn(_QueueRef, _Data) ->
?NotLoaded.
-spec tryIn(QueueRef :: reference(), ProdToken :: any(), Data :: any()) -> true | {error, Reason :: binary()}.
tryIn(_QueueRef, _ProdToken, _Data) ->
?NotLoaded.
-spec tryIns(QueueRef :: reference(), DataList :: [any()]) -> true | {error, Reason :: binary()}.
tryIns(_QueueRef, _DataList) ->
?NotLoaded.
-spec tryIns(QueueRef :: reference(), ProdToken :: any(), DataList :: [any()]) -> true | {error, Reason :: binary()}.
tryIns(_QueueRef, _ProdToken, _DataList) ->
?NotLoaded.
-spec tryOut(QueueRef :: reference()) -> Data :: any() | {error, Reason :: binary()}.
-spec tryOut(QueueRef :: reference()) -> Data :: any() | lfq_empty | lfq_error.
tryOut(_QueueRef) ->
?NotLoaded.
-spec tryOut(QueueRef :: reference(), ConsToken :: any()) -> Data :: any() | {error, Reason :: binary()}.
tryOut(_QueueRef, _ConsToken) ->
?NotLoaded.
-spec tryOuts(QueueRef :: reference(), Cnt :: pos_integer()) -> DataList :: [any()] | {error, Reason :: binary()}.
-spec tryOuts(QueueRef :: reference(), Cnt :: pos_integer()) -> DataList :: [any()].
tryOuts(_QueueRef, _Cnt) ->
?NotLoaded.
-spec tryOuts(QueueRef :: reference(), ConsToken :: any(), Cnt :: pos_integer()) -> DataList :: [any()] | {error, Reason :: binary()}.
tryOuts(_QueueRef, _ConsToken, _Cnt) ->
?NotLoaded.
-spec tryOutByProd(QueueRef :: reference(), ProdToken :: any()) -> Data :: any() | {error, Reason :: binary()}.
tryOutByProd(_QueueRef, _ProdToken) ->
?NotLoaded.
-spec tryOutsByProd(QueueRef :: reference(), ProdToken :: any(), Cnt :: pos_integer()) -> DataList :: [any()] | {error, Reason :: binary()}.
tryOutsByProd(_QueueRef, _ProdToken, _Cnt) ->
?NotLoaded.
-spec size(QueueRef :: reference()) -> pos_integer() | {error, Reason :: binary()}.
-spec size(QueueRef :: reference()) -> pos_integer().
size(_QueueRef) ->
?NotLoaded.
?NotLoaded.

Loading…
Cancel
Save