public override void Generate(Generator generator, TypeReference returnType) { base.Generate(generator, returnType); expression.Prepare(generator, null); expression.Generate(generator); generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); exceptionType.GenerateConversion(this, generator, expression.TypeReference); generator.Assembler.PushValue(); Method m = exceptionType.Definition.FindMethod(new Identifier(this, "Throw"), false, null, null, true); int offset = exceptionType.Definition.GetMethodOffset(this, m, exceptionType.Definition); // bypasses visibility generator.Assembler.FetchMethod(offset); generator.Assembler.PushValue(); Placeholder retSite = generator.Assembler.CallFromStack(0); if (generator.Resolver.CurrentDefinition != null) { generator.AddCallTraceEntry(retSite, this, generator.Resolver.CurrentDefinition.Name.DataModifierLess, generator.Resolver.CurrentFieldName); } else { generator.AddCallTraceEntry(retSite, this, "meh", "raiseOverflow"); } generator.Assembler.PopValue(); generator.Assembler.ExceptionHandlerInvoke(); }
public void Call(Generator generator) { ILocation location = new NowhereLocation(); SlotExpression e = new SlotExpression(location, new Identifier(location, "this"), true); e.Resolve(generator); e.Prepare(generator, null); e.Generate(generator); generator.Assembler.SetTypePart(node.RuntimeStruct); generator.Assembler.PushValue(); int i = 0; foreach (Expression a in arguments) { a.Prepare(generator, node.parameters.ParameterList[i].TypeReference); a.Generate(generator); node.parameters.ParameterList[i].TypeReference.GenerateConversion(a, generator, a.TypeReference); generator.Assembler.PushValue(); i++; } Placeholder retSite = generator.Assembler.CallFromStack(arguments.Count); generator.AddCallTraceEntry(retSite, location, generator.Resolver.CurrentDefinition.Name.DataModifierLess, generator.Resolver.CurrentFieldName); node.MarkFieldsAssigned(generator); }
public override void Generate(Generator generator) { base.Generate(generator); parent.Generate(generator); TypeReference parentType = parent.TypeReference; generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); generator.Assembler.PushValue(); FunctionTypeReference callType = (FunctionTypeReference)parentType; List <TypeReference> callParameters = callType.FunctionParameters; int idx = 0; foreach (Expression parameter in parameters) { parameter.Generate(generator); callParameters[idx].GenerateConversion(parameter, generator, parameter.TypeReference); idx++; generator.Assembler.PushValue(); } generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); Placeholder retSite = generator.Assembler.CallFromStack(parameters.Count); if (generator.Resolver.CurrentDefinition != null) { generator.AddCallTraceEntry(retSite, this, generator.Resolver.CurrentDefinition.Name.DataModifierLess, generator.Resolver.CurrentFieldName); } }
public override void Generate(Generator generator) { rootConstructorNode.GenerateFunction(generator); generator.Resolver.EnterContext(); generator.Resolver.CurrentFieldName = ConstructorName(); generator.AllocateAssembler(); parametersMetadata.Generate(generator); generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); generator.Assembler.StartFunction(); generator.Assembler.CallAllocator(generator.Allocator, ParentDefinition.InstanceSize, ParentDefinition.RuntimeStruct); int thisslot = generator.Resolver.ResolveSlotOffset(new Identifier(this, "this")); generator.Resolver.IncompleteSlot(thisslot, false); generator.Assembler.StoreVariable(thisslot); generator.Assembler.SetTypePart(rootConstructorNode.RuntimeStruct); generator.Assembler.PushValue(); foreach (ParameterMetadata p in parametersMetadata.ParameterList) { generator.Assembler.RetrieveVariable(p.Slot); generator.Assembler.PushValue(); } Placeholder retSite = generator.Assembler.CallFromStack(parametersMetadata.ParameterList.Count); generator.AddCallTraceEntry(retSite, this, generator.Resolver.CurrentDefinition.Name.DataModifierLess, generator.Resolver.CurrentFieldName); generator.Resolver.LeaveContext(); generator.Assembler.RetrieveVariable(thisslot); generator.Assembler.StopFunction(); generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this, SourceMark.EndSequence); generator.Symbols.WriteCode(generator.Assembler.Region.BaseLocation, generator.Assembler.Region.Length, "constructor:" + ParentDefinition.TypeReference.TypeName.Data + ".constructor"); functionPointer = generator.Assembler.Region.BaseLocation; castFunction = new CallableCastFunction(this); castFunction.Generate(generator); if (ParentDefinition.GarbageCollectable) { runtimeStruct.WriteNumber(1); } else { runtimeStruct.WriteNumber(0); } runtimeStruct.WritePlaceholder(castFunction.FunctionPointer); runtimeStruct.WriteNumber(0); runtimeStruct.WriteNumber(0); runtimeStruct.WritePlaceholder(functionPointer); runtimeStruct.WritePlaceholder(ParentDefinition.RuntimeStruct); generator.Symbols.WriteData(runtimeStruct.BaseLocation, runtimeStruct.Length, "ms:" + ParentDefinition.TypeReference.TypeName.Data + ".constructor"); }
public override void Generate(Generator generator) { base.Generate(generator); if (target == null) { int slot = generator.Resolver.ResolveSlotOffset(name); value.Generate(generator); type.GenerateConversion(this, generator, value.TypeReference); generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); generator.Resolver.WriteSlot(this, slot); generator.Assembler.StoreVariable(slot); } else { target.Generate(generator); TypeReference thisType = target.TypeReference; bool staticRef = thisType is StaticTypeReference; Definition thisDefinition; if (staticRef) { thisDefinition = ((StaticTypeReference)thisType).Parent.Definition; } else { thisDefinition = ((DefinitionTypeReference)thisType).Definition; } if (thisDefinition.HasField(name, staticRef)) { Field field = thisDefinition.GetField(name, staticRef); if (!field.GetModifiers.Static) { generator.Assembler.PushValue(); int fieldOffset = thisDefinition.GetFieldOffset(this, name, generator.Resolver.CurrentDefinition, true); if (target is IIncompleteSlotAssignment) { if (((IIncompleteSlotAssignment)target).IsIncompleteSlot()) { generator.Resolver.AssignField(field); } } value.Generate(generator); type.GenerateConversion(value, generator, value.TypeReference); generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); TypeReference slot = field.TypeReference; if (slot.IsNullable) { slot = ((NullableTypeReference)slot).Parent; } DefinitionTypeReference dtr = slot as DefinitionTypeReference; if ((dtr != null) && (!dtr.Definition.GarbageCollectable)) { generator.Assembler.StoreInFieldOfSlotNoTouch(fieldOffset); } else { generator.Assembler.StoreInFieldOfSlot(generator.Toucher, fieldOffset); } } else { generator.Assembler.PushValue(); if (target is IIncompleteSlotAssignment) { if (((IIncompleteSlotAssignment)target).IsIncompleteSlot()) { generator.Resolver.AssignField(field); } } value.Generate(generator); type.GenerateConversion(value, generator, value.TypeReference); generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); generator.Assembler.Store(field.StaticSlot); } } else { int propertySlot = thisDefinition.GetSetPropertyOffset(this, name, generator.Resolver.CurrentDefinition); generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); generator.Assembler.FetchMethod(propertySlot); generator.Assembler.PushValue(); value.Generate(generator); type.GenerateConversion(value, generator, value.TypeReference); generator.Assembler.PushValue(); Placeholder retSite = generator.Assembler.CallFromStack(1); generator.AddCallTraceEntry(retSite, this, generator.Resolver.CurrentDefinition.Name.DataModifierLess, generator.Resolver.CurrentFieldName); } } }
public override void Generate(Generator generator) { base.Generate(generator); if ((typeName != null) && UseTypeName()) { generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); generator.Assembler.SetImmediateValue(typeName.Parent.RuntimeStruct, 0); if (!allowTypeGenerate) { throw new CompilerException(this, Resource.CannotUseATypeAsAValue); } } else { TypeReference type; if (parent.SuppliesType()) { type = parent.TypeReference; bool static_ = type.IsStatic; if (static_) { parent.ConsumeType(); } } if (!skipGenerateParent) { parent.Generate(generator); } generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this); type = parent.TypeReference; bool staticRef = type.IsStatic; if (staticRef) { type = ((StaticTypeReference)type).Parent; } if (type.IsDefinition) { Definition definition = ((DefinitionTypeReference)type).Definition; if (definition.HasField(name, staticRef)) { Field field = definition.GetField(name, staticRef); generator.Resolver.RetrieveField(this, field); if (!field.GetModifiers.Static) { int offset = definition.GetFieldOffset(this, name, generator.Resolver.CurrentDefinition, false); generator.Assembler.FetchField(offset); } else { generator.Assembler.Load(field.StaticSlot); } } else if (definition.HasMethod(name, staticRef)) { int offset = definition.GetMethodOffset(this, method, generator.Resolver.CurrentDefinition); generator.Assembler.FetchMethod(offset); } else if (definition.HasProperty(name, staticRef)) { int offset = definition.GetGetPropertyOffset(this, name, generator.Resolver.CurrentDefinition); generator.Assembler.FetchMethod(offset); generator.Assembler.PushValue(); Placeholder retSite = generator.Assembler.CallFromStack(0); generator.AddCallTraceEntry(retSite, this, generator.Resolver.CurrentDefinition.Name.DataModifierLess, generator.Resolver.CurrentFieldName); } } } }