aboutsummaryrefslogtreecommitdiff
path: root/src/expressions/shift_expr.ml
blob: 17cce95c80b850222795389e0e9da050fb969d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(*
This file is part of licht.

licht is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

licht 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with licht.  If not, see <http://www.gnu.org/licenses/>.
*)

module Shift_Ref = struct

  type 'a t = (int * int) -> ScTypes.Refs.t
  type 'a obs = (int * int) -> ScTypes.Refs.t

  let _shift (vector_x, vector_y) ((x, y), (fixed_x, fixed_y)) =
    let x' = if fixed_x then x else x + vector_x
    and y' = if fixed_y then y else y + vector_y in
      (x', y'), (fixed_x, fixed_y)

  let cell t shift =
    ScTypes.Refs.cell (_shift shift t)


  let range c1 c2 shift =
    ScTypes.Refs.range (_shift shift c1) (_shift shift c2)

  let observe elem shift = elem shift

end

module Shift_Expr = struct

  type t = (int * int) -> ScTypes.Expr.t
  type obs =  (int * int) -> ScTypes.Expr.t

  module R = Shift_Ref
  module T = Id_type

  let observe f x = f x

  let value t vector = ScTypes.Expr.value (T.observe t)

  let ref r vector = ScTypes.Expr.ref (R.observe r vector)

  let call0 ident vector = ScTypes.Expr.call0 ident

  let call1 ident p1 vector = ScTypes.Expr.call1 ident (observe p1 vector)

  let call2 ident p1 p2 vector = ScTypes.Expr.call2  ident (observe p1 vector) (observe p2 vector)

  let call3 ident p1 p2 p3 vector = ScTypes.Expr.call3 ident (observe p1 vector) (observe p2 vector) (observe p3 vector)

  let expression e vector = ScTypes.Expr.expression (observe e vector)

  let callN ident (params: t list) vector = ScTypes.Expr.callN ident (List.map (fun x -> observe x vector) params)

end

include Shift_Expr