Exemple #1
0
 public string VisitLiteralExpression(Expression.Literal expression)
 {
     if (expression.value == null)
     {
         return("nil");
     }
     return(expression.value.ToString());
 }
Exemple #2
0
        public ByteCodeChunk VisitLiteral(Expression.Literal expression)
        {
            var chunk = new ByteCodeChunk(9);

            switch (expression.Value)
            {
            case long i:
                chunk.AddInstruction(Instruction.Push64, i);
                break;

            default:
                throw new Exception();
            }

            return(chunk);
        }
Exemple #3
0
    public object visitLiteralExpression(Expression.Literal expr)
    {
        if (expr.Value is string)
        {
            // TODO handle the memory slot correctly
            wasm.addData(memoryPointer, expr.Value.ToString());
            addInstruction(0x41);
            addInstruction(Util.LEB128encode(memoryPointer));
            // addInstruction(0x41);
            // addInstruction(Util.LEB128encode(memoryPointer));
            // addInstruction(0x2d, 0x00, 0x00);
            memoryPointer += expr.Value.ToString().Length + 1;
            return(null);
        }

        addInstruction(0x41);
        addInstruction(Util.LEB128encode((int)expr.Value));
        return(null);
    }
Exemple #4
0
 protected override Value?Visit(Expression.Literal lit) => lit.Type switch
 {
 public object VisitLiteralExpression(Expression.Literal expression)
 {
     return(null);
 }
Exemple #6
0
 public object visitLiteralExpression(Expression.Literal expr)
 {
     return(expr.Type);
 }
Exemple #7
0
 public object VisitLiteralExpr(Expression.Literal expr)
 {
     return(new Expression.Literal());
 }
 public object VisitLiteralExpression(Expression.Literal expression)
 {
     return(expression.value);
 }
Exemple #9
0
 protected override Node?Visit(Expression.Literal lit) =>
 new Expression.Literal(lit.ParseTreeNode, lit.Type, lit.Value);
Exemple #10
0
 public object VisitLiteralExpr(Expression.Literal expr)
 {
     return(expr.LiteralValue());
 }
Exemple #11
0
        private Statement ForStatement()
        {
            try
            {
                loopDepth++;

                Consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'.");

                Statement initialiser = null;

                if (Match(TokenType.SEMICOLON))
                {
                }
                else if (Match(TokenType.VAR))
                {
                    initialiser = VarDeclaration();
                }
                else
                {
                    initialiser = ExpressionStatement();
                }

                Expression condition = Expression();

                if (!Check(TokenType.SEMICOLON))
                {
                    condition = Expression();
                }

                Consume(TokenType.SEMICOLON, "Expect ';' after loop condition.");

                Expression increment = null;

                if (!Check(TokenType.RIGHT_PAREN))
                {
                    increment = Expression();
                }

                Consume(TokenType.RIGHT_PAREN, "Expect ')' after for clauses.");

                Statement body = Statement();

                if (increment != null)
                {
                    body = new Statement.Block(new List <Statement> {
                        body, new Statement.Expression(increment)
                    });
                }

                if (condition == null)
                {
                    condition = new Expression.Literal(true);
                }
                body = new Statement.While(condition, body);

                if (initialiser != null)
                {
                    body = new Statement.Block(new List <Statement> {
                        initialiser, body
                    });
                }

                return(body);
            }
            finally
            {
                loopDepth--;
            }
        }