From 5f673e766cc34904bf1f6259e60e6a84e3ac2b8f Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Mon, 25 Nov 2019 15:26:00 +0300 Subject: [PATCH] public extern is added --- src/Language.ml | 6 +++--- src/SM.ml | 15 +++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Language.ml b/src/Language.ml index 59fea8020..16f2113f3 100644 --- a/src/Language.ml +++ b/src/Language.ml @@ -328,7 +328,7 @@ module Expr = (* leave a scope *) | Leave (* intrinsic (for evaluation) *) | Intrinsic of (t config, 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 (* Reff : parsed expression should return value Reff (look for ":="); @@ -805,7 +805,7 @@ module Definition = %"at" s:STRING {Infix.at coord (unquote s) newp} | f:(%"before" {Infix.before} | %"after" {Infix.after}) s:STRING {f coord (unquote s) newp ass}; 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}) l:$ op:(s:STRING {unquote s}) md:position[ass][l#coord][op] { @@ -820,7 +820,7 @@ module Definition = | _ -> name, (m,`Variable value) }; 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} | - <(m, orig_name, name, infix')> : head[infix] -"(" -args:!(Util.list0 arg) -")" (body:expr[def][infix'][Expr.Void] { diff --git a/src/SM.ml b/src/SM.ml index 32e5e3654..f51f3fc57 100644 --- a/src/SM.ml +++ b/src/SM.ml @@ -350,7 +350,14 @@ object (self : 'self) method nlocals = scope.nlocals 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 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)) - 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; scope = { scope with @@ -452,7 +459,7 @@ object (self : 'self) method fun_internal_name (name : string) = (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 st' = match scope.st with @@ -473,7 +480,7 @@ object (self : 'self) 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' - 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 match m with | `Extern -> self