File: OpenSCAD_argenv.dats

package info (click to toggle)
ats2-lang 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,064 kB
  • sloc: ansic: 389,637; makefile: 7,123; lisp: 812; sh: 657; php: 573; python: 387; perl: 365
file content (163 lines) | stat: -rw-r--r-- 2,368 bytes parent folder | download | duplicates (4)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
(* ****** ****** *)
//
// Author: Hongwei Xi
// Start time: May, 2017
// Authoremail: gmhwxiATgmailDOTcom
//
(* ****** ****** *)
(*
** For implementing
** a DSL that supports
** ATS and OpenSCAD co-programming
*)
(* ****** ****** *)
//
#staload "./../SATS/OpenSCAD.sats"
//
(* ****** ****** *)
//
implement
scadexp_int
  (i0) = SCADEXPint(i0)
implement
scadexp_bool
  (b0) = SCADEXPbool(b0)
implement
scadexp_float
  (f0) = SCADEXPfloat(f0)
implement
scadexp_string
  (s0) = SCADEXPstring(s0)
//
implement
scadarg_int(i0) =
SCADARGexp(SCADEXPint(i0))
implement
scadarg_bool(b0) =
SCADARGexp(SCADEXPbool(b0))
implement
scadarg_float(f0) =
SCADARGexp(SCADEXPfloat(f0))
implement
scadarg_string(s0) =
SCADARGexp(SCADEXPstring(s0))
//
(* ****** ****** *)
//
assume
scadenv_type = List0(@(label, scadexp))
//
(* ****** ****** *)
//
implement
scadenv_nil() = list_nil()
//
implement
scadenv_sing(l, x) =
let
  val lx = @(l, x) in list_sing(lx)
end // end of [scadenv_sing]
//
(* ****** ****** *)
//
implement
scadenv_is_nil(env) = list_is_nil(env)
implement
scadenv_is_cons(env) = list_is_cons(env)
//
(* ****** ****** *)

implement
fprint_scadenv
  (out, lxs) = let
//
fun
loop
(
 i: int, lxs: scadenv
) : void =
(
case+ lxs of
| list_nil() => ()
| list_cons(lx, lxs) =>
  (
    if i > 0
      then fprint(out, ", ");
    // end of [if]
    fprint!(out, lx.0, "=", lx.1);
    loop(i+1, lxs)
  )
)
//
in
  loop(0, lxs)
end // end of [fprint_scadenv]

(* ****** ****** *)

implement
scadenv_search
  (lxs, k0) =
  loop(lxs) where
{
//
fun
loop
(
  lxs: scadenv
) : Option_vt(scadexp) =
(
case+ lxs of
| list_nil
    () => None_vt()
  // list_nil
| list_cons(lx, lxs) =>
  if (k0 = lx.0)
    then Some_vt(lx.1) else loop(lxs)
  // end of [if]
)
//
} (* end of [scadenv_search] *)

(* ****** ****** *)
//
implement
scadenv_insert_any
  (lxs, k0, x0) =
(
  scadenv_insert_any(lxs, k0, x0)
)
//
(* ****** ****** *)
//
implement
scadenv_femit
  (out, lxs) = let
//
fun
loop
(
 i: int, lxs: scadenv
) : void =
(
case+ lxs of
| list_nil() => ()
| list_cons(lx, lxs) =>
    loop(i+1, lxs) where
  {
    val () =
    if i > 0
      then fprint(out, ", ")
    // end of [if]
    val () = fprint!(out, lx.0, "=")
    val () = scadexp_femit(out, lx.1)
  }
) (* end of [loop] *)
//
in
  loop(0, lxs)
end // end of [scadenv_femit]

(* ****** ****** *)

(* end of [OpenSCAD_argenv.dats] *)