Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file tail_call.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081(* Wasm_of_ocaml compiler
* http://www.ocsigen.org/js_of_ocaml/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)open!Stdlibletget_return~taili=matchiwith|Wasm_ast.Return(Some(LocalGety))->Somey|Push(LocalGety)whentail->Somey|_->Noneletrewrite_tail_call~yi=matchiwith|Wasm_ast.LocalSet(x,Call(symb,l))whenCode.Var.equalxy->Some(Wasm_ast.Return_call(symb,l))|LocalSet(x,Call_ref(ty,e,l))whenCode.Var.equalxy->Some(Return_call_ref(ty,e,l))|_->Noneletrecinstruction~taili=matchiwith|Wasm_ast.Loop(ty,l)->Wasm_ast.Loop(ty,instructions~taill)|Block(ty,l)->Block(ty,instructions~taill)|If(ty,e,l1,l2)->If(ty,e,instructions~taill1,instructions~taill2)|Return(Some(Call(symb,l)))->Return_call(symb,l)|Return(Some(Call_ref(ty,e,l)))->Return_call_ref(ty,e,l)|Push(Call(symb,l))whentail->Return_call(symb,l)|Push(Call_ref(ty,e,l))whentail->Return_call_ref(ty,e,l)|Push(Call_ref_)->i|Drop(BlockExpr(typ,l))->Drop(BlockExpr(typ,instructions~tail:falsel))|Drop_|LocalSet_|GlobalSet_|Br_table_|Br_|Br_if_|Return_|Throw_|Rethrow_|CallInstr_|Nop|Push_|ArraySet_|StructSet_|Return_call_|Return_call_ref_|Event_->iandinstructions~taill=matchlwith|[]->[]|[i]->[instruction~taili]|i::Nop::rem->instructions~tail(i::rem)|i::i'::Nop::rem->instructions~tail(i::i'::rem)|i::i'::(([]|[Event_])asevent_opt)->((* There can be an event at the end of the function, which we
should keep. *)matchget_return~taili'with|None->instruction~tail:falsei::instruction~taili'::event_opt|Somey->(matchrewrite_tail_call~yiwith|None->instruction~tail:falsei::instruction~taili'::event_opt|Somei''->i''::event_opt))|i::rem->instruction~tail:falsei::instructions~tailremletfl=instructions~tail:truel