Ejemplo n.º 1
0
 public BooMethodBuilder(BooCodeBuilder codeBuilder,
                         string name,
                         IType returnType) :
     this(codeBuilder, name, returnType,
          TypeMemberModifiers.Public)
 {
 }
Ejemplo n.º 2
0
 public GeneratorExpressionTrees(string parameter, ReferenceExpression parameterRef, NameResolutionService nameResolutionService, BooCodeBuilder codeBuilder)
 {
     _parameter = parameter;
     _parameterRef = parameterRef;
     _nameResolutionService = nameResolutionService;
     _codeBuilder = codeBuilder;
 }
Ejemplo n.º 3
0
        public TypeSystemServices(CompilerContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException("context");
            }

            _context = context;

            CodeBuilder = new BooCodeBuilder(this);

            Cache(typeof(Builtins.duck), DuckType = new DuckTypeImpl(this));
            Cache(IQuackFuType             = new ExternalType(this, typeof(IQuackFu)));
            Cache(VoidType                 = new VoidTypeImpl(this));
            Cache(ObjectType               = new ExternalType(this, Types.Object));
            Cache(RegexType                = new ExternalType(this, Types.Regex));
            Cache(ValueTypeType            = new ExternalType(this, typeof(ValueType)));
            Cache(EnumType                 = new ExternalType(this, typeof(Enum)));
            Cache(ArrayType                = new ExternalType(this, Types.Array));
            Cache(TypeType                 = new ExternalType(this, Types.Type));
            Cache(StringType               = new ExternalType(this, Types.String));
            Cache(BoolType                 = new ExternalType(this, Types.Bool));
            Cache(SByteType                = new ExternalType(this, Types.SByte));
            Cache(CharType                 = new ExternalType(this, Types.Char));
            Cache(ShortType                = new ExternalType(this, Types.Short));
            Cache(IntType                  = new ExternalType(this, Types.Int));
            Cache(LongType                 = new ExternalType(this, Types.Long));
            Cache(ByteType                 = new ExternalType(this, Types.Byte));
            Cache(UShortType               = new ExternalType(this, Types.UShort));
            Cache(UIntType                 = new ExternalType(this, Types.UInt));
            Cache(ULongType                = new ExternalType(this, Types.ULong));
            Cache(SingleType               = new ExternalType(this, Types.Single));
            Cache(DoubleType               = new ExternalType(this, Types.Double));
            Cache(DecimalType              = new ExternalType(this, Types.Decimal));
            Cache(TimeSpanType             = new ExternalType(this, Types.TimeSpan));
            Cache(DateTimeType             = new ExternalType(this, Types.DateTime));
            Cache(RuntimeServicesType      = new ExternalType(this, Types.RuntimeServices));
            Cache(BuiltinsType             = new ExternalType(this, Types.Builtins));
            Cache(ListType                 = new ExternalType(this, Types.List));
            Cache(HashType                 = new ExternalType(this, Types.Hash));
            Cache(ICallableType            = new ExternalType(this, Types.ICallable));
            Cache(IEnumerableType          = new ExternalType(this, Types.IEnumerable));
            Cache(IEnumeratorType          = new ExternalType(this, typeof(IEnumerator)));
            Cache(ICollectionType          = new ExternalType(this, Types.ICollection));
            Cache(IListType                = new ExternalType(this, Types.IList));
            Cache(IDictionaryType          = new ExternalType(this, Types.IDictionary));
            Cache(ApplicationExceptionType = new ExternalType(this, Types.ApplicationException));
            Cache(ExceptionType            = new ExternalType(this, Types.Exception));
            Cache(IntPtrType               = new ExternalType(this, Types.IntPtr));
            Cache(MulticastDelegateType    = new ExternalType(this, Types.MulticastDelegate));
            Cache(DelegateType             = new ExternalType(this, Types.Delegate));

            ObjectArrayType = GetArrayType(ObjectType, 1);

            PreparePrimitives();
            PrepareBuiltinFunctions();
        }
Ejemplo n.º 4
0
 public BooMethodBuilder(BooCodeBuilder codeBuilder, Method method)
 {
     if (null == codeBuilder)
     {
         throw new ArgumentNullException("codeBuilder");
     }
     if (null == method)
     {
         throw new ArgumentNullException("method");
     }
     _codeBuilder = codeBuilder;
     _method      = method;
 }
