Add builtin bit field type
This commit is contained in:
@@ -348,6 +348,30 @@ ast_body(?qid_app(["String", "concat"], [String1, String2], _, _), Icode) ->
|
||||
ast_body(?qid_app(["String", "sha3"], [String], _, _), Icode) ->
|
||||
#unop{ op = 'sha3', rand = ast_body(String, Icode) };
|
||||
|
||||
%% -- Bits
|
||||
ast_body(?qid_app(["Bits", "test"], [Bits, Ix], _, _), Icode) ->
|
||||
%% (Bits bsr Ix) band 1
|
||||
#binop{ op = 'band'
|
||||
, left = #binop{ op = 'bsr', left = ast_body(Ix, Icode), right = ast_body(Bits, Icode) }
|
||||
, right = #integer{ value = 1 } };
|
||||
ast_body(?qid_app(["Bits", "set"], [Bits, Ix], _, _), Icode) ->
|
||||
%% Bits bor (1 bsl Ix)
|
||||
#binop{ op = 'bor'
|
||||
, left = ast_body(Bits, Icode)
|
||||
, right = #binop{ op = 'bsl', left = ast_body(Ix, Icode), right = #integer{ value = 1 } } };
|
||||
ast_body(?qid_app(["Bits", "clear"], [Bits, Ix], _, _), Icode) ->
|
||||
%% Bits band (bnot (1 bsl Ix))
|
||||
#binop{ op = 'band'
|
||||
, left = ast_body(Bits, Icode)
|
||||
, right = #unop{ op = 'bnot'
|
||||
, rand = #binop{ op = 'bsl'
|
||||
, left = ast_body(Ix, Icode)
|
||||
, right = #integer{ value = 1 } } } };
|
||||
ast_body({qid, _, ["Bits", "zero"]}, _Icode) ->
|
||||
#integer{ value = 0 };
|
||||
ast_body(?qid_app(["Bits", "sum"], [Bits], _, _), Icode) ->
|
||||
builtin_call(popcount, [ast_body(Bits, Icode), #integer{ value = 0 }]);
|
||||
|
||||
%% -- Conversion
|
||||
ast_body(?qid_app(["Int", "to_str"], [Int], _, _), Icode) ->
|
||||
builtin_call(int_to_str, [ast_body(Int, Icode)]);
|
||||
|
||||
Reference in New Issue
Block a user