Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the atom '$sesterl' to every bare message sent by programs written in Sesterl #44

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ let plugin_name =

let plugin_url =
"https://github.com/gfngfn/rebar_sesterl_plugin.git"


let message_tag_atom =
"'$sesterl'"
14 changes: 11 additions & 3 deletions src/outputErlangCode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ and stringify_ast (nmap : name_map) (ast : ast) =

| ICase(ast0, branches) ->
let s0 = iter ast0 in
let sbrs = branches |> List.map (stringify_branch nmap) in
let sbrs = branches |> List.map (stringify_case_branch nmap) in
Printf.sprintf "case %s of %s end" s0 (String.concat "; " sbrs)

| IReceive(branches) ->
let sbrs = branches |> List.map (stringify_branch nmap) in
let sbrs = branches |> List.map (stringify_receive_branch nmap) in
Printf.sprintf "receive %s end" (String.concat "; " sbrs)

| ITuple(es) ->
Expand Down Expand Up @@ -477,14 +477,22 @@ and mapify_label_assoc (nmap : name_map) (emap : ast LabelAssoc.t) =
) emap Alist.empty |> Alist.to_list |> String.concat ", "


and stringify_branch (nmap : name_map) (br : branch) =
and stringify_case_branch (nmap : name_map) (br : branch) =
match br with
| IBranch(pat, ast1) ->
let spat = stringify_pattern pat in
let s1 = stringify_ast nmap ast1 in
Printf.sprintf "%s -> %s" spat s1


and stringify_receive_branch (nmap : name_map) (br : branch) =
match br with
| IBranch(pat, ast1) ->
let spat = stringify_pattern pat in
let s1 = stringify_ast nmap ast1 in
Printf.sprintf "{%s, %s} -> %s" Constants.message_tag_atom spat s1


and stringify_pattern (ipat : pattern) =
match ipat with
| IPUnit -> unit_atom
Expand Down
4 changes: 2 additions & 2 deletions src/primitives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ let primitive_definitions = [
};
target = {
target_name = "send";
parameters = ["X"; "Y"];
code = "X ! Y, ok";
parameters = ["Pid"; "Msg"];
code = Printf.sprintf "Pid ! {%s, Msg}, ok" Constants.message_tag_atom;
};
};
{
Expand Down