Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case BlockExp(vals, vars, defs, classes, exps) =>
- var tenv1 = tenv
- var ctenv1 = ctenv
- for (v <- vals) {
- val t = typeCheck(v.exp, tenv1, ctenv1)
- val ot = getType(v.opttype, ctenv1)
- checkTypesEqual(t, ot, v)
- tenv1 = tenv1 + (v.x -> ot.getOrElse(t))
- }
- for (va <- vars) {
- val t = typeCheck(va.exp, tenv1, ctenv1)
- val ot = getType(va.opttype, ctenv1)
- checkTypesEqual(t, ot, va)
- tenv1 = tenv1 + (va.x -> MutableType(ot.getOrElse(t)))
- }
- for (d <- defs) {
- d match {
- case DefDecl(fun, params, optrestype, body) =>
- val funtype = makeFunType(d)
- tenv1 = tenv1 + (fun -> funtype)
- for (param <- params)
- val in = getType(param.opttype, ctenv1)
- tenv1 = tenv1 + (param.x -> in.getOrElse(throw TypeError(s"Type annotation missing at parameter ${param.x}", param)))
- val out = typeCheck(body, tenv1, ctenv1)
- val optionaltype = getType(optrestype, ctenv1)
- checkTypesEqual(out, optionaltype, body)
- case null => throw TypeError(s"Expected DefDecl", e)
- }
- }
- for (c <- classes) {
- val ct2 = makeStaticClassType(c, ctenv, classes)
- ctenv1 = ctenv1 + (c.klass -> ct2) //første del
- val cp2 = c.params
- val ctp2 = ct2.params
- if (cp2.length != ctp2.length) throw TypeError("what", e) //hvis ikke de er lige lange er de ikke ens
- for ((t, e) <- (cp2.zip(ctp2)))
- tenv1 = tenv1 + (t.x -> e)
- typeCheck(c.body, tenv1, ctenv1)
- }
- if (exps.size > 0) {
- for (e <- exps)
- typeCheck(e, tenv1, ctenv1)
- typeCheck(exps.last, tenv1, ctenv1)
- }
- else {
- unitType //tom type
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement