12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667(**************************************************************************)(* *)(* 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)(* 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()in(* do set_field BEFORE set_tag *)Obj.set_field(Obj.reprblk)0(Obj.reprresult);Obj.set_tag(Obj.reprblk)Obj.forward_tag;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()in(* do set_field BEFORE set_tag *)Obj.set_field(Obj.reprblk)0(Obj.reprresult);Obj.set_tag(Obj.reprblk)(Obj.forward_tag);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