Skip to content

Commit

Permalink
Remove the distinction between [Def] and [Defun].
Browse files Browse the repository at this point in the history
There was no strong reason for this distinction to exist.
  • Loading branch information
fpottier committed Jul 7, 2024
1 parent 794fd2c commit 4c94688
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
11 changes: 2 additions & 9 deletions src/cppo_eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -556,19 +556,12 @@ and expand_node ?(top = false) g env0 (x : node) =
env


| `Def (loc, name, body)->
| `Def (loc, name, formals, body)->
g.require_location := true;
if M.mem name env0 then
error loc (sprintf "%S is already defined" name)
else
M.add name (EDef (loc, [], body, env0)) env0

| `Defun (loc, name, arg_names, body) ->
g.require_location := true;
if M.mem name env0 then
error loc (sprintf "%S is already defined" name)
else
M.add name (EDef (loc, arg_names, body, env0)) env0
M.add name (EDef (loc, formals, body, env0)) env0

| `Undef (loc, name) ->
g.require_location := true;
Expand Down
7 changes: 4 additions & 3 deletions src/cppo_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ node:
let body = $2 @ [safe_space] in
let _, pos2 = $3 in
`Def ((pos1, pos2), name, body) }
let formals = [] in
`Def ((pos1, pos2), name, formals, body) }

| DEFUN def_args1 CL_PAREN unode_list0 ENDEF
{ let (pos1, _), name = $1 in
let args = $2 in
let formals = $2 in
(* Additional spacing is needed for cases like 'foo()bar'
where 'foo()' expands into 'abc', giving 'abcbar'
Expand All @@ -117,7 +118,7 @@ node:
let body = $4 @ [safe_space] in
let _, pos2 = $5 in
`Defun ((pos1, pos2), name, args, body) }
`Def ((pos1, pos2), name, formals, body) }

| DEFUN CL_PAREN
{ error (fst (fst $1), snd $2)
Expand Down
5 changes: 3 additions & 2 deletions src/cppo_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ and arith_expr = (* signed int64 *)

type node =
[ `Ident of (loc * string * actuals)
| `Def of (loc * macro * body)
| `Defun of (loc * macro * formals * body)
(* the list [actuals] is empty if and only if no parentheses
are used at this macro invocation site. *)
| `Def of (loc * macro * formals * body)
(* the list [formals] is empty if and only if no parentheses
are used at this macro definition site. *)
| `Undef of (loc * macro)
| `Include of (loc * string)
| `Ext of (loc * string * string)
Expand Down
5 changes: 3 additions & 2 deletions src/cppo_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ type node =
[ `Ident of (loc * string * actuals)
(* the list [actuals] is empty if and only if no parentheses
are used at this macro invocation site. *)
| `Def of (loc * macro * body)
| `Defun of (loc * macro * formals * body)
| `Def of (loc * macro * formals * body)
(* the list [formals] is empty if and only if no parentheses
are used at this macro definition site. *)
| `Undef of (loc * macro)
| `Include of (loc * string)
| `Ext of (loc * string * string)
Expand Down

0 comments on commit 4c94688

Please sign in to comment.