Ejemplo n.º 1
0
        public void Print( mysToken output )
        {
            if ( output != null ) {
                string outputstring = string.Join( ", ", output );

                if ( outputstring != "" ) {
                    Console.WriteLine( outputstring );
                }
            }

            Console.WriteLine( "Ok.\n" );
        }
Ejemplo n.º 2
0
        public Type DeepType(
			Stack<mysSymbolSpace> spaceStack
		)
        {
            mysToken temp = new mysToken( new mysSymbol( ToString() ) );

            while ( temp.Type == typeof(mysSymbol) ) {
                // EvaluateSymbol clones the stack by itself
                temp = Value( spaceStack );
            }

            return temp.Type;
        }
Ejemplo n.º 3
0
        // arg 1 function
        // arg 2 instance (with . operator)
        // arg 3+ arguments
        public List<mysToken> Call(
			mysToken target,
			List<mysToken> arguments,
			mysState state,
			Stack<mysSymbolSpace> spaceStack
		)
        {
            object targetObject = null;

            if ( target.Type != typeof(Type) ) {
                targetObject = target.Value;
            }

            List<object> realArguments = new List<object>();

            foreach ( mysToken t in arguments ) {
                mysToken current = t;

                while ( current.Type == typeof(mysSymbol) ) {
                    current =
                        (current.Value as mysSymbol)
                        .Value( spaceStack );
                }

                realArguments.Add( current.Value );
            }

            object result = method.Invoke(
                targetObject,
                realArguments.ToArray()
            );

            if ( result == null ) {
                return null;
            }

            return new List<mysToken>() {
                Builtins.Clr.ClrTools.ConvertClrObject( result )
            };
        }
Ejemplo n.º 4
0
        public static double Promote( mysToken n )
        {
            if ( n.Type == typeof(int) ) return (int)n.Value;
            if ( n.Type == typeof(long) ) return (long)n.Value;
            if ( n.Type == typeof(float) ) return (float)n.Value;
            if ( n.Type == typeof(double) ) return (double)n.Value;

            throw new ArgumentException();
        }
Ejemplo n.º 5
0
 public void Define( mysSymbol symbol, mysToken value )
 {
     Values[ symbol ] = value;
 }
Ejemplo n.º 6
0
        // given a type from our sig, and the token supplied as a potential
        // argument, see if they match
        bool typeCheck(
			Type type,
			mysToken token,
			Stack<mysSymbolSpace> spaceStack
		)
        {
            // we might need to do weird shit with symbols in here?
            // like, you should only really be able to send a quoted symbol
            // in (mainly for ease of reading the code, easy to see reasoning
            // etc., less likely for bugs to occur because of an accidental sig
            // match).

            bool plainAssignable = mysToken.AssignableFrom(
                type,
                token.Type
            );

            bool complexAssignable = false;

            if ( token.Type == typeof(mysSymbol) && !token.Quoted ) {
                mysSymbol s = (token.Value as mysSymbol);
                Type t = s.DeepType( spaceStack );

                if ( t != null ) {
                    complexAssignable = mysToken.AssignableFrom( type, t );
                }
            }

            return plainAssignable || complexAssignable;
        }
Ejemplo n.º 7
0
        mysToken resolveClrMethod( Type targetType, string methodName )
        {
            List<MethodInfo> variants = targetType
                .GetMethods()
                .Where( m => m.Name == methodName )
                .ToList()
            ;

            int signatureLength = variants
                .Max( v => v.GetParameters().Length );

            clrFunction f = null;
            for ( int j = signatureLength; j >= 0; j-- ) {
                List<mysToken> args = tokens
                    .Skip( current + 2 )
                    .Take( j )
                    .ToList()
                ;

                f = clrFunctionGroup.Judge( variants, args, spaceStack );

                if ( f != null ) {
                    mysToken t = new mysToken( f );

                    // replace clrfg token with clrf token
                    tokens.RemoveAt( current );
                    tokens.Insert( current, t );

                    return t;
                }
            }

            // maybe actually evaluate the function here?? idk

            return null;
        }
Ejemplo n.º 8
0
        mysToken resolveClrConstructor( Type targetType )
        {
            List<ConstructorInfo> variants = targetType
                .GetConstructors()
                .ToList()
            ;

            int signatureLength = variants
                .Max( v => v.GetParameters().Length );

            ConstructorInfo ci;
            List<mysToken> args;

            for ( int j = signatureLength; j >= 0; j-- ) {
                args = tokens
                    .Skip( current + 2 )
                    .Take( j )
                    .ToList()
                ;

                ci = clrFunctionGroup.Judge( variants, args, spaceStack );

                if ( ci != null ) {
                    mysToken t = new mysToken(
                        ci.Invoke(
                            args.Select( a => a.Value ).ToArray()
                        )
                    );

                    // rem new-token, type-token, and args
                    tokens.RemoveRange( current, args.Count + 2 );
                    tokens.Insert( current, t );

                    return t;
                }
            }

            return null;
        }