From befbc76f89f3d8abc8da17caf91ea4a87ec96eeb Mon Sep 17 00:00:00 2001 From: xleroy Date: Wed, 28 Mar 2012 13:32:21 +0000 Subject: checklink: first import of Valentin Robert's validator for asm and link cparser: renamed Errors to Cerrors; removed packing into Cparser. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1856 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- checklink/Lens.ml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 checklink/Lens.ml (limited to 'checklink/Lens.ml') diff --git a/checklink/Lens.ml b/checklink/Lens.ml new file mode 100644 index 0000000..4335933 --- /dev/null +++ b/checklink/Lens.ml @@ -0,0 +1,32 @@ +type ('a, 'b) t = { + get: 'a -> 'b; + set: 'b -> 'a -> 'a; +} + +let ( |- ) f g x = g (f x) + +let modify l f a = + let oldval = l.get a in + let newval = f oldval in + l.set newval a + +let compose l1 l2 = { + get = l2.get |- l1.get; + set = l1.set |- modify l2 +} + +let _get a l = l.get a + +let _set v a l = l.set v a + +let _modify f l = modify l f + +let (|.) = _get + +let (^=) l v = fun a -> _set v a l + +let (^%=) l f = _modify f l + +let (|--) l1 l2 = compose l2 l1 + +let (--|) = compose -- cgit v1.2.3