mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-29 01:58:48 +00:00
Return expression eliminated
This commit is contained in:
parent
7eb3e223b8
commit
297139c72a
114 changed files with 37 additions and 1018 deletions
|
|
@ -379,7 +379,6 @@ module Expr =
|
|||
(* loop with a pre-condition *) | While of t * t
|
||||
(* loop with a post-condition *) | Repeat of t * t
|
||||
(* pattern-matching *) | Case of t * (Pattern.t * t) list * Loc.t * atr
|
||||
(* return statement *) | Return of t option
|
||||
(* ignore a value *) | Ignore of t
|
||||
(* unit value *) | Unit
|
||||
(* entering the scope *) | Scope of (string * decl) list * t
|
||||
|
|
@ -540,7 +539,6 @@ module Expr =
|
|||
eval conf k (schedule_list [e; Control (fun (st, i, o, e::vs) -> (if Value.to_int e <> 0 then seq s expr else Skip), (st, i, o, vs))])
|
||||
| Repeat (s, e) ->
|
||||
eval conf (seq (While (Binop ("==", e, Const 0), s)) k) s
|
||||
| Return e -> (match e with None -> (st, i, o, []) | Some e -> eval (st, i, o, []) Skip e)
|
||||
| Case (e, bs, _, _)->
|
||||
let rec branch ((st, i, o, v::vs) as conf) = function
|
||||
| [] -> failwith (Printf.sprintf "Pattern matching failed: no branch is selected while matching %s\n" (show(Value.t) (fun _ -> "<expr>") (fun _ -> "<state>") v))
|
||||
|
|
@ -786,7 +784,6 @@ module Expr =
|
|||
Scope (defs, Repeat (s, e))
|
||||
| _ -> Repeat (s, e)
|
||||
}
|
||||
| %"return" e:basic[infix][Val]? => {isVoid atr} => {Return e}
|
||||
| %"case" l:$ e:parse[infix][Val] %"of" bs:!(Util.listBy)[ostap ("|")][ostap (!(Pattern.parse) -"->" scope[infix][atr])] %"esac"{Case (e, bs, l#coord, atr)}
|
||||
| l:$ %"lazy" e:basic[infix][Val] => {notRef atr} :: (not_a_reference l) => {env#add_import "Lazy"; ignore atr (Call (Var "makeLazy", [Lambda ([], e)]))}
|
||||
| l:$ %"eta" e:basic[infix][Val] => {notRef atr} :: (not_a_reference l) => {let name = env#get_tmp in ignore atr (Lambda ([name], Call (e, [Var name])))}
|
||||
|
|
@ -1270,7 +1267,7 @@ let run_parser cmd =
|
|||
"while"; "do"; "od";
|
||||
"repeat"; "until";
|
||||
"for";
|
||||
"fun"; "local"; "public"; "external"; "return"; "import";
|
||||
"fun"; "local"; "public"; "external"; "import";
|
||||
"length";
|
||||
"string";
|
||||
"case"; "of"; "esac"; "when";
|
||||
|
|
|
|||
|
|
@ -869,11 +869,6 @@ let compile cmd ((imports, infixes), p) =
|
|||
let env, flag, body = compile_expr false check env s in
|
||||
env, false, [LABEL loop] @ body @ (if flag then [LABEL check] else []) @ se @ (if fe then [LABEL lexp] else []) @ [CJMP ("z", loop)]
|
||||
|
||||
| Expr.Return (Some e) -> let lret, env = env#get_label in
|
||||
add_code (compile_expr true lret env e) lret false [JMP env#end_label] (* [RET] *)
|
||||
|
||||
| Expr.Return None -> env, false, [CONST 0; (*RET*) JMP env#end_label]
|
||||
|
||||
| Expr.Leave -> env, false, []
|
||||
|
||||
| Expr.Case (e, brs, loc, atr) ->
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
let version = "Version 1.00, 2b9adec08, Mon Jan 25 01:22:56 2021 +0300"
|
||||
let version = "Version 1.10, 7eb3e223b, Mon Jan 25 01:38:59 2021 +0300"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue