From 71920c9b25f45ffbfa45efeacccc167eb8f50909 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Sat, 12 Dec 2020 23:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dynamicCompile/utStrToBeam.erl | 11 +++++++++++ src/testCase/utTpfm.erl | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/dynamicCompile/utStrToBeam.erl diff --git a/src/dynamicCompile/utStrToBeam.erl b/src/dynamicCompile/utStrToBeam.erl new file mode 100644 index 0000000..eb61539 --- /dev/null +++ b/src/dynamicCompile/utStrToBeam.erl @@ -0,0 +1,11 @@ +-module(utStrToBeam). + +-export([load/3]). + +-spec load(Module :: atom(), Export :: [{Fun :: atom(), Arity :: pos_integer()}], Str :: string()) -> {module, Module :: atom()} | {error, _}. +load(Module, Export, Str) -> + {ok, Tokens, _EndLine} = erl_scan:string(Str), + {ok, Forms} = erl_parse:parse_form(Tokens), + NewForms = [{attribute, 1, module, Module}, {attribute, 2, export, Export}, Forms], + {ok, _, Binary} = compile:forms(NewForms), + code:load_binary(Module, "", Binary). diff --git a/src/testCase/utTpfm.erl b/src/testCase/utTpfm.erl index a9c4900..dcbd511 100644 --- a/src/testCase/utTpfm.erl +++ b/src/testCase/utTpfm.erl @@ -559,3 +559,18 @@ tPd(0, _) -> tPd(N, _) -> erlang:put(pdVpSize, 0), tPd(N -1, erlang:get(pdVpSize)). + +load1(0, List) -> + utKvsToBeam:load(load1, List); +load1(N, List) -> + utKvsToBeam:load(load1, List), + load1(N - 1, List). + +load2(0, List) -> + utKvsToBeam:load(load2, List); +load2(N, List) -> + Str = << <<"get(", (utTypeCast:toBinary(Key))/binary, ") -> ", (utTypeCast:toBinary(Value))/binary, ";">> || {Key, Value} <- List>>, + LastStr = < undefine.">>, + utStrToBeam:load(load2, [{get, 1}], binary_to_list(LastStr)), + load2(N - 1, List). +