mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-07 07:18:48 +00:00
public extern is added
This commit is contained in:
parent
1a849e7a56
commit
5f673e766c
2 changed files with 14 additions and 7 deletions
|
|
@ -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] {
|
||||
|
|
|
|||
15
src/SM.ml
15
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue