Compile character literals
This commit is contained in:
parent
b7153b1d75
commit
3c6e06e99a
@ -379,7 +379,7 @@ global_env() ->
|
|||||||
%% Abort
|
%% Abort
|
||||||
{"abort", Fun1(String, A)}])
|
{"abort", Fun1(String, A)}])
|
||||||
, types = MkDefs(
|
, types = MkDefs(
|
||||||
[{"int", 0}, {"bool", 0}, {"string", 0}, {"address", 0},
|
[{"int", 0}, {"bool", 0}, {"char", 0}, {"string", 0}, {"address", 0},
|
||||||
{"hash", {[], {alias_t, Bytes(32)}}},
|
{"hash", {[], {alias_t, Bytes(32)}}},
|
||||||
{"signature", {[], {alias_t, Bytes(64)}}},
|
{"signature", {[], {alias_t, Bytes(64)}}},
|
||||||
{"bits", 0},
|
{"bits", 0},
|
||||||
@ -909,6 +909,8 @@ infer_expr(_Env, Body={bool, As, _}) ->
|
|||||||
{typed, As, Body, {id, As, "bool"}};
|
{typed, As, Body, {id, As, "bool"}};
|
||||||
infer_expr(_Env, Body={int, As, _}) ->
|
infer_expr(_Env, Body={int, As, _}) ->
|
||||||
{typed, As, Body, {id, As, "int"}};
|
{typed, As, Body, {id, As, "int"}};
|
||||||
|
infer_expr(_Env, Body={char, As, _}) ->
|
||||||
|
{typed, As, Body, {id, As, "char"}};
|
||||||
infer_expr(_Env, Body={string, As, _}) ->
|
infer_expr(_Env, Body={string, As, _}) ->
|
||||||
{typed, As, Body, {id, As, "string"}};
|
{typed, As, Body, {id, As, "string"}};
|
||||||
infer_expr(_Env, Body={bytes, As, Bin}) ->
|
infer_expr(_Env, Body={bytes, As, Bin}) ->
|
||||||
@ -1179,6 +1181,8 @@ infer_prefix({IntOp,As}) when IntOp =:= '-' ->
|
|||||||
|
|
||||||
free_vars({int, _, _}) ->
|
free_vars({int, _, _}) ->
|
||||||
[];
|
[];
|
||||||
|
free_vars({char, _, _}) ->
|
||||||
|
[];
|
||||||
free_vars({string, _, _}) ->
|
free_vars({string, _, _}) ->
|
||||||
[];
|
[];
|
||||||
free_vars({bool, _, _}) ->
|
free_vars({bool, _, _}) ->
|
||||||
|
@ -131,6 +131,7 @@ init_type_env() ->
|
|||||||
#{ ["int"] => ?type(integer),
|
#{ ["int"] => ?type(integer),
|
||||||
["bool"] => ?type(boolean),
|
["bool"] => ?type(boolean),
|
||||||
["bits"] => ?type(bits),
|
["bits"] => ?type(bits),
|
||||||
|
["char"] => ?type(integer),
|
||||||
["string"] => ?type(string),
|
["string"] => ?type(string),
|
||||||
["address"] => ?type(address),
|
["address"] => ?type(address),
|
||||||
["hash"] => ?type(hash),
|
["hash"] => ?type(hash),
|
||||||
@ -259,6 +260,7 @@ expr_to_fcode(Env, Expr) ->
|
|||||||
|
|
||||||
%% Literals
|
%% Literals
|
||||||
expr_to_fcode(_Env, _Type, {int, _, N}) -> {int, N};
|
expr_to_fcode(_Env, _Type, {int, _, N}) -> {int, N};
|
||||||
|
expr_to_fcode(_Env, _Type, {char, _, N}) -> {int, N};
|
||||||
expr_to_fcode(_Env, _Type, {bool, _, B}) -> {bool, B};
|
expr_to_fcode(_Env, _Type, {bool, _, B}) -> {bool, B};
|
||||||
expr_to_fcode(_Env, _Type, {string, _, S}) -> {string, S};
|
expr_to_fcode(_Env, _Type, {string, _, S}) -> {string, S};
|
||||||
|
|
||||||
@ -595,12 +597,10 @@ pat_to_fcode(Env, _Type, {app, _, {typed, _, {C, _, _} = Con, _}, Pats}) when C
|
|||||||
{con, As, I, [pat_to_fcode(Env, Pat) || Pat <- Pats]};
|
{con, As, I, [pat_to_fcode(Env, Pat) || Pat <- Pats]};
|
||||||
pat_to_fcode(Env, _Type, {tuple, _, Pats}) ->
|
pat_to_fcode(Env, _Type, {tuple, _, Pats}) ->
|
||||||
{tuple, [ pat_to_fcode(Env, Pat) || Pat <- Pats ]};
|
{tuple, [ pat_to_fcode(Env, Pat) || Pat <- Pats ]};
|
||||||
pat_to_fcode(_Env, _Type, {bool, _, B}) ->
|
pat_to_fcode(_Env, _Type, {bool, _, B}) -> {bool, B};
|
||||||
{bool, B};
|
pat_to_fcode(_Env, _Type, {int, _, N}) -> {int, N};
|
||||||
pat_to_fcode(_Env, _Type, {int, _, N}) ->
|
pat_to_fcode(_Env, _Type, {char, _, N}) -> {int, N};
|
||||||
{int, N};
|
pat_to_fcode(_Env, _Type, {string, _, N}) -> {string, N};
|
||||||
pat_to_fcode(_Env, _Type, {string, _, N}) ->
|
|
||||||
{string, N};
|
|
||||||
pat_to_fcode(Env, _Type, {list, _, Ps}) ->
|
pat_to_fcode(Env, _Type, {list, _, Ps}) ->
|
||||||
lists:foldr(fun(P, Qs) ->
|
lists:foldr(fun(P, Qs) ->
|
||||||
{'::', pat_to_fcode(Env, P), Qs}
|
{'::', pat_to_fcode(Env, P), Qs}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user