91 |
dim = checkDim (cxt, dim), |
dim = checkDim (cxt, dim), |
92 |
shape = checkShape (cxt, shape) |
shape = checkShape (cxt, shape) |
93 |
} |
} |
94 |
| PT.T_Array(ty, dims) => raise Fail "Array type" |
| PT.T_Array(ty, dims) => raise Fail "Array type not supported" |
95 |
(* end case *)) |
(* end case *)) |
96 |
|
|
97 |
fun checkLit lit = (case lit |
fun checkLit lit = (case lit |
139 |
case (ty1, ty2) |
case (ty1, ty2) |
140 |
of (Ty.T_Bool, Ty.T_Bool) => |
of (Ty.T_Bool, Ty.T_Bool) => |
141 |
(AST.E_Cond(e1', AST.E_Lit(Literal.Bool true), e2'), Ty.T_Bool) |
(AST.E_Cond(e1', AST.E_Lit(Literal.Bool true), e2'), Ty.T_Bool) |
142 |
| _ => raise Fail "arguments to \"||\" must have bool type" |
| _ => err (cxt, [S "arguments to \"||\" must have bool type"]) |
143 |
(* end case *) |
(* end case *) |
144 |
end |
end |
145 |
| PT.E_AndAlso(e1, e2) => let |
| PT.E_AndAlso(e1, e2) => let |
149 |
case (ty1, ty2) |
case (ty1, ty2) |
150 |
of (Ty.T_Bool, Ty.T_Bool) => |
of (Ty.T_Bool, Ty.T_Bool) => |
151 |
(AST.E_Cond(e1', e2', AST.E_Lit(Literal.Bool false)), Ty.T_Bool) |
(AST.E_Cond(e1', e2', AST.E_Lit(Literal.Bool false)), Ty.T_Bool) |
152 |
| _ => raise Fail "arguments to \"||\" must have bool type" |
| _ => err (cxt, [S "arguments to \"&&\" must have bool type"]) |
153 |
(* end case *) |
(* end case *) |
154 |
end |
end |
155 |
| PT.E_BinOp(e1, rator, e2) => let |
| PT.E_BinOp(e1, rator, e2) => let |
207 |
S " expected: ", TYS domTy, S "\n", |
S " expected: ", TYS domTy, S "\n", |
208 |
S " but found: ", TYS tys, S "\n" |
S " but found: ", TYS tys, S "\n" |
209 |
]) |
]) |
210 |
| _ => raise Fail "application of non-function" |
| _ => err(cxt, [S "application of non-function ", V f]) |
211 |
(* end case *)) |
(* end case *)) |
212 |
| NONE => raise Fail "unknown function" |
| NONE => err(cxt, [S "unknown function ", A f]) |
213 |
(* end case *) |
(* end case *) |
214 |
end |
end |
215 |
| PT.E_Cons args => let |
| PT.E_Cons args => let |
222 |
in |
in |
223 |
if List.all chkTy tys |
if List.all chkTy tys |
224 |
then (AST.E_Cons args, resTy) |
then (AST.E_Cons args, resTy) |
225 |
else raise Fail "arguments of tensor construction must have same type" |
else err(cxt, [S "arguments of tensor construction must have same type"]) |
226 |
end |
end |
227 |
| _ => raise Fail "Invalid argument type for tensor construction" |
| _ => err(cxt, [S "Invalid argument type for tensor construction"]) |
228 |
(* end case *) |
(* end case *) |
229 |
end |
end |
230 |
| PT.E_Real e => (case checkExpr (env, cxt, e) |
| PT.E_Real e => (case checkExpr (env, cxt, e) |
231 |
of (e', Ty.T_Int) => |
of (e', Ty.T_Int) => |
232 |
(AST.E_Apply(BasisVars.i2r, [], [e'], Ty.realTy), Ty.realTy) |
(AST.E_Apply(BasisVars.i2r, [], [e'], Ty.realTy), Ty.realTy) |
233 |
| _ => raise Fail "argument of real conversion must be int" |
| _ => err(cxt, [S "argument of real conversion must be int"]) |
234 |
(* end case *)) |
(* end case *)) |
235 |
(* end case *)) |
(* end case *)) |
236 |
|
|
254 |
val x' = Var.new (x, kind, ty) |
val x' = Var.new (x, kind, ty) |
255 |
val (e', ty') = checkExpr (env, cxt, e) |
val (e', ty') = checkExpr (env, cxt, e) |
256 |
in |
in |
257 |
(* FIXME: check types *) |
(* FIXME: this check is not flexible enough; should allow lhs type to support |
258 |
(x, x', e') |
* fewer levels of differentiation than rhs provides. |
259 |
|
*) |
260 |
|
if U.matchType(ty, ty') |
261 |
|
then (x, x', e') |
262 |
|
else err(cxt, [ |
263 |
|
S "type of variable ", A x, |
264 |
|
S " does not match type of initializer\n", |
265 |
|
S " expected: ", TY ty, S "\n", |
266 |
|
S " but found: ", TY ty', S "\n" |
267 |
|
]) |
268 |
end |
end |
269 |
(* end case *)) |
(* end case *)) |
270 |
|
|
293 |
(* check that condition has bool type *) |
(* check that condition has bool type *) |
294 |
case ty |
case ty |
295 |
of Ty.T_Bool => () |
of Ty.T_Bool => () |
296 |
| _ => raise Fail "condition not boolean type" |
| _ => err(cxt, [S "condition not boolean type"]) |
297 |
(* end case *); |
(* end case *); |
298 |
(AST.S_IfThenElse(e', s', AST.S_Block[]), env) |
(AST.S_IfThenElse(e', s', AST.S_Block[]), env) |
299 |
end |
end |
305 |
(* check that condition has bool type *) |
(* check that condition has bool type *) |
306 |
case ty |
case ty |
307 |
of Ty.T_Bool => () |
of Ty.T_Bool => () |
308 |
| _ => raise Fail "condition not boolean type" |
| _ => err(cxt, [S "condition not boolean type"]) |
309 |
(* end case *); |
(* end case *); |
310 |
(AST.S_IfThenElse(e', s1', s2'), env) |
(AST.S_IfThenElse(e', s1', s2'), env) |
311 |
end |
end |
312 |
| PT.S_Assign(x, e) => (case Env.findVar (env, x) |
| PT.S_Assign(x, e) => (case Env.findVar (env, x) |
313 |
of NONE => raise Fail "undefined variable" |
of NONE => err(cxt, [ |
314 |
|
S "undefined variable ", A x |
315 |
|
]) |
316 |
| SOME x' => let |
| SOME x' => let |
317 |
val (e', ty) = checkExpr (env, cxt, e) |
(* FIXME: check for polymorphic variables *) |
318 |
|
val ([], ty) = Var.typeOf x' |
319 |
|
val (e', ty') = checkExpr (env, cxt, e) |
320 |
in |
in |
321 |
(* FIXME: check types *) |
if U.matchType(ty, ty') |
322 |
|
then (x, x', e') |
323 |
|
else err(cxt, [ |
324 |
|
S "type of assigned variable ", A x, |
325 |
|
S " does not match type of rhs\n", |
326 |
|
S " expected: ", TY ty, S "\n", |
327 |
|
S " but found: ", TY ty', S "\n" |
328 |
|
]); |
329 |
(* check that x' is mutable *) |
(* check that x' is mutable *) |
330 |
case Var.kindOf x' |
case Var.kindOf x' |
331 |
of Var.ActorStateVar => () |
of Var.ActorStateVar => () |
332 |
| Var.LocalVar => () |
| Var.LocalVar => () |
333 |
| _ => raise Fail "assignment to immutable variable" |
| _ => err(cxt, [ |
334 |
|
S "assignment to immutable variable ", A x |
335 |
|
]) |
336 |
(* end case *); |
(* end case *); |
337 |
(AST.S_Assign(x', e'), env) |
(AST.S_Assign(x', e'), env) |
338 |
end |
end |