public override CType CheckType() { var t1 = exp1.CheckType(); var t2 = exp2.CheckType(); return(t1 == CType.Double || t2 == CType.Double ? CType.Double : t1); }
public override CType CheckType() { var idType = Compiler.variables[id]; var expType = exp.CheckType(); if (idType != expType && !(idType == CType.Double && expType == CType.Int)) { new Error($"Cannot assign {expType} to {idType}"); } return(idType); }
public override void GenCode() { var t = exp.CheckType(); if (t == CType.Double) { EmitCode("call class [mscorlib]System.Globalization.CultureInfo [mscorlib]System.Globalization.CultureInfo::get_InvariantCulture()"); EmitCode("ldstr \"{0:0.000000}\""); } exp.GenCode(); string type = ""; switch (t) { case CType.Bool: type = "bool"; break; case CType.Int: type = "int32"; break; case CType.Double: type = "float64"; EmitCode("box [mscorlib]System.Double"); EmitCode("call string [mscorlib]System.String::Format(class [mscorlib]System.IFormatProvider, string, object)"); EmitCode("call void [System.Console]System.Console::Write(string)"); return; } EmitCode("call void [System.Console]System.Console::Write({0})", type); }
public RelationNode( SyntaxNode ex1, SyntaxNode ex2, string op, string opName, bool canBeBool) : base(ex1, ex2, op) { var t1 = ex1.CheckType(); var t2 = ex2.CheckType(); if (canBeBool) { if (t1 != t2 && !(t1 == CType.Double && t2 == CType.Int) && !(t1 == CType.Int && t2 == CType.Double)) { new Error($"Attempted {opName} check on a {t1} and {t2}"); } } else { if (t1 == CType.Bool || t2 == CType.Bool) { new Error($"Attempted {opName} check on a non number type"); } } }
public CalculationNode(SyntaxNode ex1, SyntaxNode ex2, string op, string opName) : base(ex1, ex2, op) { if (ex1.CheckType() == CType.Bool || ex2.CheckType() == CType.Bool) { new Error($"Attempted {opName} on a non number type"); } }
public BitNegNode(SyntaxNode ex) { if (ex.CheckType() != CType.Int) { new Error("Attempted bit negation on a non int type"); } exp = ex; }
public NegNode(SyntaxNode ex) { if (ex.CheckType() == CType.Bool) { new Error("Attempted negation on a non number type"); } exp = ex; }
public override void GenCode() { exp.GenCode(); if (exp.CheckType() != CType.Double) { EmitCode("conv.r8"); } }
public BoolNegNode(SyntaxNode ex) { if (ex.CheckType() != CType.Bool) { new Error("Attempted logical negation on a non bool type"); } exp = ex; }
public IfNode(SyntaxNode con, SyntaxNode stmnt) { if (con.CheckType() != CType.Bool) { new Error("If condition must return bool"); } condition = con; statement = stmnt; label = Compiler.NextLabel(); }
public LogicalNode(SyntaxNode ex1, SyntaxNode ex2, string op, string opName) : base(ex1, ex2, op) { if (ex1.CheckType() != CType.Bool || ex2.CheckType() != CType.Bool) { new Error($"Attempted {opName} on a non bool type"); } label = Compiler.NextLabel(); }
public IfElseNode( SyntaxNode con, SyntaxNode ifStmnt, SyntaxNode elseStmnt) { if (con.CheckType() != CType.Bool) { new Error("If condition must return bool"); } condition = con; ifStatement = ifStmnt; elseStatement = elseStmnt; ifLabel = Compiler.NextLabel(); elseLabel = Compiler.NextLabel(); }
public AssignNode(string i, SyntaxNode e) { if (!Compiler.variables.ContainsKey(i)) { throw new ErrorException($"Attempted to assign to undeclared variable {i}"); } var idType = Compiler.variables[i]; var expType = e.CheckType(); if (idType != expType && !(idType == CType.Double && expType == CType.Int)) { new Error($"Cannot assign {expType} to {idType}"); } id = i; exp = e; }
public SemicolonNode(SyntaxNode exp) { exp.CheckType(); expression = exp; }
public override CType CheckType() { return(exp.CheckType()); }