1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465(**************************************************************************)(* *)(* OCaml *)(* *)(* Damien Doligez, projet Para, INRIA Rocquencourt *)(* *)(* Copyright 1997 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(* Internals of forcing lazy values. *)type'at='alazy_texceptionUndefinedletraise_undefined=Obj.repr(fun()->raiseUndefined)externalmake_forward:Obj.t->Obj.t->unit="caml_obj_make_forward"(* Assume [blk] is a block with tag lazy *)letforce_lazy_block(blk:'arglazy_t)=letclosure=(Obj.obj(Obj.field(Obj.reprblk)0):unit->'arg)inObj.set_field(Obj.reprblk)0raise_undefined;tryletresult=closure()inmake_forward(Obj.reprblk)(Obj.reprresult);resultwithe->Obj.set_field(Obj.reprblk)0(Obj.repr(fun()->raisee));raisee(* Assume [blk] is a block with tag lazy *)letforce_val_lazy_block(blk:'arglazy_t)=letclosure=(Obj.obj(Obj.field(Obj.reprblk)0):unit->'arg)inObj.set_field(Obj.reprblk)0raise_undefined;letresult=closure()inmake_forward(Obj.reprblk)(Obj.reprresult);result(* [force] is not used, since [Lazy.force] is declared as a primitive
whose code inlines the tag tests of its argument. This function is
here for the sake of completeness, and for debugging purpose. *)letforce(lzv:'arglazy_t)=letx=Obj.reprlzvinlett=Obj.tagxinift=Obj.forward_tagthen(Obj.obj(Obj.fieldx0):'arg)elseift<>Obj.lazy_tagthen(Obj.objx:'arg)elseforce_lazy_blocklzvletforce_val(lzv:'arglazy_t)=letx=Obj.reprlzvinlett=Obj.tagxinift=Obj.forward_tagthen(Obj.obj(Obj.fieldx0):'arg)elseift<>Obj.lazy_tagthen(Obj.objx:'arg)elseforce_val_lazy_blocklzv