Add Gitea tests Rename Remove oracle references Package for zx Reviewed-on: #235 Reviewed-by: dimitar.p.ivanov <dimitarivanov@qpq.swiss> Co-authored-by: Craig Everett <zxq9@zxq9.com> Co-committed-by: Craig Everett <zxq9@zxq9.com>
This commit was merged in pull request #235.
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Encode and decode data and function calls according to
|
||||
%%% Sophia-AEVM-ABI
|
||||
%%% @end
|
||||
%%% Updated : 22 Jan 2025
|
||||
%%% Created : 25 Jan 2018
|
||||
%%%
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(aeb_aevm_abi).
|
||||
-module(gmb_aevm_abi).
|
||||
-vsn("3.4.1").
|
||||
-define(HASH_SIZE, 32).
|
||||
|
||||
-export([ create_calldata/4
|
||||
@@ -25,7 +28,7 @@
|
||||
|
||||
-type hash() :: <<_:256>>. %% 256 = ?HASH_SIZE * 8.
|
||||
-type function_name() :: binary(). %% String
|
||||
-type typerep() :: aeb_aevm_data:type().
|
||||
-type typerep() :: gmb_aevm_data:type().
|
||||
-type function_type_info() :: { FunctionHash :: hash()
|
||||
, FunctionName :: function_name()
|
||||
, Payable :: boolean()
|
||||
@@ -50,7 +53,7 @@ create_calldata(FunName, Args, ArgTypes0, RetType) ->
|
||||
ArgTypes = {tuple, ArgTypes0},
|
||||
<<TypeHashInt:?HASH_SIZE/unit:8>> =
|
||||
function_type_hash(list_to_binary(FunName), ArgTypes, RetType),
|
||||
Data = aeb_heap:to_binary({TypeHashInt, list_to_tuple(Args)}),
|
||||
Data = gmb_heap:to_binary({TypeHashInt, list_to_tuple(Args)}),
|
||||
{ok, Data}.
|
||||
|
||||
-spec check_calldata(binary(), type_info(), boolean()) ->
|
||||
@@ -73,7 +76,7 @@ check_calldata(Hash, CallData, TypeInfo, true) ->
|
||||
check_calldata(Hash, CallData, TypeInfo, false) ->
|
||||
case typereps_from_type_hash(Hash, TypeInfo) of
|
||||
{ok, ArgType, OutType} ->
|
||||
try aeb_heap:from_binary({tuple, [word, ArgType]}, CallData) of
|
||||
try gmb_heap:from_binary({tuple, [word, ArgType]}, CallData) of
|
||||
{ok, _Something} ->
|
||||
{ok, {tuple, [word, ArgType]}, OutType};
|
||||
{error, _} ->
|
||||
@@ -90,7 +93,7 @@ check_calldata(Hash, CallData, TypeInfo, false) ->
|
||||
-spec get_function_hash_from_calldata(CallData::binary()) ->
|
||||
{ok, binary()} | {error, term()}.
|
||||
get_function_hash_from_calldata(CallData) ->
|
||||
case aeb_heap:from_binary({tuple, [word]}, CallData) of
|
||||
case gmb_heap:from_binary({tuple, [word]}, CallData) of
|
||||
{ok, {HashInt}} -> {ok, <<HashInt:?HASH_SIZE/unit:8>>};
|
||||
{error, _} = Error -> Error
|
||||
end.
|
||||
@@ -105,15 +108,15 @@ function_type_info(Name, Payable, ArgTypes, OutType) ->
|
||||
{ function_type_hash(Name, ArgType, OutType)
|
||||
, Name
|
||||
, Payable
|
||||
, aeb_heap:to_binary(ArgType)
|
||||
, aeb_heap:to_binary(OutType)
|
||||
, gmb_heap:to_binary(ArgType)
|
||||
, gmb_heap:to_binary(OutType)
|
||||
}.
|
||||
|
||||
-spec function_type_hash(function_name(), typerep(), typerep()) -> hash().
|
||||
function_type_hash(Name, ArgType, OutType) when is_binary(Name) ->
|
||||
Bin = iolist_to_binary([ Name
|
||||
, aeb_heap:to_binary(ArgType)
|
||||
, aeb_heap:to_binary(OutType)
|
||||
, gmb_heap:to_binary(ArgType)
|
||||
, gmb_heap:to_binary(OutType)
|
||||
]),
|
||||
%% Calculate a 256 bit digest BLAKE2b hash value of a binary
|
||||
{ok, Hash} = eblake2:blake2b(?HASH_SIZE, Bin),
|
||||
@@ -132,7 +135,7 @@ arg_typerep_from_function(Function, TypeInfo) ->
|
||||
end.
|
||||
|
||||
arg_typerep_from_type_binary(ArgTBin) ->
|
||||
case aeb_heap:from_binary(typerep, ArgTBin) of
|
||||
case gmb_heap:from_binary(typerep, ArgTBin) of
|
||||
{ok, ArgT} -> {ok, ArgT};
|
||||
{error,_} -> {error, bad_type_data}
|
||||
end.
|
||||
@@ -150,7 +153,7 @@ typereps_from_type_hash(TypeHash, TypeInfo) ->
|
||||
end.
|
||||
|
||||
typereps_from_type_binaries(ArgTBin, OutTBin) ->
|
||||
case {aeb_heap:from_binary(typerep, ArgTBin), aeb_heap:from_binary(typerep, OutTBin)} of
|
||||
case {gmb_heap:from_binary(typerep, ArgTBin), gmb_heap:from_binary(typerep, OutTBin)} of
|
||||
{{ok, ArgT}, {ok, OutT}} -> {ok, ArgT, OutT};
|
||||
{_, _} -> {error, bad_type_data}
|
||||
end.
|
||||
@@ -1,4 +1,5 @@
|
||||
-module(aeb_aevm_data).
|
||||
-module(gmb_aevm_data).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export_type([data/0,
|
||||
type/0,
|
||||
@@ -1,4 +1,5 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||
%%% @doc Assembler for aevm machine code.
|
||||
%%%
|
||||
@@ -25,17 +26,19 @@
|
||||
%%% 4. labels as descibed above.
|
||||
%%%
|
||||
%%% @end
|
||||
%%% Updated : 22 Jan 2025
|
||||
%%% Created : 21 Dec 2017
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeb_asm).
|
||||
-module(gmb_asm).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ file/2
|
||||
, pp/1
|
||||
, to_hexstring/1
|
||||
]).
|
||||
|
||||
-include_lib("aebytecode/include/aeb_opcodes.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_opcodes.hrl").
|
||||
|
||||
|
||||
pp(Asm) ->
|
||||
@@ -47,10 +50,10 @@ format(Asm) -> format(Asm, 0).
|
||||
format([{comment, Comment} | Rest], Address) ->
|
||||
";; " ++ Comment ++ "\n" ++ format(Rest, Address);
|
||||
format([Mnemonic | Rest], Address) ->
|
||||
Op = aeb_opcodes:m_to_op(Mnemonic),
|
||||
Op = gmb_opcodes:m_to_op(Mnemonic),
|
||||
case (Op >= ?PUSH1) andalso (Op =< ?PUSH32) of
|
||||
true ->
|
||||
Arity = aeb_opcodes:op_size(Op) - 1,
|
||||
Arity = gmb_opcodes:op_size(Op) - 1,
|
||||
{Args, Code} = get_args(Arity, Rest),
|
||||
" " ++ atom_to_list(Mnemonic)
|
||||
++ " " ++ Args ++ "\n"
|
||||
@@ -72,7 +75,7 @@ get_args(N, [Arg|Code]) ->
|
||||
|
||||
file(Filename, Options) ->
|
||||
{ok, File} = file:read_file(Filename),
|
||||
{ok, Tokens, _} = aeb_asm_scan:scan(binary_to_list(File)),
|
||||
{ok, Tokens, _} = gmb_asm_scan:scan(binary_to_list(File)),
|
||||
|
||||
case proplists:lookup(pp_tokens, Options) of
|
||||
{pp_tokens, true} ->
|
||||
@@ -100,8 +103,8 @@ to_hexstring(ByteList) ->
|
||||
|
||||
|
||||
to_bytecode([{mnemonic,_line, Op}|Rest], Address, Env, Code, Opts) ->
|
||||
OpCode = aeb_opcodes:m_to_op(Op),
|
||||
OpSize = aeb_opcodes:op_size(OpCode),
|
||||
OpCode = gmb_opcodes:m_to_op(Op),
|
||||
OpSize = gmb_opcodes:op_size(OpCode),
|
||||
to_bytecode(Rest, Address + OpSize, Env, [OpCode|Code], Opts);
|
||||
to_bytecode([{int,_line, Int}|Rest], Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env, [Int|Code], Opts);
|
||||
@@ -138,7 +141,7 @@ resolve_refs([Op | Rest], Env, Code) ->
|
||||
resolve_refs([],_Env, Code) -> Code.
|
||||
|
||||
expand_args([OP, Arg | Rest]) when OP >= ?PUSH1 andalso OP =< ?PUSH32 ->
|
||||
BitSize = (aeb_opcodes:op_size(OP) - 1) * 8,
|
||||
BitSize = (gmb_opcodes:op_size(OP) - 1) * 8,
|
||||
Bin = << << X:BitSize>> || X <- [Arg] >>,
|
||||
ArgByteList = binary_to_list(Bin),
|
||||
[OP | ArgByteList] ++ expand_args(Rest);
|
||||
@@ -1,5 +1,6 @@
|
||||
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||
%%% @doc Assembler lexer.
|
||||
%%%
|
||||
@@ -195,7 +196,7 @@ Erlang code.
|
||||
|
||||
-ignore_xref([format_error/1, string/2, token/2, token/3, tokens/2, tokens/3]).
|
||||
|
||||
-include_lib("aebytecode/include/aeb_opcodes.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_opcodes.hrl").
|
||||
|
||||
|
||||
parse_hex("0x" ++ Chars) -> list_to_integer(Chars, 16).
|
||||
@@ -1,19 +1,22 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Prettyprint aevm machine code
|
||||
%%% @end
|
||||
%%% Created : 2 Oct 2017
|
||||
%%% Updated : 22 Jan 2025
|
||||
%%% Created : 02 Oct 2017
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeb_disassemble).
|
||||
-module(gmb_disassemble).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ pp/1,
|
||||
format/2,
|
||||
format_address/1
|
||||
]).
|
||||
|
||||
-include_lib("aebytecode/include/aeb_opcodes.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_opcodes.hrl").
|
||||
|
||||
|
||||
pp(Binary) ->
|
||||
@@ -26,37 +29,37 @@ format(Binary, ErrFormatFun) ->
|
||||
pp(Address, [Op|Ops], Assembly, ErrFormatFun) ->
|
||||
case Op of
|
||||
X when (X >= ?STOP) andalso (X =< ?SIGNEXTEND) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?LT) andalso (X =< ?BYTE) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?SHA3) andalso (X =< ?SHA3) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?ADDRESS) andalso (X =< ?EXTCODECOPY) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?BLOCKHASH) andalso (X =< ?GASLIMIT) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?POP) andalso (X =< ?JUMPDEST) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?PUSH1) andalso (X =< ?PUSH32) ->
|
||||
Bytes = X-?PUSH1+1,
|
||||
{ArgList, NextOps} = lists:split(Bytes, Ops),
|
||||
Arg = arglist_to_arg(ArgList),
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), [{Arg,8*Bytes}]),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), [{Arg,8*Bytes}]),
|
||||
next(Address+Bytes, NextOps, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?DUP1) andalso (X =< ?LOG4) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?CREATE) andalso (X =< ?DELEGATECALL) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
X when (X >= ?INVALID) andalso (X =< ?SUICIDE) ->
|
||||
Instr = pp_instruction(Address, aeb_opcodes:mnemonic(Op), []),
|
||||
Instr = pp_instruction(Address, gmb_opcodes:mnemonic(Op), []),
|
||||
next(Address, Ops, Instr, Assembly, ErrFormatFun);
|
||||
_ ->
|
||||
ErrFormatFun("unhandled op ~p at ~p",[Op, Address]),
|
||||
@@ -1,13 +1,16 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Encode and decode data and function calls according to
|
||||
%%% Sophia-FATE-ABI
|
||||
%%% @end
|
||||
%%% Updated : 22 Jan 2025
|
||||
%%% Created : 11 Jun 2019
|
||||
%%%
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(aeb_fate_abi).
|
||||
-module(gmb_fate_abi).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ create_calldata/2
|
||||
, decode_calldata/2
|
||||
@@ -16,7 +19,7 @@
|
||||
, get_function_type_from_function_hash/2
|
||||
, abi_version/0 ]).
|
||||
|
||||
-include("../include/aeb_fate_data.hrl").
|
||||
-include("../include/gmb_fate_data.hrl").
|
||||
|
||||
%%%===================================================================
|
||||
%%% API
|
||||
@@ -29,27 +32,27 @@ abi_version() ->
|
||||
|
||||
-spec create_calldata(list(), [term()]) -> {ok, binary()}.
|
||||
create_calldata(FunName, Args) ->
|
||||
FunctionId = aeb_fate_code:symbol_identifier(list_to_binary(FunName)),
|
||||
{ok, aeb_fate_encoding:serialize(
|
||||
aeb_fate_data:make_tuple({FunctionId,
|
||||
aeb_fate_data:make_tuple(list_to_tuple(Args))}))}.
|
||||
FunctionId = gmb_fate_code:symbol_identifier(list_to_binary(FunName)),
|
||||
{ok, gmb_fate_encoding:serialize(
|
||||
gmb_fate_data:make_tuple({FunctionId,
|
||||
gmb_fate_data:make_tuple(list_to_tuple(Args))}))}.
|
||||
|
||||
-spec decode_calldata(list(), binary()) -> {ok, term()} | {error, term()}.
|
||||
decode_calldata(FunName, Calldata) ->
|
||||
FunctionId = aeb_fate_code:symbol_identifier(list_to_binary(FunName)),
|
||||
try ?FATE_TUPLE_ELEMENTS(aeb_fate_encoding:deserialize(Calldata)) of
|
||||
FunctionId = gmb_fate_code:symbol_identifier(list_to_binary(FunName)),
|
||||
try ?FATE_TUPLE_ELEMENTS(gmb_fate_encoding:deserialize(Calldata)) of
|
||||
[FunctionId, FateArgs] -> {ok, ?FATE_TUPLE_ELEMENTS(FateArgs)};
|
||||
_ -> {error, decode_error}
|
||||
catch _:_ ->
|
||||
{error, decode_error}
|
||||
end.
|
||||
|
||||
-spec get_function_name_from_function_hash(binary(), aeb_fate_code:fcode()) ->
|
||||
-spec get_function_name_from_function_hash(binary(), gmb_fate_code:fcode()) ->
|
||||
{ok, term()} | {error, term()}.
|
||||
get_function_name_from_function_hash(<<SymbolHash:4/binary, _:28/binary>>, FateCode) ->
|
||||
get_function_name_from_function_hash(SymbolHash, FateCode);
|
||||
get_function_name_from_function_hash(SymbolHash = <<_:4/binary>>, FateCode) ->
|
||||
Symbols = aeb_fate_code:symbols(FateCode),
|
||||
Symbols = gmb_fate_code:symbols(FateCode),
|
||||
case maps:get(SymbolHash, Symbols, undefined) of
|
||||
undefined -> {error, no_function_matching_function_hash};
|
||||
Function -> {ok, Function}
|
||||
@@ -58,19 +61,19 @@ get_function_name_from_function_hash(SymbolHash = <<_:4/binary>>, FateCode) ->
|
||||
-spec get_function_hash_from_calldata(binary()) ->
|
||||
{ok, binary()} | {error, term()}.
|
||||
get_function_hash_from_calldata(CallData) ->
|
||||
try ?FATE_TUPLE_ELEMENTS(aeb_fate_encoding:deserialize(CallData)) of
|
||||
try ?FATE_TUPLE_ELEMENTS(gmb_fate_encoding:deserialize(CallData)) of
|
||||
[FunHash, _Args] -> {ok, FunHash};
|
||||
_ -> {error, bad_calldata}
|
||||
catch _:_ ->
|
||||
{error, bad_calldata}
|
||||
end.
|
||||
|
||||
-spec get_function_type_from_function_hash(binary(), aeb_fate_code:fcode()) ->
|
||||
-spec get_function_type_from_function_hash(binary(), gmb_fate_code:fcode()) ->
|
||||
{ok, term(), term()} | {error, term()}.
|
||||
get_function_type_from_function_hash(<<SymbolHash:4/binary, _:28/binary>>, FateCode) ->
|
||||
get_function_type_from_function_hash(SymbolHash, FateCode);
|
||||
get_function_type_from_function_hash(SymbolHash, FateCode) ->
|
||||
Functions = aeb_fate_code:functions(FateCode),
|
||||
Functions = gmb_fate_code:functions(FateCode),
|
||||
case maps:get(SymbolHash, Functions, undefined) of
|
||||
undefined ->
|
||||
{error, no_function_matching_function_hash};
|
||||
@@ -1,4 +1,5 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||
%%% @doc Assembler for Fate machine code.
|
||||
%%% @end
|
||||
@@ -80,10 +81,12 @@
|
||||
%%% Size: Digits
|
||||
%%% Tag: Digits
|
||||
%%%
|
||||
%%% Updated : 22 Jan 2025
|
||||
%%% Created : 21 Dec 2017
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeb_fate_asm).
|
||||
-module(gmb_fate_asm).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ assemble_file/3
|
||||
, asm_to_bytecode/2
|
||||
@@ -94,8 +97,8 @@
|
||||
, to_asm/1
|
||||
]).
|
||||
|
||||
-include_lib("aebytecode/include/aeb_fate_opcodes.hrl").
|
||||
-include_lib("aebytecode/include/aeb_fate_data.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_fate_opcodes.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_fate_data.hrl").
|
||||
-define(HASH_BYTES, 32).
|
||||
|
||||
assemble_file(InFile, OutFile, Options) ->
|
||||
@@ -104,12 +107,12 @@ assemble_file(InFile, OutFile, Options) ->
|
||||
ok = file:write_file(OutFile, BC).
|
||||
|
||||
function_call(String) ->
|
||||
{ok, Tokens, _} = aeb_fate_asm_scan:scan(String),
|
||||
{ok, Tokens, _} = gmb_fate_asm_scan:scan(String),
|
||||
parse_function_call(Tokens).
|
||||
|
||||
parse_function_call([{id,_,Name}, {'(',_}| Rest]) ->
|
||||
{Args, []} = to_args(Rest),
|
||||
aeb_fate_encoding:serialize(
|
||||
gmb_fate_encoding:serialize(
|
||||
{tuple, {mk_hash(Name), {tuple, list_to_tuple(Args)}}}).
|
||||
|
||||
|
||||
@@ -129,9 +132,9 @@ pp(FateCode) ->
|
||||
|
||||
|
||||
to_asm(FateCode) ->
|
||||
Functions = aeb_fate_code:functions(FateCode),
|
||||
Symbols = aeb_fate_code:symbols(FateCode),
|
||||
Annotations = aeb_fate_code:annotations(FateCode),
|
||||
Functions = gmb_fate_code:functions(FateCode),
|
||||
Symbols = gmb_fate_code:symbols(FateCode),
|
||||
Annotations = gmb_fate_code:annotations(FateCode),
|
||||
insert_comments(get_comments(Annotations), 1,
|
||||
lists:flatten(
|
||||
io_lib:format("~s",
|
||||
@@ -191,7 +194,7 @@ format_code([], _) ->
|
||||
"";
|
||||
format_code([Op|Rest], Symbols) ->
|
||||
[" ",
|
||||
aeb_fate_pp:format_op(Op, Symbols),
|
||||
gmb_fate_pp:format_op(Op, Symbols),
|
||||
"\n",
|
||||
format_code(Rest, Symbols)].
|
||||
|
||||
@@ -201,7 +204,7 @@ read_file(Filename) ->
|
||||
binary_to_list(File).
|
||||
|
||||
asm_to_bytecode(AssemblerCode, Options) ->
|
||||
{ok, Tokens, _} = aeb_fate_asm_scan:scan(AssemblerCode),
|
||||
{ok, Tokens, _} = gmb_fate_asm_scan:scan(AssemblerCode),
|
||||
|
||||
case proplists:lookup(pp_tokens, Options) of
|
||||
{pp_tokens, true} ->
|
||||
@@ -209,7 +212,7 @@ asm_to_bytecode(AssemblerCode, Options) ->
|
||||
none ->
|
||||
ok
|
||||
end,
|
||||
Env = #{ fate_code => aeb_fate_code:new()
|
||||
Env = #{ fate_code => gmb_fate_code:new()
|
||||
, functions => #{}
|
||||
},
|
||||
|
||||
@@ -218,11 +221,11 @@ asm_to_bytecode(AssemblerCode, Options) ->
|
||||
FunctionsMap = maps:get(functions, Env1),
|
||||
Functions = [X || {_, X} <- lists:sort(maps:to_list(FunctionsMap))],
|
||||
FunctionsBin = iolist_to_binary(Functions),
|
||||
ByteCode = aeb_fate_code:serialize(FateCode, FunctionsBin, Options),
|
||||
ByteCode = gmb_fate_code:serialize(FateCode, FunctionsBin, Options),
|
||||
{Env, ByteCode}.
|
||||
|
||||
strip(ByteCode) ->
|
||||
{Code, _Rest} = aeser_rlp:decode_one(ByteCode),
|
||||
{Code, _Rest} = gmser_rlp:decode_one(ByteCode),
|
||||
Code.
|
||||
|
||||
%% -------------------------------------------------------------------
|
||||
@@ -235,7 +238,7 @@ to_bytecode([{function,_line, 'FUNCTION'}|Rest], Address, Env, Code, Opts) ->
|
||||
{Fun, Rest2} = to_fun_def(Rest),
|
||||
to_bytecode(Rest2, Fun, Env2, [], Opts);
|
||||
to_bytecode([{mnemonic,_line, Op}|Rest], Address, Env, Code, Opts) ->
|
||||
OpCode = aeb_fate_opcodes:m_to_op(Op),
|
||||
OpCode = gmb_fate_opcodes:m_to_op(Op),
|
||||
to_bytecode(Rest, Address, Env, [OpCode|Code], Opts);
|
||||
to_bytecode([{arg,_line, N}|Rest], Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env, [{arg, N}|Code], Opts);
|
||||
@@ -249,41 +252,41 @@ to_bytecode([{boolean,_line, Bool}|Rest], Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env, [{immediate, Bool}|Code], Opts);
|
||||
to_bytecode([{string,_line, String}|Rest], Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_string(String)}|Code],
|
||||
[{immediate, gmb_fate_data:make_string(String)}|Code],
|
||||
Opts);
|
||||
to_bytecode([{object,_line, {address, Value}}|Rest],
|
||||
Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_address(Value)}|Code],
|
||||
[{immediate, gmb_fate_data:make_address(Value)}|Code],
|
||||
Opts);
|
||||
to_bytecode([{object,_line, {contract, Value}}|Rest],
|
||||
Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_contract(Value)}|Code],
|
||||
[{immediate, gmb_fate_data:make_contract(Value)}|Code],
|
||||
Opts);
|
||||
to_bytecode([{object,_line, {oracle, Value}}|Rest],
|
||||
Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_oracle(Value)}|Code],
|
||||
[{immediate, gmb_fate_data:make_oracle(Value)}|Code],
|
||||
Opts);
|
||||
to_bytecode([{object,_line, {oracle_query, Value}}|Rest],
|
||||
Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_oracle_query(Value)}|Code],
|
||||
[{immediate, gmb_fate_data:make_oracle_query(Value)}|Code],
|
||||
Opts);
|
||||
to_bytecode([{object,_line, {channel, Value}}|Rest],
|
||||
Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_contract(Value)}|Code],
|
||||
[{immediate, gmb_fate_data:make_contract(Value)}|Code],
|
||||
Opts);
|
||||
to_bytecode([{bytes,_line, Value}|Rest],
|
||||
Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_bytes(Value)}|Code],
|
||||
[{immediate, gmb_fate_data:make_bytes(Value)}|Code],
|
||||
Opts);
|
||||
to_bytecode([{contract_bytearray,_line, FateCode}|Rest], Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_contract_bytearray(FateCode)}|Code],
|
||||
[{immediate, gmb_fate_data:make_contract_bytearray(FateCode)}|Code],
|
||||
Opts);
|
||||
to_bytecode([{id,_line, ID}|Rest], Address, Env, Code, Opts) ->
|
||||
{Env2, Id} = insert_symbol(list_to_binary(ID), Env),
|
||||
@@ -296,19 +299,19 @@ to_bytecode([{'[',_line}|Rest], Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest2, Address, Env, [{immediate, List}|Code], Opts);
|
||||
to_bytecode([{'(',_line}|Rest], Address, Env, Code, Opts) ->
|
||||
{Elements, Rest2} = parse_tuple(Rest),
|
||||
Tuple = aeb_fate_data:make_tuple(list_to_tuple(Elements)),
|
||||
Tuple = gmb_fate_data:make_tuple(list_to_tuple(Elements)),
|
||||
to_bytecode(Rest2, Address, Env, [{immediate, Tuple}|Code], Opts);
|
||||
to_bytecode([{start_variant,_line}|_] = Tokens, Address, Env, Code, Opts) ->
|
||||
{Arities, Tag, Values, Rest} = parse_variant(Tokens),
|
||||
Variant = aeb_fate_data:make_variant(Arities, Tag, Values),
|
||||
Variant = gmb_fate_data:make_variant(Arities, Tag, Values),
|
||||
to_bytecode(Rest, Address, Env, [{immediate, Variant}|Code], Opts);
|
||||
to_bytecode([{typerep,_line}|Rest], Address, Env, Code, Opts) ->
|
||||
{Type, Rest1} = to_type(Rest),
|
||||
TypeRep = aeb_fate_data:make_typerep(Type),
|
||||
TypeRep = gmb_fate_data:make_typerep(Type),
|
||||
to_bytecode(Rest1, Address, Env, [{immediate, TypeRep}|Code], Opts);
|
||||
to_bytecode([{bits,_line, Bits}|Rest], Address, Env, Code, Opts) ->
|
||||
to_bytecode(Rest, Address, Env,
|
||||
[{immediate, aeb_fate_data:make_bits(Bits)}|Code], Opts);
|
||||
[{immediate, gmb_fate_data:make_bits(Bits)}|Code], Opts);
|
||||
|
||||
to_bytecode([{comment, Line, Comment}|Rest], Address, Env, Code, Opts) ->
|
||||
Env2 = insert_annotation(comment, Line, Comment, Env),
|
||||
@@ -383,29 +386,29 @@ parse_value([{'{',_line} | Rest]) -> parse_map(Rest);
|
||||
parse_value([{'[',_line} | Rest]) -> parse_list(Rest);
|
||||
parse_value([{'(',_line} | Rest]) ->
|
||||
{T, Rest2} = parse_tuple(Rest),
|
||||
{aeb_fate_data:make_tuple(list_to_tuple(T)), Rest2};
|
||||
{gmb_fate_data:make_tuple(list_to_tuple(T)), Rest2};
|
||||
parse_value([{bits,_line, Bits} | Rest]) ->
|
||||
{aeb_fate_data:make_bits(Bits), Rest};
|
||||
{gmb_fate_data:make_bits(Bits), Rest};
|
||||
parse_value([{start_variant,_line}|_] = Tokens) ->
|
||||
{Arities, Tag, Values, Rest} = parse_variant(Tokens),
|
||||
Variant = aeb_fate_data:make_variant(Arities, Tag, Values),
|
||||
Variant = gmb_fate_data:make_variant(Arities, Tag, Values),
|
||||
{Variant, Rest};
|
||||
parse_value([{string,_line, String} | Rest]) ->
|
||||
{aeb_fate_data:make_string(String), Rest};
|
||||
{gmb_fate_data:make_string(String), Rest};
|
||||
parse_value([{object,_line, {address, Address}} | Rest]) ->
|
||||
{aeb_fate_data:make_address(Address), Rest};
|
||||
{gmb_fate_data:make_address(Address), Rest};
|
||||
parse_value([{object,_line, {contract, Address}} | Rest]) ->
|
||||
{aeb_fate_data:make_contract(Address), Rest};
|
||||
{gmb_fate_data:make_contract(Address), Rest};
|
||||
parse_value([{object,_line, {oracle, Address}} | Rest]) ->
|
||||
{aeb_fate_data:make_oracle(Address), Rest};
|
||||
{gmb_fate_data:make_oracle(Address), Rest};
|
||||
parse_value([{object,_line, {oracle_query, Address}} | Rest]) ->
|
||||
{aeb_fate_data:make_oracle_query(Address), Rest};
|
||||
{gmb_fate_data:make_oracle_query(Address), Rest};
|
||||
parse_value([{object,_line, {channel, Address}} | Rest]) ->
|
||||
{aeb_fate_data:make_channel(Address), Rest};
|
||||
{gmb_fate_data:make_channel(Address), Rest};
|
||||
parse_value([{hash,_line, Hash} | Rest]) ->
|
||||
{aeb_fate_data:make_hash(Hash), Rest};
|
||||
{gmb_fate_data:make_hash(Hash), Rest};
|
||||
parse_value([{signature,_line, Hash} | Rest]) ->
|
||||
{aeb_fate_data:make_signature(Hash), Rest};
|
||||
{gmb_fate_data:make_signature(Hash), Rest};
|
||||
parse_value([{typerep,_line} | Rest]) ->
|
||||
to_type(Rest).
|
||||
|
||||
@@ -485,20 +488,20 @@ insert_fun(none, [], Env) -> Env;
|
||||
insert_fun({NameString, ArgType, RetType}, Code, #{ fate_code := FateCode
|
||||
, functions := Funs} = Env) ->
|
||||
Name = list_to_binary(NameString),
|
||||
{FateCode1, Id} = aeb_fate_code:insert_symbol(Name, FateCode),
|
||||
BodyByteCode = aeb_fate_code:serialize_code(lists:reverse(Code)),
|
||||
SigByteCode = aeb_fate_code:serialize_signature({ArgType, RetType}),
|
||||
FunByteCode = [?FUNCTION, Id, aeb_fate_encoding:serialize(0), SigByteCode, BodyByteCode],
|
||||
{FateCode1, Id} = gmb_fate_code:insert_symbol(Name, FateCode),
|
||||
BodyByteCode = gmb_fate_code:serialize_code(lists:reverse(Code)),
|
||||
SigByteCode = gmb_fate_code:serialize_signature({ArgType, RetType}),
|
||||
FunByteCode = [?FUNCTION, Id, gmb_fate_encoding:serialize(0), SigByteCode, BodyByteCode],
|
||||
Env#{ functions => Funs#{ Id => FunByteCode }
|
||||
, fate_code => FateCode1}.
|
||||
|
||||
insert_symbol(Name, #{ fate_code := FateCode } = Env) ->
|
||||
{FateCode1, Id} = aeb_fate_code:insert_symbol(Name, FateCode),
|
||||
{FateCode1, Id} = gmb_fate_code:insert_symbol(Name, FateCode),
|
||||
{ Env#{ fate_code => FateCode1 }
|
||||
, Id}.
|
||||
|
||||
insert_annotation(comment, Line, Comment, #{ fate_code := FateCode } = Env) ->
|
||||
FateCode1 = aeb_fate_code:insert_annotation(comment, Line, Comment, FateCode),
|
||||
FateCode1 = gmb_fate_code:insert_annotation(comment, Line, Comment, FateCode),
|
||||
Env#{ fate_code => FateCode1}.
|
||||
|
||||
mk_hash(Id) ->
|
||||
@@ -1,6 +1,7 @@
|
||||
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2019, aeternity Anstalt
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Handling FATE code.
|
||||
%%% @end
|
||||
@@ -100,7 +101,7 @@ Erlang code.
|
||||
|
||||
-ignore_xref([format_error/1, string/2, token/2, token/3, tokens/2, tokens/3]).
|
||||
|
||||
-include_lib("aebytecode/include/aeb_fate_opcodes.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_fate_opcodes.hrl").
|
||||
|
||||
|
||||
parse_hex("0x" ++ Chars) -> list_to_integer(Chars, 16).
|
||||
@@ -115,12 +116,12 @@ parse_hash("#" ++ Chars) ->
|
||||
base64:decode(Chars).
|
||||
|
||||
parse_contract_bytearray("@" ++ Chars) ->
|
||||
case aeser_api_encoder:decode(unicode:characters_to_binary(Chars)) of
|
||||
case gmser_api_encoder:decode(unicode:characters_to_binary(Chars)) of
|
||||
{contract_bytearray, Bin} -> Bin
|
||||
end.
|
||||
|
||||
parse_object([_|Chars]) ->
|
||||
case aeser_api_encoder:decode(unicode:characters_to_binary(Chars)) of
|
||||
case gmser_api_encoder:decode(unicode:characters_to_binary(Chars)) of
|
||||
{account_pubkey, Bin} -> {address, Bin};
|
||||
{contract_pubkey, Bin} -> {contract, Bin};
|
||||
{oracle_pubkey, Bin} -> {oracle, Bin};
|
||||
@@ -1,11 +1,13 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% ADT for fate byte code/fate code
|
||||
%%% @end
|
||||
%%%
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(aeb_fate_code).
|
||||
-module(gmb_fate_code).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ annotations/1
|
||||
, deserialize/1
|
||||
@@ -24,8 +26,8 @@
|
||||
, symbols/1
|
||||
]).
|
||||
|
||||
-include("../include/aeb_fate_opcodes.hrl").
|
||||
-include("../include/aeb_fate_data.hrl").
|
||||
-include("../include/gmb_fate_opcodes.hrl").
|
||||
-include("../include/gmb_fate_data.hrl").
|
||||
|
||||
-export([ update_annotations/2
|
||||
, update_functions/2
|
||||
@@ -87,8 +89,8 @@ insert_symbol(Name, #fcode{ symbols = Syms } = F) ->
|
||||
end.
|
||||
|
||||
insert_annotation(comment =_Type, Line, Comment, FCode) ->
|
||||
Key = aeb_fate_data:make_tuple({aeb_fate_data:make_string("comment"), Line}),
|
||||
Value = aeb_fate_data:make_string(Comment),
|
||||
Key = gmb_fate_data:make_tuple({gmb_fate_data:make_string("comment"), Line}),
|
||||
Value = gmb_fate_data:make_string(Comment),
|
||||
update_annotations(FCode, #{ Key => Value }).
|
||||
|
||||
strip_init_function(#fcode{ functions = Funs,
|
||||
@@ -111,9 +113,9 @@ serialize(#fcode{} = F, Options) ->
|
||||
serialize(#fcode{} = F, Functions, Options) ->
|
||||
SymbolTable = serialize_symbol_table(F),
|
||||
Annotatations = serialize_annotations(F),
|
||||
ByteCode = << (aeser_rlp:encode(Functions))/binary,
|
||||
(aeser_rlp:encode(SymbolTable))/binary,
|
||||
(aeser_rlp:encode(Annotatations))/binary
|
||||
ByteCode = << (gmser_rlp:encode(Functions))/binary,
|
||||
(gmser_rlp:encode(SymbolTable))/binary,
|
||||
(gmser_rlp:encode(Annotatations))/binary
|
||||
>>,
|
||||
|
||||
case proplists:lookup(pp_hex_string, Options) of
|
||||
@@ -139,20 +141,20 @@ serialize_functions(#fcode{ functions = Functions }) ->
|
||||
|
||||
serialize_attributes(Attrs) ->
|
||||
AttrVal = lists:sum([ attr_value(Attr) || Attr <- Attrs ]),
|
||||
aeb_fate_encoding:serialize(?MAKE_FATE_INTEGER(AttrVal)).
|
||||
gmb_fate_encoding:serialize(?MAKE_FATE_INTEGER(AttrVal)).
|
||||
|
||||
attr_value(private) -> 1;
|
||||
attr_value(payable) -> 2.
|
||||
|
||||
serialize_signature({Args, RetType}) ->
|
||||
[aeb_fate_encoding:serialize_type({tuple, Args}) |
|
||||
aeb_fate_encoding:serialize_type(RetType)].
|
||||
[gmb_fate_encoding:serialize_type({tuple, Args}) |
|
||||
gmb_fate_encoding:serialize_type(RetType)].
|
||||
|
||||
serialize_symbol_table(#fcode{ symbols = Symbols }) ->
|
||||
aeb_fate_encoding:serialize(aeb_fate_data:make_map(Symbols)).
|
||||
gmb_fate_encoding:serialize(gmb_fate_data:make_map(Symbols)).
|
||||
|
||||
serialize_annotations(#fcode{ annotations = Annotations }) ->
|
||||
aeb_fate_encoding:serialize(aeb_fate_data:make_map(Annotations)).
|
||||
gmb_fate_encoding:serialize(gmb_fate_data:make_map(Annotations)).
|
||||
|
||||
serialize_bbs(#{} = BBs) ->
|
||||
serialize_bbs(BBs, 0, []).
|
||||
@@ -174,7 +176,7 @@ serialize_op(Op) ->
|
||||
true -> tuple_to_list(Op);
|
||||
false -> [Op]
|
||||
end,
|
||||
[aeb_fate_opcodes:m_to_op(Mnemonic) | serialize_code(Args)].
|
||||
[gmb_fate_opcodes:m_to_op(Mnemonic) | serialize_code(Args)].
|
||||
|
||||
sanity_check(#fcode{ functions = Funs }) ->
|
||||
_ = [ case Def of
|
||||
@@ -213,12 +215,12 @@ sanity_check_op(IsLast, Op) ->
|
||||
true -> tuple_to_list(Op);
|
||||
false -> [Op]
|
||||
end,
|
||||
safe_sanity_check(IsLast, aeb_fate_opcodes:m_to_op(Mnemonic), Args).
|
||||
safe_sanity_check(IsLast, gmb_fate_opcodes:m_to_op(Mnemonic), Args).
|
||||
|
||||
safe_sanity_check(IsLast, Op, Args) ->
|
||||
case length(Args) == aeb_fate_opcodes:args(Op) of
|
||||
case length(Args) == gmb_fate_opcodes:args(Op) of
|
||||
true ->
|
||||
case IsLast == aeb_fate_opcodes:end_bb(Op) of
|
||||
case IsLast == gmb_fate_opcodes:end_bb(Op) of
|
||||
true -> ok;
|
||||
false -> error({wrong_opcode_in_bb, Op})
|
||||
end;
|
||||
@@ -269,7 +271,7 @@ pad_args(List) ->
|
||||
end.
|
||||
|
||||
serialize_data(_, Data) ->
|
||||
aeb_fate_encoding:serialize(Data).
|
||||
gmb_fate_encoding:serialize(Data).
|
||||
|
||||
%% 00 : stack/unused (depending on instruction)
|
||||
%% 01 : argN
|
||||
@@ -291,9 +293,9 @@ bits_to_modifier(2#00) -> stack.
|
||||
%%%===================================================================
|
||||
|
||||
deserialize(Bytes) ->
|
||||
{ByteCode, Rest1} = aeser_rlp:decode_one(Bytes),
|
||||
{SymbolTable, Rest2} = aeser_rlp:decode_one(Rest1),
|
||||
{Annotations, <<>>} = aeser_rlp:decode_one(Rest2),
|
||||
{ByteCode, Rest1} = gmser_rlp:decode_one(Bytes),
|
||||
{SymbolTable, Rest2} = gmser_rlp:decode_one(Rest1),
|
||||
{Annotations, <<>>} = gmser_rlp:decode_one(Rest2),
|
||||
|
||||
Env = #{ function => none
|
||||
, bb => 0
|
||||
@@ -353,7 +355,7 @@ deserialize_functions(<<Op:8, Rest/binary>>,
|
||||
, current_bb_code := Code
|
||||
, code := Program} = Env) ->
|
||||
{Rest2, OpCode} = deserialize_op(Op, Rest, Code),
|
||||
case aeb_fate_opcodes:end_bb(Op) of
|
||||
case gmb_fate_opcodes:end_bb(Op) of
|
||||
true ->
|
||||
deserialize_functions(Rest2, Env#{ bb => BB+1
|
||||
, current_bb_code => []
|
||||
@@ -378,8 +380,8 @@ deserialize_functions(<<>>, #{ function := {F, Attrs, Sig}
|
||||
Funs#{F => {Attrs, Sig, FunctionCode}}.
|
||||
|
||||
deserialize_op(Op, Rest, Code) ->
|
||||
OpName = aeb_fate_opcodes:mnemonic(Op),
|
||||
case aeb_fate_opcodes:args(Op) of
|
||||
OpName = gmb_fate_opcodes:mnemonic(Op),
|
||||
case gmb_fate_opcodes:args(Op) of
|
||||
0 ->
|
||||
{Rest, [OpName | Code]};
|
||||
N ->
|
||||
@@ -395,7 +397,7 @@ deserialize_n_args(N, <<M3:2, M2:2, M1:2, M0:2, Rest/binary>>) when N =< 4 ->
|
||||
stack ->
|
||||
{{stack, 0}, Acc};
|
||||
Modifier ->
|
||||
{Arg, Acc2} = aeb_fate_encoding:deserialize_one(Acc),
|
||||
{Arg, Acc2} = gmb_fate_encoding:deserialize_one(Acc),
|
||||
{{Modifier, Arg}, Acc2}
|
||||
end
|
||||
end, Rest, ArgMods);
|
||||
@@ -408,13 +410,13 @@ deserialize_n_args(N, <<M7:2, M6:2, M5:2, M4:2, M3:2, M2:2, M1:2, M0:2,
|
||||
stack ->
|
||||
{{stack, 0}, Acc};
|
||||
Modifier ->
|
||||
{Arg, Acc2} = aeb_fate_encoding:deserialize_one(Acc),
|
||||
{Arg, Acc2} = gmb_fate_encoding:deserialize_one(Acc),
|
||||
{{Modifier, Arg}, Acc2}
|
||||
end
|
||||
end, Rest, ArgMods).
|
||||
|
||||
deserialize_attributes(Binary) ->
|
||||
{AttrVal, Rest} = aeb_fate_encoding:deserialize_one(Binary),
|
||||
{AttrVal, Rest} = gmb_fate_encoding:deserialize_one(Binary),
|
||||
Attrs = [ attr(AVal) || AVal <- attr_vals(1, AttrVal) ],
|
||||
{lists:sort(Attrs), Rest}.
|
||||
|
||||
@@ -426,16 +428,16 @@ attr(1) -> private;
|
||||
attr(2) -> payable.
|
||||
|
||||
deserialize_signature(Binary) ->
|
||||
{{tuple, Args}, Rest} = aeb_fate_encoding:deserialize_type(Binary),
|
||||
{RetType, Rest2} = aeb_fate_encoding:deserialize_type(Rest),
|
||||
{{tuple, Args}, Rest} = gmb_fate_encoding:deserialize_type(Binary),
|
||||
{RetType, Rest2} = gmb_fate_encoding:deserialize_type(Rest),
|
||||
{{Args, RetType}, Rest2}.
|
||||
|
||||
deserialize_symbols(Table) ->
|
||||
?FATE_MAP_VALUE(SymbolTable) = aeb_fate_encoding:deserialize(Table),
|
||||
?FATE_MAP_VALUE(SymbolTable) = gmb_fate_encoding:deserialize(Table),
|
||||
SymbolTable.
|
||||
|
||||
deserialize_annotations(AnnotationsBin) ->
|
||||
?FATE_MAP_VALUE(Annotations) = aeb_fate_encoding:deserialize(AnnotationsBin),
|
||||
?FATE_MAP_VALUE(Annotations) = gmb_fate_encoding:deserialize(AnnotationsBin),
|
||||
Annotations.
|
||||
|
||||
assert_zero([]) ->
|
||||
@@ -1,8 +1,9 @@
|
||||
%% FATE data representation.
|
||||
%%
|
||||
-include("aeb_fate_data.hrl").
|
||||
-include("gmb_fate_data.hrl").
|
||||
|
||||
-module(aeb_fate_data).
|
||||
-module(gmb_fate_data).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-type fate_integer() :: ?FATE_INTEGER_T.
|
||||
-type fate_boolean() :: ?FATE_BOOLEAN_T.
|
||||
@@ -182,19 +183,19 @@ format(M) when ?IS_FATE_MAP(M) ->
|
||||
["{ ", format_kvs(maps:to_list(?FATE_MAP_VALUE(M))), " }"];
|
||||
format(?FATE_BYTES(X)) -> ["#", base64:encode(X)];
|
||||
format(?FATE_ADDRESS(X)) ->
|
||||
["@", aeser_api_encoder:encode(account_pubkey, X)];
|
||||
["@", gmser_api_encoder:encode(account_pubkey, X)];
|
||||
format(?FATE_CONTRACT(X)) ->
|
||||
["@", aeser_api_encoder:encode(contract_pubkey, X)];
|
||||
["@", gmser_api_encoder:encode(contract_pubkey, X)];
|
||||
format(?FATE_ORACLE(X)) ->
|
||||
["@", aeser_api_encoder:encode(oracle_pubkey, X)];
|
||||
["@", gmser_api_encoder:encode(oracle_pubkey, X)];
|
||||
format(?FATE_ORACLE_Q(X)) ->
|
||||
["@", aeser_api_encoder:encode(oracle_query_id, X)];
|
||||
["@", gmser_api_encoder:encode(oracle_query_id, X)];
|
||||
format(?FATE_CHANNEL(X)) ->
|
||||
["@", aeser_api_encoder:encode(channel, X)];
|
||||
["@", gmser_api_encoder:encode(channel, X)];
|
||||
format(?FATE_TYPEREP(X)) ->
|
||||
["'", io_lib:format("~p", [X])];
|
||||
format(?FATE_CONTRACT_BYTEARRAY(B)) ->
|
||||
["@", aeser_api_encoder:encode(contract_bytearray, B)];
|
||||
["@", gmser_api_encoder:encode(contract_bytearray, B)];
|
||||
format(V) -> exit({not_a_fate_type, V}).
|
||||
|
||||
format_bits(0, Acc) -> Acc;
|
||||
@@ -29,7 +29,7 @@
|
||||
%% * First draft of FATE serialization encoding/decoding.
|
||||
%% Initial experiment with tags
|
||||
%% * Second draft
|
||||
%% * FATE data is now defined in aefa_data.erl
|
||||
%% * FATE data is now defined in gmfa_data.erl
|
||||
%% * Third draft
|
||||
%% * Added Bit strings
|
||||
%%
|
||||
@@ -39,7 +39,8 @@
|
||||
%% * Handle instructions.
|
||||
%%
|
||||
%% ------------------------------------------------------------------------
|
||||
-module(aeb_fate_encoding).
|
||||
-module(gmb_fate_encoding).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ deserialize/1
|
||||
, deserialize_one/1
|
||||
@@ -52,7 +53,7 @@
|
||||
-export([sort/1]).
|
||||
-endif.
|
||||
|
||||
-include("aeb_fate_data.hrl").
|
||||
-include("gmb_fate_data.hrl").
|
||||
|
||||
%% Definition of tag scheme.
|
||||
%% This has to follow the protocol specification.
|
||||
@@ -135,7 +136,7 @@
|
||||
%% Serialized a Fate data value into a sequence of bytes
|
||||
%% according to the Fate serialization specification.
|
||||
%% TODO: The type Fate Data is not final yet.
|
||||
-spec serialize(aeb_fate_data:fate_type()) -> binary().
|
||||
-spec serialize(gmb_fate_data:fate_type()) -> binary().
|
||||
serialize(?FATE_TRUE) -> <<?TRUE>>;
|
||||
serialize(?FATE_FALSE) -> <<?FALSE>>;
|
||||
serialize(?FATE_UNIT) -> <<?EMPTY_TUPLE>>; %% ! Untyped
|
||||
@@ -158,15 +159,15 @@ serialize(String) when ?IS_FATE_STRING(String),
|
||||
serialize(?FATE_BYTES(Bytes)) when is_binary(Bytes) ->
|
||||
<<?OBJECT, ?OTYPE_BYTES, (serialize(?FATE_STRING(Bytes)))/binary>>;
|
||||
serialize(?FATE_ADDRESS(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_ADDRESS, (aeser_rlp:encode(Address))/binary>>;
|
||||
<<?OBJECT, ?OTYPE_ADDRESS, (gmser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_CONTRACT(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_CONTRACT, (aeser_rlp:encode(Address))/binary>>;
|
||||
<<?OBJECT, ?OTYPE_CONTRACT, (gmser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_ORACLE(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_ORACLE, (aeser_rlp:encode(Address))/binary>>;
|
||||
<<?OBJECT, ?OTYPE_ORACLE, (gmser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_ORACLE_Q(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_ORACLE_Q, (aeser_rlp:encode(Address))/binary>>;
|
||||
<<?OBJECT, ?OTYPE_ORACLE_Q, (gmser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_CHANNEL(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_CHANNEL, (aeser_rlp:encode(Address))/binary>>;
|
||||
<<?OBJECT, ?OTYPE_CHANNEL, (gmser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_TUPLE(T)) when size(T) > 0 ->
|
||||
S = size(T),
|
||||
L = tuple_to_list(T),
|
||||
@@ -209,7 +210,7 @@ serialize(?FATE_VARIANT(Arities, Tag, Values)) ->
|
||||
, is_tuple(Values) ->
|
||||
Arity = lists:nth(Tag+1, Arities),
|
||||
if size(Values) =:= Arity ->
|
||||
EncodedArities = aeser_rlp:encode(list_to_binary(Arities)),
|
||||
EncodedArities = gmser_rlp:encode(list_to_binary(Arities)),
|
||||
<<?VARIANT,
|
||||
EncodedArities/binary,
|
||||
Tag:8,
|
||||
@@ -227,7 +228,7 @@ serialize(?FATE_CONTRACT_BYTEARRAY(B)) ->
|
||||
|
||||
%% -----------------------------------------------------
|
||||
|
||||
-spec serialize_type(aeb_fate_data:fate_type_type()) -> [byte()].
|
||||
-spec serialize_type(gmb_fate_data:fate_type_type()) -> [byte()].
|
||||
serialize_type(integer) -> [?TYPE_INTEGER];
|
||||
serialize_type(boolean) -> [?TYPE_BOOLEAN];
|
||||
serialize_type(any) -> [?TYPE_ANY];
|
||||
@@ -259,7 +260,7 @@ serialize_type({variant, ListOfVariants}) ->
|
||||
serialize_type(contract_bytearray) -> [?TYPE_CONTRACT_BYTEARRAY].
|
||||
|
||||
|
||||
-spec deserialize_type(binary()) -> {aeb_fate_data:fate_type_type(), binary()}.
|
||||
-spec deserialize_type(binary()) -> {gmb_fate_data:fate_type_type(), binary()}.
|
||||
deserialize_type(<<?TYPE_INTEGER, Rest/binary>>) -> {integer, Rest};
|
||||
deserialize_type(<<?TYPE_BOOLEAN, Rest/binary>>) -> {boolean, Rest};
|
||||
deserialize_type(<<?TYPE_ANY, Rest/binary>>) -> {any, Rest};
|
||||
@@ -316,13 +317,13 @@ deserialize_types(N, Binary, Acc) ->
|
||||
%% -----------------------------------------------------
|
||||
|
||||
rlp_encode_int(S) when S >= 0 ->
|
||||
aeser_rlp:encode(binary:encode_unsigned(S)).
|
||||
gmser_rlp:encode(binary:encode_unsigned(S)).
|
||||
|
||||
|
||||
%% first byte of the binary gives the number of bytes we need <<129>> is 1, <<130>> = 2,
|
||||
%% so <<129, 0>> is <<0>> and <<130, 0, 0>> is <<0, 0>>
|
||||
rlp_decode_int(Binary) ->
|
||||
{Bin1, Rest} = aeser_rlp:decode_one(Binary),
|
||||
{Bin1, Rest} = gmser_rlp:decode_one(Binary),
|
||||
Int = binary:decode_unsigned(Bin1),
|
||||
ReEncode = rlp_encode_int(Int),
|
||||
case <<ReEncode/binary, Rest/binary>> == Binary of
|
||||
@@ -353,7 +354,7 @@ serialize_bits(B) when is_integer(B) ->
|
||||
B >= 0 -> <<?POS_BITS, (rlp_encode_int(Abs))/binary>>
|
||||
end.
|
||||
|
||||
-spec deserialize(binary()) -> aeb_fate_data:fate_type().
|
||||
-spec deserialize(binary()) -> gmb_fate_data:fate_type().
|
||||
deserialize(B) ->
|
||||
{T, <<>>} = deserialize2(B),
|
||||
T.
|
||||
@@ -406,7 +407,7 @@ deserialize2(<<?OBJECT, ?OTYPE_BYTES, Rest/binary>>) ->
|
||||
true = ?IS_FATE_STRING(String),
|
||||
{?FATE_BYTES(?FATE_STRING_VALUE(String)), Rest2};
|
||||
deserialize2(<<?OBJECT, ObjectType, Rest/binary>>) ->
|
||||
{A, Rest2} = aeser_rlp:decode_one(Rest),
|
||||
{A, Rest2} = gmser_rlp:decode_one(Rest),
|
||||
Val =
|
||||
case ObjectType of
|
||||
?OTYPE_ADDRESS -> ?FATE_ADDRESS(A);
|
||||
@@ -455,7 +456,7 @@ deserialize2(<<?MAP_ID, Rest/binary>>) ->
|
||||
{Id, Rest1} = rlp_decode_int(Rest),
|
||||
{?FATE_STORE_MAP(#{}, Id), Rest1};
|
||||
deserialize2(<<?VARIANT, Rest/binary>>) ->
|
||||
{AritiesBin, <<Tag:8, Rest2/binary>>} = aeser_rlp:decode_one(Rest),
|
||||
{AritiesBin, <<Tag:8, Rest2/binary>>} = gmser_rlp:decode_one(Rest),
|
||||
Arities = binary_to_list(AritiesBin),
|
||||
Size = length(Arities),
|
||||
if Tag > Size -> exit({too_large_tag_in_variant, Tag, Size});
|
||||
@@ -502,7 +503,7 @@ sort_and_check(List) ->
|
||||
|
||||
sort(KVList) ->
|
||||
SortFun = fun({K1, _}, {K2, _}) ->
|
||||
aeb_fate_data:elt(K1, K2)
|
||||
gmb_fate_data:elt(K1, K2)
|
||||
end,
|
||||
lists:sort(SortFun, KVList).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
-module(aeb_fate_generate_docs).
|
||||
-module(gmb_fate_generate_docs).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([generate_documentation/2, generate_documentation/3]).
|
||||
|
||||
@@ -26,7 +27,7 @@ generate_documentation(Filename, Fields, Filter) when is_function(Filter, 1) ->
|
||||
Instructions =
|
||||
lists:flatten(
|
||||
[gen_doc_for_op(Op, Fields)
|
||||
++ "\n" || Op <- aeb_fate_generate_ops:get_ops(), Filter(Op)]),
|
||||
++ "\n" || Op <- gmb_fate_generate_ops:get_ops(), Filter(Op)]),
|
||||
io:format(File, "~ts~ts~ts\n", [Header, Separator, Instructions]),
|
||||
file:close(File).
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
-module(aeb_fate_generate_ops).
|
||||
-module(gmb_fate_generate_ops).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ gen_and_halt/1
|
||||
, generate/0
|
||||
@@ -18,12 +19,12 @@ generate(Src, Include) ->
|
||||
check_defs(ops_defs()),
|
||||
Ops = get_ops(),
|
||||
%% io:format("ops: ~p\n", [Ops]),
|
||||
HrlFile = Include ++ "aeb_fate_opcodes.hrl",
|
||||
HrlFile = Include ++ "gmb_fate_opcodes.hrl",
|
||||
generate_header_file(HrlFile, Ops),
|
||||
generate_opcodes_ops(aeb_fate_opcodes, HrlFile, Src, Ops),
|
||||
generate_code_ops(aeb_fate_ops, Src, Ops),
|
||||
generate_scanner("aeb_fate_asm_scan.template", "aeb_fate_asm_scan.xrl", Src, Ops),
|
||||
gen_asm_pp(aeb_fate_pp, Src, Ops).
|
||||
generate_opcodes_ops(gmb_fate_opcodes, HrlFile, Src, Ops),
|
||||
generate_code_ops(gmb_fate_ops, Src, Ops),
|
||||
generate_scanner("gmb_fate_asm_scan.template", "gmb_fate_asm_scan.xrl", Src, Ops),
|
||||
gen_asm_pp(gmb_fate_pp, Src, Ops).
|
||||
|
||||
check_defs(List) ->
|
||||
true = check_numbering(0, lists:keysort(2, List)).
|
||||
@@ -333,7 +334,7 @@ generate_code_ops(Modulename, SrcDir, Ops) ->
|
||||
" and documentation for Fate "
|
||||
"instructions.\n")]),
|
||||
io:format(File, "-module(~w).\n\n", [Modulename]),
|
||||
io:format(File, "-include_lib(\"aebytecode/include/aeb_fate_data.hrl\").\n\n"
|
||||
io:format(File, "-include_lib(\"gmbytecode/include/gmb_fate_data.hrl\").\n\n"
|
||||
"-define(i(__X__), {immediate, __X__ }).\n\n"
|
||||
"-type fate_arg_immediate(T) :: {immediate, T}.\n"
|
||||
"-type fate_arg_var() :: {var, integer()}.\n"
|
||||
@@ -343,7 +344,7 @@ generate_code_ops(Modulename, SrcDir, Ops) ->
|
||||
" | fate_arg_var()\n"
|
||||
" | fate_arg_arg()\n"
|
||||
" | fate_arg_stack().\n\n"
|
||||
"-type fate_arg_immediate() :: {immediate, aeb_fate_data:fate_type()}.\n"
|
||||
"-type fate_arg_immediate() :: {immediate, gmb_fate_data:fate_type()}.\n"
|
||||
, []),
|
||||
io:format(File, "~s", [Types]),
|
||||
io:format(File, "-type fate_code() :: ~s\n~s .\n\n",
|
||||
@@ -388,15 +389,15 @@ gen_constructors(#{constructor := Function, format := ArgSpec,
|
||||
|
||||
gen_arg_type_specs([]) -> [];
|
||||
gen_arg_type_specs([a]) -> "fate_arg()";
|
||||
gen_arg_type_specs([is]) -> "aeb_fate_data:fate_string()";
|
||||
gen_arg_type_specs([ii]) -> "aeb_fate_data:fate_integer()";
|
||||
gen_arg_type_specs([li]) -> "[aeb_fate_data:fate_integer()]";
|
||||
gen_arg_type_specs([t]) -> "aeb_fate_data:fate_type_type()";
|
||||
gen_arg_type_specs([is]) -> "gmb_fate_data:fate_string()";
|
||||
gen_arg_type_specs([ii]) -> "gmb_fate_data:fate_integer()";
|
||||
gen_arg_type_specs([li]) -> "[gmb_fate_data:fate_integer()]";
|
||||
gen_arg_type_specs([t]) -> "gmb_fate_data:fate_type_type()";
|
||||
gen_arg_type_specs([a | Args]) -> "fate_arg(), " ++ gen_arg_type_specs(Args);
|
||||
gen_arg_type_specs([is | Args]) -> "aeb_fate_data:fate_string(), " ++ gen_arg_type_specs(Args);
|
||||
gen_arg_type_specs([ii | Args]) -> "aeb_fate_data:fate_integer(), " ++ gen_arg_type_specs(Args);
|
||||
gen_arg_type_specs([li | Args]) -> "[aeb_fate_data:fate_integer()], " ++ gen_arg_type_specs(Args);
|
||||
gen_arg_type_specs([t | Args]) -> "aeb_fate_data:fate_type_type(), " ++ gen_arg_type_specs(Args).
|
||||
gen_arg_type_specs([is | Args]) -> "gmb_fate_data:fate_string(), " ++ gen_arg_type_specs(Args);
|
||||
gen_arg_type_specs([ii | Args]) -> "gmb_fate_data:fate_integer(), " ++ gen_arg_type_specs(Args);
|
||||
gen_arg_type_specs([li | Args]) -> "[gmb_fate_data:fate_integer()], " ++ gen_arg_type_specs(Args);
|
||||
gen_arg_type_specs([t | Args]) -> "gmb_fate_data:fate_type_type(), " ++ gen_arg_type_specs(Args).
|
||||
|
||||
|
||||
gen_arg_names(_, []) ->
|
||||
@@ -428,7 +429,7 @@ ops_exports(Module, HrlFile, Exports) ->
|
||||
lists:flatten(io_lib:format(
|
||||
"-module(~w).\n\n"
|
||||
"-export([ ~s ]).\n\n"
|
||||
"-include_lib(\"aebytecode/" ++ HrlFile ++"\").\n\n"
|
||||
"-include_lib(\"gmbytecode/" ++ HrlFile ++"\").\n\n"
|
||||
"%%====================================================================\n"
|
||||
"%% API\n"
|
||||
"%%====================================================================\n",
|
||||
@@ -468,7 +469,7 @@ prelude(Doc) ->
|
||||
"%%%\n"
|
||||
"%%% === === N O T E : This file is generated do not edit. === ===\n"
|
||||
"%%%\n"
|
||||
"%%% Source is in aeb_fate_generate_ops.erl\n"
|
||||
"%%% Source is in gmb_fate_generate_ops.erl\n"
|
||||
"%%% @doc\n"
|
||||
"%%% "++Doc++
|
||||
"%%% @end\n"
|
||||
@@ -517,10 +518,10 @@ expand_types([T]) -> expand_type(T);
|
||||
expand_types([T|Ts]) ->expand_type(T) ++ ", " ++ expand_types(Ts).
|
||||
|
||||
expand_type(a) -> "fate_arg()";
|
||||
expand_type(is) -> "fate_arg_immediate(aeb_fate_data:fate_string())";
|
||||
expand_type(ii) -> "fate_arg_immediate(aeb_fate_data:fate_integer())";
|
||||
expand_type(li) -> "fate_arg_immediate([aeb_fate_data:fate_integer()])";
|
||||
expand_type(t) -> "aeb_fate_data:fate_type_type()".
|
||||
expand_type(is) -> "fate_arg_immediate(gmb_fate_data:fate_string())";
|
||||
expand_type(ii) -> "fate_arg_immediate(gmb_fate_data:fate_integer())";
|
||||
expand_type(li) -> "fate_arg_immediate([gmb_fate_data:fate_integer()])";
|
||||
expand_type(t) -> "gmb_fate_data:fate_type_type()".
|
||||
|
||||
generate_scanner(TemplateFile, Outfile, Path, Ops) ->
|
||||
{ok, Template} = file:read_file(filename:join(Path,TemplateFile)),
|
||||
@@ -540,8 +541,8 @@ insert_tokens_in_template(<<"%%% ###REPLACEWITHNOTE###", Rest/binary >>, Tokens)
|
||||
"%%%\n"
|
||||
"%%% === === N O T E : This file is generated do not edit. === ===\n"
|
||||
"%%%\n"
|
||||
"%%% Source is in aeb_fate_generate_ops.erl\n"
|
||||
"%%% and aeb_fate_asm_scan.template"
|
||||
"%%% Source is in gmb_fate_generate_ops.erl\n"
|
||||
"%%% and gmb_fate_asm_scan.template"
|
||||
| insert_tokens_in_template(Rest, Tokens)];
|
||||
insert_tokens_in_template(<<B,Rest/binary>>, Tokens) ->
|
||||
[B|insert_tokens_in_template(Rest, Tokens)].
|
||||
@@ -557,9 +558,9 @@ gen_asm_pp(Module, Path, Ops) ->
|
||||
io:format(File,
|
||||
"-export([format_op/2]).\n\n"
|
||||
"format_arg(li, {immediate, LI}) ->\n"
|
||||
" aeb_fate_data:format(LI);\n"
|
||||
" gmb_fate_data:format(LI);\n"
|
||||
"format_arg(_, {immediate, I}) ->\n"
|
||||
" aeb_fate_data:format(I);\n"
|
||||
" gmb_fate_data:format(I);\n"
|
||||
"format_arg(a, {arg, N}) -> io_lib:format(\"arg~~p\", [N]);\n"
|
||||
"format_arg(a, {var, N}) when N < 0 -> io_lib:format(\"store~~p\", [-N]);\n"
|
||||
"format_arg(a, {var, N}) -> io_lib:format(\"var~~p\", [N]);\n"
|
||||
@@ -1,4 +1,5 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Functions for manipulating FATE maps. In particular for mediating
|
||||
@@ -6,9 +7,10 @@
|
||||
%%% fully or partially saved in the contract store.
|
||||
%%% @end
|
||||
%%% -------------------------------------------------------------------
|
||||
-module(aeb_fate_maps).
|
||||
-module(gmb_fate_maps).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-include("aeb_fate_data.hrl").
|
||||
-include("gmb_fate_data.hrl").
|
||||
|
||||
-export([ allocate_store_maps/2
|
||||
, has_store_maps/1
|
||||
@@ -31,11 +33,11 @@
|
||||
-define(STORE_MAP_THRESHOLD, 100).
|
||||
-endif.
|
||||
|
||||
-type fate_value() :: aeb_fate_data:fate_type().
|
||||
-type fate_value() :: gmb_fate_data:fate_type().
|
||||
-type fate_value_or_tombstone() :: fate_value() | ?FATE_MAP_TOMBSTONE.
|
||||
-type id() :: integer().
|
||||
-type used_ids() :: list(id()).
|
||||
-type maps() :: #{ id() => aeb_fate_data:fate_map() | aeb_fate_data:fate_store_map() }.
|
||||
-type maps() :: #{ id() => gmb_fate_data:fate_map() | gmb_fate_data:fate_store_map() }.
|
||||
|
||||
%% -- Allocating store maps --------------------------------------------------
|
||||
|
||||
@@ -70,7 +72,7 @@ allocate_store_maps(Used, ?FATE_VARIANT(Arities, Tag, Vals), Maps) ->
|
||||
allocate_store_maps(Used, Val, Maps) when ?IS_FATE_MAP(Val) ->
|
||||
{Used1, KVs, Maps1} = allocate_store_maps_m(Used, ?FATE_MAP_VALUE(Val), Maps),
|
||||
Val1 = ?MAKE_FATE_MAP(KVs),
|
||||
case byte_size(aeb_fate_encoding:serialize(Val1)) < ?STORE_MAP_THRESHOLD of
|
||||
case byte_size(gmb_fate_encoding:serialize(Val1)) < ?STORE_MAP_THRESHOLD of
|
||||
true -> {Used1, Val1, Maps1};
|
||||
false ->
|
||||
{Id, Used2} = next_id(Used1),
|
||||
@@ -97,7 +99,7 @@ allocate_store_maps_m(Used, Val, Maps) ->
|
||||
|
||||
%% -- Unfolding store maps ---------------------------------------------------
|
||||
|
||||
-type unfold_fun() :: fun((id()) -> aeb_fate_data:fate_map()).
|
||||
-type unfold_fun() :: fun((id()) -> gmb_fate_data:fate_map()).
|
||||
|
||||
-spec unfold_store_maps(unfold_fun(), fate_value_or_tombstone()) -> fate_value_or_tombstone().
|
||||
unfold_store_maps(_Unfold, ?FATE_MAP_TOMBSTONE = Val) -> Val;
|
||||
@@ -1,4 +1,5 @@
|
||||
-module(aeb_heap).
|
||||
-module(gmb_heap).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ to_binary/1
|
||||
, to_binary/2
|
||||
@@ -22,8 +23,8 @@
|
||||
|
||||
-export_type([binary_value/0, heap_value/0, offset/0, heap_fragment/0]).
|
||||
|
||||
-include_lib("aebytecode/include/aeb_typerep_def.hrl").
|
||||
-include_lib("aebytecode/include/aeb_heap.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_typerep_def.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_heap.hrl").
|
||||
|
||||
-type word() :: non_neg_integer().
|
||||
-type pointer() :: word().
|
||||
@@ -112,7 +113,7 @@ pmap_size(#pmap{data = Data}) when is_map(Data) ->
|
||||
|
||||
%% -- Value to binary --------------------------------------------------------
|
||||
|
||||
-spec to_binary(aeb_aevm_data:data()) -> aeb_aevm_data:heap().
|
||||
-spec to_binary(gmb_aevm_data:data()) -> gmb_aevm_data:heap().
|
||||
%% Encode the data as a heap where the first word is the value (for unboxed
|
||||
%% types) or a pointer to the value (for boxed types).
|
||||
to_binary(Data) ->
|
||||
@@ -131,10 +132,10 @@ to_binary1(Data,_Address) when is_integer(Data) ->
|
||||
{Data,<<>>};
|
||||
to_binary1(Data, Address) when is_binary(Data) ->
|
||||
%% a string
|
||||
Words = aeb_memory:binary_to_words(Data),
|
||||
Words = gmb_memory:binary_to_words(Data),
|
||||
{Address,<<(size(Data)):256, << <<W:256>> || W <- Words>>/binary>>};
|
||||
to_binary1({contract_bytearray, FateCode}, Address) when is_binary(FateCode) ->
|
||||
Words = aeb_memory:binary_to_words(FateCode),
|
||||
Words = gmb_memory:binary_to_words(FateCode),
|
||||
{Address,<<(size(FateCode)):256, << <<W:256>> || W <- Words>>/binary>>};
|
||||
to_binary1(none, Address) -> to_binary1({variant, 0, []}, Address);
|
||||
to_binary1({some, Value}, Address) -> to_binary1({variant, 1, [Value]}, Address);
|
||||
@@ -1,12 +1,15 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Memory speifics that compiler and VM need to agree upon
|
||||
%%% @end
|
||||
%%% Updated : 22 Jan 2025
|
||||
%%% Created : 19 Dec 2018
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeb_memory).
|
||||
-module(gmb_memory).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([binary_to_words/1]).
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Opcodes
|
||||
%%% @end
|
||||
%%% Created : 2 Oct 2017
|
||||
%%% Updated : 22 Jan 2025
|
||||
%%% Created : 02 Oct 2017
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeb_opcodes).
|
||||
-module(gmb_opcodes).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([ dup/1
|
||||
, mnemonic/1
|
||||
@@ -17,7 +20,7 @@
|
||||
, swap/1
|
||||
]).
|
||||
|
||||
-include_lib("aebytecode/include/aeb_opcodes.hrl").
|
||||
-include_lib("gmbytecode/include/gmb_opcodes.hrl").
|
||||
|
||||
|
||||
%%====================================================================
|
||||
@@ -1,18 +1,21 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Handle interaction with the aeternity chain
|
||||
%%% Handle interaction with the gmternity chain
|
||||
%%% through calls to AEternity primitive operations at address 0.
|
||||
%%% @end
|
||||
%%% Updated : 22 Jan 2025
|
||||
%%% Created : 18 Dec 2018
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeb_primops).
|
||||
-module(gmb_primops).
|
||||
-vsn("3.4.1").
|
||||
-export([ is_local_primop_op/1
|
||||
, op_needs_type_check/1
|
||||
]).
|
||||
|
||||
-include("aeb_opcodes.hrl").
|
||||
-include("gmb_opcodes.hrl").
|
||||
|
||||
is_local_primop_op(Op) when ?PRIM_CALL_IN_MAP_RANGE(Op) -> true;
|
||||
is_local_primop_op(Op) when ?PRIM_CALL_IN_CRYPTO_RANGE(Op) -> true;
|
||||
@@ -1,12 +1,12 @@
|
||||
{application, aebytecode,
|
||||
[{description, "Bytecode definitions, serialization and deserialization for aeternity."},
|
||||
{vsn, "3.4.0"},
|
||||
{application, gmbytecode,
|
||||
[{description, "Bytecode definitions, serialization and deserialization for the Gajumaru."},
|
||||
{vsn, "3.4.1"},
|
||||
{registered, []},
|
||||
{applications,
|
||||
[kernel,
|
||||
stdlib,
|
||||
eblake2,
|
||||
aeserialization,
|
||||
gmserialization,
|
||||
getopt
|
||||
]},
|
||||
{env,[]},
|
||||
@@ -1,4 +1,5 @@
|
||||
-module(aefateasm).
|
||||
-module(gmfateasm).
|
||||
-vsn("3.4.1").
|
||||
|
||||
-export([main/1]).
|
||||
|
||||
@@ -9,7 +10,7 @@
|
||||
, {outfile, $o, "out", string, "Output file (experimental)"} ]).
|
||||
|
||||
usage() ->
|
||||
getopt:usage(?OPT_SPEC, "aefateasm").
|
||||
getopt:usage(?OPT_SPEC, "gmfateasm").
|
||||
|
||||
main(Args) ->
|
||||
case getopt:parse(?OPT_SPEC, Args) of
|
||||
@@ -43,8 +44,8 @@ assemble(File, Opts) ->
|
||||
Verbose = proplists:get_value(verbose, Opts, false),
|
||||
case proplists:get_value(outfile, Opts, undefined) of
|
||||
undefined ->
|
||||
Asm = aeb_fate_asm:read_file(File),
|
||||
{Env, BC} = aeb_fate_asm:asm_to_bytecode(Asm, Opts),
|
||||
Asm = gmb_fate_asm:read_file(File),
|
||||
{Env, BC} = gmb_fate_asm:asm_to_bytecode(Asm, Opts),
|
||||
case Verbose of
|
||||
true ->
|
||||
io:format("Env: ~0p~n", [Env]);
|
||||
@@ -52,6 +53,6 @@ assemble(File, Opts) ->
|
||||
end,
|
||||
io:format("Code: ~0p~n", [BC]);
|
||||
OutFile ->
|
||||
aeb_fate_asm:assemble_file(File, OutFile, Opts)
|
||||
gmb_fate_asm:assemble_file(File, OutFile, Opts)
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user