示例#1
0
 protected override object?Visit(Declaration.Const cons)
 {
     AllocateName(cons.Value, Push(cons.Name));
     base.Visit(cons);
     currentName.Pop();
     return(null);
 }
示例#2
0
        public Value EvaluateConst(Declaration.Const constDecl)
        {
            var symbol = (Symbol.Const)SymbolTable.DefinedSymbol(constDecl);

            // Check if there's a pre-stored value, if not, evaluate it
            if (symbol.Value == null)
            {
                symbol.Value = Evaluate(constDecl.Value);
            }
            return(symbol.Value);
        }
示例#3
0
        // Actual code-generation //////////////////////////////////////////////

        protected override Value?Visit(Declaration.Const cons)
        {
            var constType = System.TypeOf(cons.Value);

            if (constType is Semantic.Types.Type.Proc procType && procType.GetDependency() != null)
            {
                // We don't compile this, contains dependent types
                return(null);
            }
            EvaluateConst(cons);
            return(null);
        }
示例#4
0
 protected override object?Visit(Declaration.Const cons) => WithCurrentProcReturnType(null, null, () =>
 {
     // Type-check type and value
     base.Visit(cons);
     // First we assign the type to the symbol
     var symbol  = (Symbol.Const)System.SymbolTable.DefinedSymbol(cons);
     symbol.Type = System.TypeOf(cons.Value);
     if (cons.Type != null)
     {
         // There's an explicit type, make sure they match
         var consType = System.EvaluateType(cons.Type);
         if (!symbol.Type.Equals(consType))
         {
             System.Report(new TypeMismatchError(consType, symbol.Type)
             {
                 Defined = cons.Type.ParseTreeNode,
                 Wrong   = cons.Value.ParseTreeNode,
                 Context = "constant definition",
             });
         }
     }
 });
示例#5
0
 private Value EvaluateConst(Declaration.Const constDecl) => System.EvaluateConst(constDecl);
示例#6
0
 protected override object?Visit(Declaration.Const cons)
 {
     base.Visit(cons);
     symbolTable.DefineSymbol(cons, new Symbol.Const(cons));
     return(null);
 }
示例#7
0
 /// <summary>
 /// Initializes a new <see cref="Const"/> by a constant definition.
 /// </summary>
 /// <param name="definition">The constant definition node.</param>
 public Const(Declaration.Const definition)
     : this(definition, definition.Name, null, null)
 {
 }