Compile character literals

This commit is contained in:
Ulf Norell 2019-04-26 11:09:59 +02:00
parent b7153b1d75
commit 3c6e06e99a
2 changed files with 11 additions and 7 deletions

View File

@ -379,7 +379,7 @@ global_env() ->
%% Abort
{"abort", Fun1(String, A)}])
, 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)}}},
{"signature", {[], {alias_t, Bytes(64)}}},
{"bits", 0},
@ -909,6 +909,8 @@ infer_expr(_Env, Body={bool, As, _}) ->
{typed, As, Body, {id, As, "bool"}};
infer_expr(_Env, Body={int, As, _}) ->
{typed, As, Body, {id, As, "int"}};
infer_expr(_Env, Body={char, As, _}) ->
{typed, As, Body, {id, As, "char"}};
infer_expr(_Env, Body={string, As, _}) ->
{typed, As, Body, {id, As, "string"}};
infer_expr(_Env, Body={bytes, As, Bin}) ->
@ -1179,6 +1181,8 @@ infer_prefix({IntOp,As}) when IntOp =:= '-' ->
free_vars({int, _, _}) ->
[];
free_vars({char, _, _}) ->
[];
free_vars({string, _, _}) ->
[];
free_vars({bool, _, _}) ->

View File

@ -131,6 +131,7 @@ init_type_env() ->
#{ ["int"] => ?type(integer),
["bool"] => ?type(boolean),
["bits"] => ?type(bits),
["char"] => ?type(integer),
["string"] => ?type(string),
["address"] => ?type(address),
["hash"] => ?type(hash),
@ -259,6 +260,7 @@ expr_to_fcode(Env, Expr) ->
%% Literals
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, {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]};
pat_to_fcode(Env, _Type, {tuple, _, Pats}) ->
{tuple, [ pat_to_fcode(Env, Pat) || Pat <- Pats ]};
pat_to_fcode(_Env, _Type, {bool, _, B}) ->
{bool, B};
pat_to_fcode(_Env, _Type, {int, _, N}) ->
{int, N};
pat_to_fcode(_Env, _Type, {string, _, N}) ->
{string, N};
pat_to_fcode(_Env, _Type, {bool, _, B}) -> {bool, B};
pat_to_fcode(_Env, _Type, {int, _, N}) -> {int, N};
pat_to_fcode(_Env, _Type, {char, _, N}) -> {int, N};
pat_to_fcode(_Env, _Type, {string, _, N}) -> {string, N};
pat_to_fcode(Env, _Type, {list, _, Ps}) ->
lists:foldr(fun(P, Qs) ->
{'::', pat_to_fcode(Env, P), Qs}