public extern is added

This commit is contained in:
Dmitry Boulytchev 2019-11-25 15:26:00 +03:00
parent 1a849e7a56
commit 5f673e766c
2 changed files with 14 additions and 7 deletions

View file

@ -328,7 +328,7 @@ module Expr =
(* leave a scope *) | Leave (* leave a scope *) | Leave
(* intrinsic (for evaluation) *) | Intrinsic of (t config, t config) arrow (* intrinsic (for evaluation) *) | Intrinsic of (t config, t config) arrow
(* control (for control flow) *) | Control of (t config, t * t config) arrow (* control (for control flow) *) | Control of (t config, t * t config) arrow
and decl = [`Local | `Public | `Extern] * [`Fun of string list * t | `Variable of t option] and decl = [`Local | `Public | `Extern | `PublicExtern ] * [`Fun of string list * t | `Variable of t option]
with show,html with show,html
(* Reff : parsed expression should return value Reff (look for ":="); (* Reff : parsed expression should return value Reff (look for ":=");
@ -805,7 +805,7 @@ module Definition =
%"at" s:STRING {Infix.at coord (unquote s) newp} %"at" s:STRING {Infix.at coord (unquote s) newp}
| f:(%"before" {Infix.before} | %"after" {Infix.after}) s:STRING {f coord (unquote s) newp ass}; | f:(%"before" {Infix.before} | %"after" {Infix.after}) s:STRING {f coord (unquote s) newp ass};
head[infix]: head[infix]:
m:(%"external" {`Extern} | %"public" {`Public})? %"fun" name:LIDENT {unopt_mod m, name, name, infix} m:(%"external" {`Extern} | %"public" e:(%"external")? {match e with None -> `Public | _ -> `PublicExtern})? %"fun" name:LIDENT {unopt_mod m, name, name, infix}
| m:(%"public" {`Public})? ass:(%"infix" {`Nona} | %"infixl" {`Lefta} | %"infixr" {`Righta}) | m:(%"public" {`Public})? ass:(%"infix" {`Nona} | %"infixl" {`Lefta} | %"infixr" {`Righta})
l:$ op:(s:STRING {unquote s}) l:$ op:(s:STRING {unquote s})
md:position[ass][l#coord][op] { md:position[ass][l#coord][op] {
@ -820,7 +820,7 @@ module Definition =
| _ -> name, (m,`Variable value) | _ -> name, (m,`Variable value)
}; };
parse[infix][expr][def]: parse[infix][expr][def]:
m:(%"local" {`Local} | %"public" {`Public} | %"external" {`Extern}) m:(%"local" {`Local} | %"public" e:(%"external")? {match e with None -> `Public | Some _ -> `PublicExtern} | %"external" {`Extern})
locs:!(Util.list (local_var m infix expr def)) ";" {locs, infix} locs:!(Util.list (local_var m infix expr def)) ";" {locs, infix}
| - <(m, orig_name, name, infix')> : head[infix] -"(" -args:!(Util.list0 arg) -")" | - <(m, orig_name, name, infix')> : head[infix] -"(" -args:!(Util.list0 arg) -")"
(body:expr[def][infix'][Expr.Void] { (body:expr[def][infix'][Expr.Void] {

View file

@ -350,7 +350,14 @@ object (self : 'self)
method nlocals = scope.nlocals method nlocals = scope.nlocals
method get_decls = method get_decls =
List.map (function (name, `Extern) -> EXTERN name | (name, `Public) -> PUBLIC name | _ -> invalid_arg "must not happen") @@ List.flatten @@
List.map
(function
| (name, `Extern) -> [EXTERN name]
| (name, `Public) -> [PUBLIC name]
| (name, `PublicExtern) -> [PUBLIC name; EXTERN name]
| _ -> invalid_arg "must not happen"
) @@
List.filter (function (_, `Local) -> false | _ -> true) decls List.filter (function (_, `Local) -> false | _ -> true) decls
method push_scope = {< method push_scope = {<
@ -431,7 +438,7 @@ object (self : 'self)
| _ -> | _ ->
raise (Semantic_error (Printf.sprintf "external/public definitions ('%s') not allowed in local scopes" name)) raise (Semantic_error (Printf.sprintf "external/public definitions ('%s') not allowed in local scopes" name))
method add_name (name : string) (m : [`Local | `Extern | `Public]) (mut : bool) = {< method add_name (name : string) (m : [`Local | `Extern | `Public | `PublicExtern]) (mut : bool) = {<
decls = (name, m) :: decls; decls = (name, m) :: decls;
scope = { scope = {
scope with scope with
@ -452,7 +459,7 @@ object (self : 'self)
method fun_internal_name (name : string) = method fun_internal_name (name : string) =
(match scope.st with State.G _ -> label | _ -> scope_label scope_index) name (match scope.st with State.G _ -> label | _ -> scope_label scope_index) name
method add_fun_name (name : string) (m : [`Local | `Extern | `Public]) = method add_fun_name (name : string) (m : [`Local | `Extern | `Public | `PublicExtern]) =
let name' = self#fun_internal_name name in let name' = self#fun_internal_name name in
let st' = let st' =
match scope.st with match scope.st with
@ -473,7 +480,7 @@ object (self : 'self)
let name' = self#fun_internal_name (Printf.sprintf "lambda_%d" lam_index) in let name' = self#fun_internal_name (Printf.sprintf "lambda_%d" lam_index) in
{< fundefs = add_fun fundefs (to_fundef name' args body scope.st); lam_index = lam_index + 1 >}, name' {< fundefs = add_fun fundefs (to_fundef name' args body scope.st); lam_index = lam_index + 1 >}, name'
method add_fun (name : string) (args : string list) (m : [`Local | `Extern | `Public]) (body : Expr.t) = method add_fun (name : string) (args : string list) (m : [`Local | `Extern | `Public | `PublicExtern]) (body : Expr.t) =
let name' = self#fun_internal_name name in let name' = self#fun_internal_name name in
match m with match m with
| `Extern -> self | `Extern -> self