Example #1
0
        public override Value VisitUnaryOpExpression([NotNull] UnaryOpExpressionContext context)
        {
            var opKind = context.GetOperatorInfo(ParserStack.Parser);

            if (opKind == OperatorKind.None)
            {
                throw new ArgumentException($"invalid unary operator {context.Op}", nameof(context));
            }

            string calleeName = $"$unary{context.Op}";
            var    function   = GetFunction(calleeName);

            if (function == null)
            {
                throw new ArgumentException($"Unknown function reference {calleeName}", nameof(context));
            }

            var arg = context.Rhs.Accept(this);

            return(InstructionBuilder.Call(function, arg).RegisterName("calltmp"));
        }
Example #2
0
        public override IAstNode VisitUnaryOpExpression([NotNull] UnaryOpExpressionContext context)
        {
            // verify the operator was previously defined
            var opKind = RuntimeState.GetUnaryOperatorInfo(context.Op).Kind;

            if (opKind == OperatorKind.None)
            {
                throw new CodeGeneratorException($"invalid unary operator {context.Op}");
            }

            string calleeName = CreateUnaryFunctionName(context.OpToken);
            var    function   = FindCallTarget(calleeName);

            if (function == null)
            {
                throw new CodeGeneratorException($"Unknown function reference {calleeName}");
            }

            var arg = ( IExpression )context.Rhs.Accept(this);

            return(new FunctionCallExpression(context.GetSourceSpan( ), function, arg));
        }
Example #3
0
 public override void EnterUnaryOpExpression(UnaryOpExpressionContext context)
 {
     ActiveNode.Properties.Add("Op", context.Op);
 }