Ejemplo n.º 5
0
        public static Expression CreateCallableFromMacroBody(BooCodeBuilder builder, MacroStatement macro)
        {
            // create closure for macro's body or null
            Expression macroBody = new NullLiteralExpression();
            if (macro.Block.Statements.Count > 0)
            {
                var callableExpr = new BlockExpression {Body = macro.Block};
                callableExpr.Parameters.Add(
                    new ParameterDeclaration("OutputStream",
                                             builder.CreateTypeReference(typeof(TextWriter))));

                macroBody = callableExpr;
            }
            return macroBody;
        }
Ejemplo n.º 6
0
        public BooClassBuilder(BooCodeBuilder codeBuilder, string name)
        {
            if (null == codeBuilder)
            {
                throw new ArgumentNullException("codeBuilder");
            }
            if (null == name)
            {
                throw new ArgumentNullException("name");
            }

            _codeBuilder = codeBuilder;
            _cd          = new ClassDefinition();
            _cd.Name     = name;
            _cd.Entity   = new InternalClass(_codeBuilder.TypeSystemServices, _cd);
        }
Ejemplo n.º 7
0
        public BooClassBuilder(BooCodeBuilder codeBuilder, string name)
        {
            if (null == codeBuilder)
            {
                throw new ArgumentNullException("codeBuilder");
            }
            if (null == name)
            {
                throw new ArgumentNullException("name");
            }

            _codeBuilder = codeBuilder;
            _cd = new ClassDefinition();
            _cd.Name = name;
            _cd.Entity = new InternalClass(_codeBuilder.TypeSystemServices, _cd);
            _cd.IsSynthetic = true;
        }
Ejemplo n.º 8
0
        public BooMethodBuilder(BooCodeBuilder codeBuilder,
                                string name,
                                IType returnType,
                                TypeMemberModifiers modifiers)
        {
            if (null == codeBuilder)
            {
                throw new ArgumentNullException("codeBuilder");
            }
            if (null == name)
            {
                throw new ArgumentNullException("name");
            }

            _codeBuilder = codeBuilder;
            _method      = _codeBuilder.CreateMethod(name,
                                                     returnType,
                                                     modifiers);
        }
Ejemplo n.º 9
0
 public GenericTypeCollector(BooCodeBuilder codeBuilder)
 {
     _matches     = new List <IGenericParameter>();
     _codeBuilder = codeBuilder;
 }
Ejemplo n.º 10
0
        public TypeSystemServices(CompilerContext context)
        {
            if (null == context) throw new ArgumentNullException("context");

            _context = context;
            _anonymousCallablesManager = new AnonymousCallablesManager(this);
            _genericsServices = new GenericsServices(context);

            CodeBuilder = new BooCodeBuilder(this);

            Cache(typeof(Builtins.duck), DuckType = new DuckTypeImpl(this));
            Cache(IQuackFuType = new ExternalType(this, typeof(IQuackFu)));
            Cache(VoidType = new VoidTypeImpl(this));
            Cache(ObjectType = new ExternalType(this, Types.Object));
            Cache(RegexType = new ExternalType(this, Types.Regex));
            Cache(ValueTypeType = new ExternalType(this, typeof(ValueType)));
            Cache(EnumType = new ExternalType(this, typeof(Enum)));
            Cache(ArrayType = new ExternalType(this, Types.Array));
            Cache(TypeType = new ExternalType(this, Types.Type));
            Cache(StringType = new ExternalType(this, Types.String));
            Cache(BoolType = new ExternalType(this, Types.Bool));
            Cache(SByteType = new ExternalType(this, Types.SByte));
            Cache(CharType = new ExternalType(this, Types.Char));
            Cache(ShortType = new ExternalType(this, Types.Short));
            Cache(IntType = new ExternalType(this, Types.Int));
            Cache(LongType = new ExternalType(this, Types.Long));
            Cache(ByteType = new ExternalType(this, Types.Byte));
            Cache(UShortType = new ExternalType(this, Types.UShort));
            Cache(UIntType = new ExternalType(this, Types.UInt));
            Cache(ULongType = new ExternalType(this, Types.ULong));
            Cache(SingleType = new ExternalType(this, Types.Single));
            Cache(DoubleType = new ExternalType(this, Types.Double));
            Cache(DecimalType = new ExternalType(this, Types.Decimal));
            Cache(TimeSpanType = new ExternalType(this, Types.TimeSpan));
            Cache(DateTimeType = new ExternalType(this, Types.DateTime));
            Cache(RuntimeServicesType = new ExternalType(this, Types.RuntimeServices));
            Cache(BuiltinsType = new ExternalType(this, Types.Builtins));
            Cache(ListType = new ExternalType(this, Types.List));
            Cache(HashType = new ExternalType(this, Types.Hash));
            Cache(ICallableType = new ExternalType(this, Types.ICallable));
            Cache(IEnumerableType = new ExternalType(this, Types.IEnumerable));
            Cache(IEnumeratorType = new ExternalType(this, typeof(IEnumerator)));
            Cache(ICollectionType = new ExternalType(this, Types.ICollection));
            Cache(IListType = new ExternalType(this, Types.IList));
            Cache(IDictionaryType = new ExternalType(this, Types.IDictionary));
            Cache(IntPtrType = new ExternalType(this, Types.IntPtr));
            Cache(UIntPtrType = new ExternalType(this, Types.UIntPtr));
            Cache(MulticastDelegateType = new ExternalType(this, Types.MulticastDelegate));
            Cache(DelegateType = new ExternalType(this, Types.Delegate));
            Cache(SystemAttribute = new ExternalType(this, typeof(System.Attribute)));
            Cache(ConditionalAttribute = new ExternalType(this, typeof(System.Diagnostics.ConditionalAttribute)));
            Cache(IEnumerableGenericType = new ExternalType(this, typeof(System.Collections.Generic.IEnumerable<>)));
            Cache(IEnumeratorGenericType = new ExternalType(this, typeof(System.Collections.Generic.IEnumerator<>)));

            ObjectArrayType = GetArrayType(ObjectType, 1);

            PreparePrimitives();
            PrepareBuiltinFunctions();
        }
