|
| 1 | +#![allow(unused_imports)] |
| 2 | +#![allow(dead_code)] |
| 3 | +#![allow(unused_variables)] |
| 4 | +use crate::arenas::{CoreArena, TypeArena}; |
| 5 | +use crate::builtin::{constructors, tycons}; |
| 6 | +use crate::types::{Constructor, Flex, Scheme, Tycon, Type, TypeVar}; |
| 7 | +use crate::{ |
| 8 | + Datatype, Decl, Expr, ExprId, ExprKind, Lambda, Pat, PatKind, Row, Rule, SortedRecord, TypeId, |
| 9 | +}; |
| 10 | +use sml_util::interner::Symbol; |
| 11 | + |
| 12 | +use ir::Var; |
| 13 | +use sml_ir as ir; |
| 14 | + |
| 15 | +pub struct LoweringCtx {} |
| 16 | + |
| 17 | +impl LoweringCtx { |
| 18 | + fn lower_sym(&mut self, sym: &Symbol) -> Symbol { |
| 19 | + todo!() |
| 20 | + } |
| 21 | + |
| 22 | + fn lower_constructor(&mut self, con: Constructor) -> ir::Constructor { |
| 23 | + ir::Constructor { |
| 24 | + name: self.lower_sym(&con.name), |
| 25 | + tycon: self.lower_tycon(&con.tycon), |
| 26 | + tag: con.tag, |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + fn lower_ty(&mut self, ty: &Type<'_>) -> ir::Type { |
| 31 | + match ty { |
| 32 | + Type::Var(tyvar) => match tyvar.ty() { |
| 33 | + Some(ty) => self.lower_ty(ty), |
| 34 | + None => self.lower_tyvar(tyvar.id), |
| 35 | + }, |
| 36 | + Type::Record(fields) => { |
| 37 | + let args = fields.iter().map(|ty| self.lower_ty(ty.data)).collect(); |
| 38 | + ir::Type::Con(ir::Tycon::Tuple, args) |
| 39 | + } |
| 40 | + Type::Flex(flex) => match flex.ty() { |
| 41 | + Some(ty) => self.lower_ty(ty), |
| 42 | + None => { |
| 43 | + // This should likely be an error, flexible type never instantiated |
| 44 | + ir::Type::Con(ir::Tycon::Unit, vec![]) |
| 45 | + } |
| 46 | + }, |
| 47 | + Type::Con(con, args) => ir::Type::Con( |
| 48 | + self.lower_tycon(&con.name), |
| 49 | + args.iter().map(|ty| self.lower_ty(ty)).collect(), |
| 50 | + ), |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + fn lower_tyvar(&mut self, tyvar: usize) -> ir::Type { |
| 55 | + ir::Type::Var(tyvar) |
| 56 | + } |
| 57 | + |
| 58 | + fn lower_tycon(&mut self, tycon: &Symbol) -> ir::Tycon { |
| 59 | + match tycon { |
| 60 | + &sml_util::interner::S_ARROW => ir::Tycon::Arrow, |
| 61 | + &sml_util::interner::S_UNIT => ir::Tycon::Unit, |
| 62 | + &sml_util::interner::S_CHAR => ir::Tycon::Char, |
| 63 | + &sml_util::interner::S_INT => ir::Tycon::Int, |
| 64 | + &sml_util::interner::S_STRING => ir::Tycon::String, |
| 65 | + &sml_util::interner::S_REF => ir::Tycon::Ref, |
| 66 | + &sml_util::interner::S_LIST => ir::Tycon::List, |
| 67 | + &sml_util::interner::S_BOOL => ir::Tycon::Bool, |
| 68 | + &sml_util::interner::S_EXN => ir::Tycon::Exn, |
| 69 | + _ => ir::Tycon::Datatype(*tycon), |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + fn lower_expr(&mut self, expr: &Expr<'_>) -> ir::Block { |
| 74 | + let ty = self.lower_ty(expr.ty); |
| 75 | + match &expr.kind { |
| 76 | + ExprKind::App(e1, e2) => { |
| 77 | + let b1 = self.lower_expr(e1); |
| 78 | + let b2 = self.lower_expr(e2); |
| 79 | + todo!() |
| 80 | + } |
| 81 | + ExprKind::Case(e1, rules) => todo!(), |
| 82 | + ExprKind::Con(con, tys) => todo!(), |
| 83 | + ExprKind::Const(con) => todo!(), |
| 84 | + ExprKind::Handle(e1, sym, e2) => todo!(), |
| 85 | + ExprKind::Lambda(lam) => todo!(), |
| 86 | + ExprKind::Let(decls, e1) => todo!(), |
| 87 | + ExprKind::List(exs) => todo!(), |
| 88 | + ExprKind::Primitive(sym) => todo!(), |
| 89 | + ExprKind::Raise(e1) => todo!(), |
| 90 | + ExprKind::Record(rows) => todo!(), |
| 91 | + ExprKind::Seq(exs) => todo!(), |
| 92 | + ExprKind::Var(sym) => { |
| 93 | + ir::Expr::Var(Var(self.lower_sym(sym), self.lower_ty(expr.ty))); |
| 94 | + todo!() |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments