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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
(* ****** ****** *)
(*
** For implementing a DSL
** that supports ATS and OpenSCAD co-programming
*)
(* ****** ****** *)
//
datatype
point2 =
POINT2 of (double, double)
datatype
point3 =
POINT3 of (double, double, double)
//
(* ****** ****** *)
//
fun
point2_make_int2
(x: int, y: int): point2
fun
point2_make_float2
(x: double, y: double): point2
//
fun
point3_make_int3
(x: int, y: int, z: int): point3
fun
point3_make_float3
(x: double, y: double, z: double): point3
//
symintr point2 point3
//
overload
point2 with point2_make_int2
overload
point2 with point2_make_float2
//
overload
point3 with point3_make_int3
overload
point3 with point3_make_float3
//
(* ****** ****** *)
//
abstype label_type
typedef label = label_type
//
(* ****** ****** *)
//
fun
label_make(x: string): label
//
symintr label
overload label with label_make
//
(* ****** ****** *)
//
fun
fprint_label
: fprint_type(label)
//
overload
fprint with fprint_label
//
(* ****** ****** *)
//
fun
eq_label_label(label, label): bool
fun
neq_label_label(label, label): bool
//
fun
compare_label_label
(l1: label, l2: label): int(*sgn*)
//
overload = with eq_label_label
overload != with neq_label_label
overload compare with compare_label_label
//
(* ****** ****** *)
abstype scadenv_type
typedef scadenv = scadenv_type
(* ****** ****** *)
datatype
scadexp =
//
| SCADEXPnil of ()
//
| SCADEXPint of (int)
//
| SCADEXPbool of (bool)
//
| SCADEXPfloat of double
//
| SCADEXPstring of string
//
| SCADEXPvec of scadexplst
//
| SCADEXPcond of
(scadexp, scadexp, scadexp)
// SCADEXPcond
//
| SCADEXPextfcall of
(string(*fun*), scadenv, scadarglst)
// SCADEXPextfcall
//
(* end of [scadexp] *)
and scadarg =
//
| SCADARGexp of scadexp
| SCADARGlabexp of (label, scadexp)
//
where
scadexplst = List0(scadexp)
and
scadarglst = List0(scadarg)
(* ****** ****** *)
//
fun
scadexp_int(int): scadexp
fun
scadexp_bool(bool): scadexp
fun
scadexp_float(double): scadexp
fun
scadexp_string(string): scadexp
(* ****** ****** *)
//
fun
scadarg_int(int): scadarg
fun
scadarg_bool(bool): scadarg
fun
scadarg_float(double): scadarg
fun
scadarg_string(string): scadarg
//
(* ****** ****** *)
(*
//
datatype
scadvec(n:int) =
{n:int}
SCADVEC of list(scadexp, n)
//
typedef scadv2d = scadvec(2)
typedef scadv3d = scadvec(3)
typedef scadvec0 = [n:int | n >= 0] scadvec(n)
//
macdef
SCADV2D(x, y) =
SCADVEC($list{scadexp}(,(x), ,(y)))
macdef
SCADV3D(x, y, z) =
SCADVEC($list{scadexp}(,(x), ,(y), ,(z)))
//
*)
(* ****** ****** *)
//
datatype
scadobj =
//
| SCADOBJfapp of
(
string(*fopr*), scadenv, scadarglst
) (* SCADOBJfopr *)
//
| SCADOBJmapp of (string(*mopr*), scadobjlst)
//
| SCADOBJtfmapp of (scadtfm(*mtfm*), scadobjlst)
//
| SCADOBJextcode of (string(*code*)) // HX: external one-liners
//
// end of [scadobj]
and
scadtfm =
//
| SCADTFMident of ()
//
| SCADTFMcompose of (scadtfm, scadtfm)
//
| SCADTFMextmcall of
(
string(*fmod*), scadenv(*env*), scadarglst(*args*)
) (* SCADTFMextmcall *)
//
where scadobjlst = List0(scadobj)
//
(* ****** ****** *)
//
fun
scadenv_nil(): scadenv
fun
scadenv_sing
(l: label, x: scadexp): scadenv
//
(* ****** ****** *)
//
fun
scadenv_is_nil(scadenv): bool
fun
scadenv_is_cons(scadenv): bool
//
(* ****** ****** *)
//
fun
scadobj_fapp
( fopr: string
, env0: scadenv, args: scadarglst): scadobj
//
fun
scadobj_fapp_enil
(fopr: string, args: scadarglst): scadobj
//
(* ****** ****** *)
//
fun
scadtfm_extmcall
( fmod: string
, env0: scadenv, args: scadarglst): scadtfm
//
(* ****** ****** *)
//
fun
fprint_scadenv : fprint_type(scadenv)
//
fun
fprint_scadexp : fprint_type(scadexp)
fun
fprint_scadarg : fprint_type(scadarg)
//
(* ****** ****** *)
overload fprint with fprint_scadenv
overload fprint with fprint_scadexp
overload fprint with fprint_scadarg
(* ****** ****** *)
//
fun
scadenv_search
(env: scadenv, k: label): Option_vt(scadexp)
fun
scadenv_insert_any
(env: scadenv, k: label, x: scadexp): scadenv
//
(* ****** ****** *)
//
fun
scadexp_femit(FILEref, scadexp): void
fun
scadexplst_femit(FILEref, scadexplst): void
//
(* ****** ****** *)
//
fun
scadenv_femit(FILEref, scadenv): void
//
(* ****** ****** *)
//
fun
scadarg_femit(FILEref, scadarg): void
fun
scadarglst_femit(FILEref, scadarglst): void
fun
scadarglst_env_femit(FILEref, scadarglst, scadenv): void
//
(* ****** ****** *)
//
fun
scadobj_femit
(out: FILEref, int(*indent*), scadobj): void
fun
scadtfm_femit
(out: FILEref, int(*indent*), scadtfm): void
//
fun
scadobjlst_femit
(out: FILEref, int(*indent*), scadobjlst): void
//
(* ****** ****** *)
(* end of [OpenSCAD.sats] *)
|