Ejemplo n.º 11
0
 public AnonymousCallablesManager(TypeSystemServices tss)
 {
     _tss         = tss;
     _codeBuilder = new BooCodeBuilder(tss);
 }
Ejemplo n.º 12
0
		public static void UnpackArray(BooCodeBuilder codeBuilder, Method method, Block block, Expression expression, DeclarationCollection declarations)
		{
			ILocalEntity local = expression.Entity as ILocalEntity;
			if (null == local)
			{
				local = codeBuilder.DeclareTempLocal(method,
				                                     expression.ExpressionType);
				block.Add(
					codeBuilder.CreateAssignment(
						codeBuilder.CreateReference(local),
						expression));
			}
			for (int i=0; i<declarations.Count; ++i)
			{
				Declaration declaration = declarations[i];
				block.Add(
					codeBuilder.CreateAssignment(
						codeBuilder.CreateReference(
							declaration.Entity),
						codeBuilder.CreateSlicing(
							codeBuilder.CreateReference(local),
							i)));
			}
		}
Ejemplo n.º 13
0
		public static void UnpackEnumerable(BooCodeBuilder codeBuilder, Method method, Block block, Expression expression, DeclarationCollection declarations)
		{
			TypeSystemServices tss = codeBuilder.TypeSystemServices;
			
			InternalLocal local = codeBuilder.DeclareTempLocal(method,
			                                                   tss.IEnumeratorType);
			
			IType expressionType = expression.ExpressionType;
			
			if (expressionType.IsSubclassOf(codeBuilder.TypeSystemServices.IEnumeratorType))
			{
				block.Add(
					codeBuilder.CreateAssignment(
						codeBuilder.CreateReference(local),
						expression));
			}
			else
			{
				if (!expressionType.IsSubclassOf(codeBuilder.TypeSystemServices.IEnumerableType))
				{
					expression = codeBuilder.CreateMethodInvocation(
						RuntimeServices_GetEnumerable, expression);
				}
				
				block.Add(
					codeBuilder.CreateAssignment(
						block.LexicalInfo,
						codeBuilder.CreateReference(local),
						codeBuilder.CreateMethodInvocation(
							expression, IEnumerable_GetEnumerator)));
			}
			
			for (int i=0; i<declarations.Count; ++i)
			{
				Declaration declaration = declarations[i];
				
				block.Add(
					codeBuilder.CreateAssignment(
						codeBuilder.CreateReference(declaration.Entity),
						codeBuilder.CreateMethodInvocation(RuntimeServices_MoveNext,
						                                   codeBuilder.CreateReference(local))));
			}
		}
Ejemplo n.º 14
0
		public static void UnpackExpression(BooCodeBuilder codeBuilder, Method method, Block block, Expression expression, DeclarationCollection declarations)
		{
			if (expression.ExpressionType.IsArray)
			{
				UnpackArray(codeBuilder, method, block, expression, declarations);
			}
			else
			{
				UnpackEnumerable(codeBuilder, method, block, expression, declarations);
			}
		}
Ejemplo n.º 15
0
 public AnonymousCallablesManager(TypeSystemServices tss)
 {
     _tss = tss;
     _codeBuilder = new BooCodeBuilder(tss);
 }