Example #1
0
 public override void Prepare(Generator generator, Set <TypeReference> dependsUpon)
 {
     if (anotherConstructor != null)
     {
         List <TypeReference> signature = new List <TypeReference>();
         foreach (Expression a in anotherConstructor)
         {
             signature.Add(null);
         }
         //                signature.Add(a.TypeReference); TODO
         anotherConstructorInstance = ParentDefinition.FindConstructor(anotherConstructorLocation, new FunctionTypeReference(this, ParentDefinition.TypeReference, signature), generator.Resolver.CurrentDefinition);
     }
     foreach (BaseConstructor c in baseConstructors)
     {
         if (c.type == null)
         {
             List <DefinitionTypeReference> se = ParentDefinition.SparseExtends;
             if ((baseConstructors.Count != 1) || (se.Count != 1))
             {
                 throw new CompilerException(this, string.Format(Resource.Culture, Resource.ImplicitConstructor));
             }
             c.typeReference = se[0];
         }
     }
     Parameters.DependsUpon(dependsUpon);
     runtimeStruct = generator.AllocateDataRegion();
 }
Example #2
0
        public Placeholder MakeSetPropertyStruct(Generator generator, Definition definition, Placeholder definitionRuntimeStruct)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }
            Require.Assigned(definitionRuntimeStruct);
            Region propertyStruct = generator.AllocateDataRegion();

            if (definition.GarbageCollectable)
            {
                propertyStruct.WriteNumber(1);
            }
            else
            {
                propertyStruct.WriteNumber(0);
            }
            propertyStruct.WriteNumber(0); // no function cast adaptor for now
            propertyStruct.WriteNumber(0);
            propertyStruct.WriteNumber(0);
            if (!setStatementPointer.IsNull)
            {
                propertyStruct.WritePlaceholder(setStatementPointer);
            }
            else
            {
                propertyStruct.WriteNumber(0);
            }
            propertyStruct.WritePlaceholder(definitionRuntimeStruct);
            generator.Symbols.WriteData(propertyStruct.BaseLocation, propertyStruct.Length, "ps:" + definition.Name.Data + ":" + ParentDefinition.Name.Data + "." + name.Data + ".+set");
            return(propertyStruct.BaseLocation);
        }
Example #3
0
        public Placeholder MakeMethodStruct(Generator generator, Definition definition, Placeholder definitionRuntimeStruct)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }
            Require.Assigned(definitionRuntimeStruct);
            Region methodStruct = generator.AllocateDataRegion();

            if (definition.GarbageCollectable)
            {
                methodStruct.WriteNumber(1);
            }
            else
            {
                methodStruct.WriteNumber(0);
            }
            methodStruct.WritePlaceholder(castFunction.FunctionPointer);
            methodStruct.WriteNumber(0);
            methodStruct.WriteNumber(0);
            methodStruct.WritePlaceholder(functionPointer);
            methodStruct.WritePlaceholder(definitionRuntimeStruct);
            StringBuilder sb = new StringBuilder(256);

            sb.Append("ms:");
            sb.Append(definition.Name.Data);
            sb.Append(":");
            sb.Append(ParentDefinition.Name.Data);
            sb.Append(".");
            sb.Append(name.Data);
            generator.Symbols.WriteData(methodStruct.BaseLocation, methodStruct.Length, sb.ToString());
            return(methodStruct.BaseLocation);
        }
Example #4
0
        private ConstructorNode InnerPrepareConstructors(Generator generator, Dictionary <DefinitionTypeReference, KeyValuePair <Definition, List <Expression> > > irc, Definition parentDefinition)
        {
            ConstructorNode result = new ConstructorNode();

            result.parentDefinition = parentDefinition;
            result.location         = this;
            result.definition       = ParentDefinition;
            result.runtimeStruct    = generator.AllocateDataRegion();
            result.parameters       = parametersMetadata;
            result.statement        = statementMetadata;

            if (anotherConstructorInstance != null)
            {
                result.redirect = new ConstructorNodeInvocation(anotherConstructor, anotherConstructorInstance.InnerPrepareConstructors(generator, irc, parentDefinition));
            }
            else
            {
                result.inherit = new List <ConstructorNodeInvocation>();
                foreach (DefinitionTypeReference e in ParentDefinition.Extends)
                {
                    if (!irc.ContainsKey(e))
                    {
                        continue;
                    }
                    KeyValuePair <Definition, List <Expression> > kv = irc[e];
                    if (kv.Key == ParentDefinition)
                    {
                        List <TypeReference> signature = new List <TypeReference>();
                        foreach (Expression a in kv.Value)
                        {
                            signature.Add(null);
                        }
                        //                            signature.Add(a.TypeReference);
                        Constructor c = e.Definition.FindConstructor(this, new FunctionTypeReference(this, e, signature), generator.Resolver.CurrentDefinition);
                        ConstructorNodeInvocation cni = new ConstructorNodeInvocation(kv.Value, c.InnerPrepareConstructors(generator, irc, parentDefinition));
                        result.inherit.Add(cni);
                    }
                }
            }
            return(result);
        }
Example #5
0
        public override void Generate(Generator generator)
        {
            base.Generate(generator);
            GenerateLambda(generator);

            Region runtimeStruct = generator.AllocateDataRegion();

            if (closureSlots.Count > 0)
            {
                generator.Assembler.CallAllocator(generator.Allocator, closureSlots.Count, runtimeStruct.BaseLocation);
                runtimeStruct.WriteNumber(1); //gc
            }
            else
            {
                generator.Assembler.SetImmediateValue(runtimeStruct.BaseLocation, 0);
                runtimeStruct.WriteNumber(0);
            }
            runtimeStruct.WriteNumber(0); //todo:cast function
            runtimeStruct.WriteNumber(0);
            runtimeStruct.WriteNumber(0);
            runtimeStruct.WritePlaceholder(functionPointer);
            runtimeStruct.WritePlaceholder(runtimeStruct.BaseLocation);
            int i = 0;

            foreach (KeyValuePair <int, int> kv in closureSlots)
            {
                //note: rs entry is nt the one matching with the closureSlots here, which are basicy in random order.
                runtimeStruct.WriteNumberTimesBitness(2 * (i++));
                //todo: crappy assembly
                generator.Assembler.PushValue();
                generator.Assembler.PushValue();
                generator.Assembler.RetrieveVariable(kv.Key);
                generator.Assembler.StoreInFieldOfSlot(generator.Toucher, kv.Value);
                generator.Assembler.PopValue();
            }
        }
Example #6
0
 public void Prepare(Generator generator)
 {
     runtimeStruct = generator.AllocateDataRegion();
 }