/// <summary> /// 変数の型推論 /// </summary> /// <param name="expr">変数</param> static void TypeinfVarExpr(MVarExpr expr) { if (env.IsDefined(expr.Name)) { expr.Type = env.Lookup(expr.Pos, expr.Name); } else { throw new NotImplementedException(); } }
/// <summary> /// 変数のコンパイル /// </summary> /// <param name="ilgen">IL Generator</param> /// <param name="expr">変数</param> static void CompileVarExpr(ILGenerator ilgen, MVarExpr expr) { var builder = _scope_manager.Lookup(expr.Pos, expr.Name); if (builder is LocalVar) { ilgen.Emit(OpCodes.Ldloc, ((LocalVar)builder).Builder); } else if (builder is ParamVar) { ilgen.Emit(OpCodes.Ldarg, ((ParamVar)builder).Index); } else { throw new NotImplementedException(); } }
/// <summary> /// 通常の関数呼び出しの型推論 /// </summary> /// <param name="fun_name">関数名</param> /// <param name="expr">式</param> static void TypeinfNormalCallExpr(MVarExpr fun_name, MCallExpr expr) { var name = fun_name.Name; if (!function_table.ContainsKey(name)) { throw new MError( string.Format("{0}: 関数 {1} は未定義です。", fun_name.Pos, name)); } var func = function_table[name]; if (expr.Args.Count != func.Args.Count) { throw new MError( string.Format("{0}: 関数 {1} のパラメータの数が不正です。", expr.Pos, name)); } for (int i = 0; i < expr.Args.Count; i++) { Unification(expr.Pos, expr.Args[i].Type, func.Args[i].Type); } expr.Type = func.RetType; }