]> git.mdlowis.com Git - proto/aas.git/commitdiff
added check_var but it's definitely broken
authorMike Lowis <mike.lowis@gentex.com>
Mon, 4 Dec 2023 21:30:16 +0000 (16:30 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Mon, 4 Dec 2023 21:30:16 +0000 (16:30 -0500)
cerise.rb

index 767b4e19ae17e334df40bc13eb23e971f287490d..f9969513b58408173261ca3d3378ee5e80801066 100755 (executable)
--- a/cerise.rb
+++ b/cerise.rb
@@ -664,6 +664,8 @@ class TypeChecker
 
     if (expr.is_a? IR::Op)
       check_op(env, expr, type)
+    elsif (expr.is_a? IR::Var)
+      check_var(env, expr, type)
     else
       etype = infer(env, expr)
       if type != etype
@@ -678,9 +680,8 @@ class TypeChecker
       infer_const(env, expr)
     elsif (expr.is_a? IR::Op)
       infer_op(env, expr)
-
-#    elsif expr.is_a? IR::Var
-#      infer_var(env, expr)
+    elsif expr.is_a? IR::Var
+      infer_var(env, expr)
 #    elsif expr.is_a? IR::Let
 #      infer_let(env, expr)
 #    elsif expr.is_a? IR::If
@@ -740,16 +741,16 @@ 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 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
@@ -786,12 +787,12 @@ class TypeChecker
   end
 
 
-#  def infer_var(env, expr)
-#    if not env.defined?(expr.name)
-#      error(expr.loc, "symbol '#{expr.name}' not defined")
-#    end
-#    expr.type = env[expr.name][:type]
-#  end
+  def infer_var(env, expr)
+    if env[expr.name].nil?
+      error(expr.loc, "symbol '#{expr.name}' not defined")
+    end
+    expr.type = env[expr.name][:type]
+  end
 #
 #  def infer_let(env, let)
 #    if let.body.nil?