Beispiel #1
0
        static void enclosureEnd(Enclosure ended)
        {
            switch (ended.type)
            {
            case NT.IF: break;

            case NT.MEMBER_TUPLE: {
                AST_Tuple      tuple = (AST_Tuple)ended.node;
                DataType_Tuple tupleType;
                ValueKind      tupleKind;
                getTuple_Type_Kind(tuple, out tupleType, out tupleKind);
                tuple.result = new IR {
                    irType = NT.TUPLE, dType = tupleType, dKind = tupleKind
                };

                // TODO: only allow members
            } break;

            case NT.FUNCTION: if (!isDefineFase)
                {
                    swap(ref instructions, ref ((IR_Function)ended.node.result).block);
                }
                break;

            case NT.STRUCT: {
                var structNode = (AST_Struct)ended.node;
                var structType = (DataType_Struct)structNode.result.dType;

                DataType[] members;
                if (structNode.inherits != null)
                {
                    members    = new DataType[structType.members.Length + 1];
                    members[0] = structNode.inherits.result.dType;
                    structType.members.CopyTo(members, 1);
                }
                else
                {
                    members = new DataType[structType.members.Length];
                    structType.members.CopyTo(members, 0);
                }
                structNode.result = instructions.Add(new IR {
                        irType = NT.STRUCT, dType = structType, dKind = ValueKind.STATIC_TYPE
                    });

                if (structNode.inherits != null)
                {
                    if (structNode.inherits.result.dKind != ValueKind.STATIC_TYPE || !(structNode.inherits.result.dType is DataType_Struct))
                    {
                        throw Jolly.addError(structNode.inherits.location, "Can only inherit from other structs");
                    }
                    structType.inherits = (DataType_Struct)structNode.inherits.result.dType;
                }
            } break;

            case NT.OBJECT: break;

            default: throw Jolly.addError(ended.node.location, "Internal compiler error: illigal node used as enclosure");
            }     // switch(ended.type)
        }
Beispiel #2
0
 public override IR getMember(IR i, int index, IRList list)
 {
     if (index >= members.Length)
     {
         throw Jolly.addError(new SourceLocation(), "Out of index bounds");
     }
     return(list.Add(IR.getMember(i, members[index], index)));
 }
Beispiel #3
0
 public override IR subscript(IR i, IR index, IRList list)
 {
     if (index.dType != Lookup.I32)
     {
         throw Jolly.addError(new SourceLocation(), "Only int can be used as subscript");
     }
     return(list.Add(IR.operation <IR_Substript>(i, index, null)));
 }
Beispiel #4
0
        public override IR getMember(IR i, string name, IRList list)
        {
            int             index;
            DataType_Struct iterator = this;

            while (iterator != null)
            {
                if (iterator.memberMap.TryGetValue(name, out index))
                {
                    IR _struct = i;
                    if (iterator != this)
                    {
                        _struct = list.Add(IR.cast <IR_Reinterpret>(i, iterator, null));
                    }
                    return(list.Add(IR.getMember(_struct, iterator.members[index], index + (iterator.inherits == null ? 0 : 1))));
                }
                iterator = iterator.inherits;
            }
            return(null);
        }
Beispiel #5
0
        public override IR implicitCast(IR i, DataType to, IRList list)
        {
            if (!(to is DataType_Reference))
            {
                return(null);
            }
            DataType_Struct iterator = this;

            while (iterator != null)
            {
                if (iterator == to)
                {
                    return(list.Add(IR.cast <IR_Reinterpret>(i, to, null)));
                }
            }
            return(null);
        }