Example #1
0
        static void defineFunction(
			mysSymbol symbol,
			mysFunction f,
			mysSymbolSpace ss
		)
        {
            mysFunctionGroup fg = null;

            // if symbol defined and of wrong type, undef it
            if (
                ss.Defined( symbol ) &&
                ss.GetValue( symbol ).Type != typeof(mysFunctionGroup)
            ) {
                // we could just overwrite it with define,
                // but I'd rather be entirely sure that we delete
                // the old value beforehand.
                ss.Undefine( symbol );
            }

            // if we're defined at this point, we know it's a function group
            if  ( ss.Defined( symbol ) ) {
                fg = ss.GetValue( symbol ).Value as mysFunctionGroup;
            } else {
                // create
                fg = new mysFunctionGroup();

                ss.Define( symbol, new mysToken( fg ) );
            }

            mysFunction collision = fg.Variants.FirstOrDefault( v =>
                v.Signature.Count() == f.Signature.Count() &&
                v.Signature
                    .Zip( f.Signature, (a, b) => a == b )
                    .Count() == v.Signature.Count()
            );

            if ( collision != null ) {
                // overwrite a conflicting sig! should probably
                // notify the user about this when it happens.
                fg.Variants.Remove( collision );
            }

            fg.Variants.Add( f );
        }
Example #2
0
        public static mysToken Evaluate(
			List<mysToken> sig,
			List<mysToken> body,
			Stack<mysSymbolSpace> sss
		)
        {
            mysSymbolSpace ss = sss.Peek();

            Argumentcheck( sig, body );

            mysFunction f = new mysFunction();

            // TODO: these two should probably be joined at some point
            for ( int i = 0; i < sig.Count; i++ ) {
                if ( sig[ i ].Type == typeof(mysSymbol) ) {
                    f.Symbols.Add(
                        sig[ i ].Value as mysSymbol
                    );
                } else {
                    Type t = (Type)sig[ i ].Value;
                    f.Signature.Add( t );
                }
            }

            f.Function = body;

            return new mysToken( f );
        }