]> git.mdlowis.com Git - proto/aas.git/commitdiff
stubbed out inference and checking functions
authorMike Lowis <mike.lowis@gentex.com>
Thu, 14 Dec 2023 19:47:12 +0000 (14:47 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Thu, 14 Dec 2023 19:47:12 +0000 (14:47 -0500)
cerise.rb

index 18d3b847cd93d95b04d7c85f0b59e3ad8f1739f6..e79220cc5cb076f3b3f835a5942097218223e89d 100755 (executable)
--- a/cerise.rb
+++ b/cerise.rb
@@ -651,21 +651,22 @@ class TypeChecker
   end
 
   def check(env, expr, type)
-#    if (expr.is_a? IR::If)
-#      check_ifexpr(env, expr, type)
-#    elsif (expr.is_a? IR::Func)
-#      check_func(env, expr, type)
-#    elsif (expr.is_a? IR::Var)
-#      check_var(env, expr, type)
-#    elsif (expr.is_a? IR::Let)
-#      check_let(env, expr, type)
-##    elsif (expr.is_a? IR::Apply)
-##      check_apply(env, expr, type)
-
-    if (expr.is_a? IR::Op)
+    if expr.is_a? IR::Const
+      check_const(env, expr, type)
+    elsif (expr.is_a? IR::Op)
       check_op(env, expr, type)
-    elsif (expr.is_a? IR::Var)
+    elsif expr.is_a? IR::Var
       check_var(env, expr, type)
+#    elsif expr.is_a? IR::Let
+#      check_let(env, expr, type)
+#    elsif expr.is_a? IR::If
+#      check_ifexpr(env, expr, type)
+#    elsif expr.is_a? IR::Set
+#      check_set(env, expr, type)
+#    elsif expr.is_a? IR::Func
+#      check_func(env, expr, type)
+#    elsif expr.is_a? IR::Apply
+#      check_apply(env, expr, type)
     else
       etype = infer(env, expr)
       if type != etype
@@ -674,7 +675,7 @@ class TypeChecker
     end
     expr.type = type
   end
-#
+
   def infer(env, expr)
     if expr.is_a? IR::Func
       infer_func(env, expr)
@@ -702,6 +703,10 @@ class TypeChecker
 
   private
 
+  ##
+  # TYPE INFERENCE
+  ##
+
   def infer_func(env, expr)
     raise "unimplemented"
   end
@@ -747,6 +752,53 @@ class TypeChecker
     raise "unimplemented"
   end
 
+  ##
+  # TYPE CHECKING
+  ##
+
+
+  def check_func(env, expr, type)
+    raise "unimplemented"
+  end
+
+  def check_return(env, expr, type)
+    raise "unimplemented"
+  end
+
+  def check_const(env, expr, type)
+    expr, type.type
+  end
+
+  def check_var(env, expr, type)
+    etype = infer(env, expr)
+    if (etype.class == String)
+      expr.type = type
+      env.set_type(expr.name, type)
+    elsif expr.type != type
+      error(expr.loc, "expected #{type}, received #{etype}")
+    end
+    type
+  end
+
+  def check_def(env, expr, type)
+    raise "unimplemented"
+  end
+
+  def check_set(env, expr, type)
+    raise "unimplemented"
+  end
+
+  def check_op(env, expr, type)
+    raise "unimplemented"
+  end
+
+  def check_call(env, expr, type)
+    raise "unimplemented"
+  end
+
+  def check_if(env, expr, type)
+    raise "unimplemented"
+  end
 
 
 
@@ -792,16 +844,6 @@ class TypeChecker
 #    check(env, expr.else, type)
 #  end
 #
-  def check_var(env, expr, type)
-    etype = infer(env, expr)
-    if (etype.class == String)
-      expr.type = type
-      env.set_type(expr.name, type)
-    elsif expr.type != type
-      error(expr.loc, "expected #{type}, received #{etype}")
-    end
-    type
-  end
 #
 #  def verify(cond, loc, msg)
 #    error(loc, msg) if not cond