public void AddCtor(string typeName, DeclarationMethod n)
        {
            var info = TypeBuilderMap[typeName];
            var function = n.Type as TypeFunction;

            //simulation is the entry point, must be static
            var attributes = n.Name.Equals("Simulation", StringComparison.OrdinalIgnoreCase)
                                ? MethodAttributes.Public | MethodAttributes.Static
                                : MethodAttributes.Public;

            var builderObj = info.Builder.DefineConstructor(attributes, CallingConventions.Standard, ArgumentTypes(function));
            var formals = n.Descriptor == null ? new List<FormalDescriptor>() : n.Descriptor.Formals;
            info.ConstructorBuilder = new ConstructorBuilderInfo(builderObj, BuildFormalMap(formals));
        }
        private ConstructorBuilderInfo CreateInternalClassCtor(DeclarationClass n, string name)
        {
            _currentType = name;
            _currentTypeBuilder = _typeManager.GetBuilderInfo(n.Name);

            var method = new DeclarationMethod(name, n.Statements)
                             {
                                 Type = new TypeFunction(true),
                                 Descriptor = new MethodDescriptor(n.Type, name, n.Descriptor)
                             };

            _typeManager.AddCtor(name, method);
            return _currentTypeBuilder.ConstructorBuilder;
        }
        //this is a special case since it will be the entry point..
        private MethodBuilderInfo CreateEntryPointMethod(DeclarationClass n, string name)
        {
            _currentType = name;
            _currentTypeBuilder = _typeManager.GetBuilderInfo(n.Name);

            var method = new DeclarationMethod(name, n.Statements)
                             {
                                 Type = new TypeFunction(true),
                                 Descriptor = new MethodDescriptor(n.Type, name, n.Descriptor)
                             };

            _typeManager.AddMethod(name, method);

            return _typeManager.GetMethodBuilderInfo(_currentType, n.Name);
        }
        public void AddMethod(string typeName, DeclarationMethod n)
        {
            var info = TypeBuilderMap[typeName];
            //simulation is the entry point, must be static
            var attributes = n.Name.Equals("Simulation", StringComparison.OrdinalIgnoreCase)
                                ? MethodAttributes.Public | MethodAttributes.Static
                                : MethodAttributes.Public;

            if(InternalMethodManager.IsSystemMethod(n.Name))
            {
                var method = InternalMethodManager.Lookup(n.Name);
                var funcInfo = method.FuncInfo;
                var formals = funcInfo.Formals.Values.Select(LookupCilType);
                var m = info.Builder.DefineMethod(n.Name,
                                                  attributes,
                                                  LookupCilType(funcInfo.ReturnType),
                                                  formals.ToArray());

                //store this MethodBuilder, keyed off its name
                info.MethodMap.Add(n.Name, new MethodBuilderInfo(m, BuildFormalMap(n.Descriptor.Formals)));
                return;
            }

            //we need to know the CIL type for the return type and arguments
            var returnType = LookupCilType(n.ReturnType);
            var function = (TypeFunction) n.Type;

            var methodBuilder = info.Builder.DefineMethod(n.Name,
                                                          attributes,
                                                          returnType,
                                                          function.Formals.Values.Select(LookupCilType).ToArray());

            //store this MethodBuilder, keyed off its name
            info.MethodMap.Add(n.Name, new MethodBuilderInfo(methodBuilder, BuildFormalMap(n.Descriptor.Formals)));
        }