annotate sema/DType.d @ 83:9e90694f5da0 new_gen

Parse array indexing, and allow reading from arrays
author Anders Halager <halager@gmail.com>
date Fri, 02 May 2008 19:54:22 +0200
parents 110c7e1c4ca2
children eb5b2c719a39
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
1 module sema.DType;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
2
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
3 import lexer.Token,
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
4 ast.Exp;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
5
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 27
diff changeset
6 import tango.io.Stdout;
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 27
diff changeset
7
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
8 class DType
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
9 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
10 private char[] id;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
11 private Location loc;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
12 public DType actual;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
13
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
14 this(Identifier id, DType actual = null)
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
15 {
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
16 Token temp = id.token;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
17 this.id = temp.get;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
18 this.loc = temp.location;
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
19 this.actual = actual is null? this : actual;
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
20 }
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
21
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
22 this(char[] id, DType actual = null)
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
23 {
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
24 this.id = id;
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
25 this.actual = actual is null? this : actual;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
26 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
27
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
28 /// Is this type a DStruct
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
29 bool isStruct() { return false; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
30 /// Return a DStruct if this is one, otherwise return null
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
31 DStruct asStruct() { return null; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
32
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
33 /// Is this type a DArray
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
34 bool isArray() { return false; }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
35 /// Return a DArray if this is one, otherwise return null
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
36 DArray asArray() { return null; }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
37
77
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
38 /// Is this type a DPointer
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
39 bool isPointer() { return false; }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
40 /// Return a DPointer if this is one, otherwise return null
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
41 DPointer asPointer() { return null; }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
42
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
43 /// Is this type a DFunction
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
44 bool isFunction() { return false; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
45 /// Return a DFunction if this is one, otherwise return null
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
46 DFunction asFunction() { return null; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
47
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
48 /// Is this type a DInteger
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
49 bool isInteger() { return false; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
50 /// Return a DInteger if this is one, otherwise return null
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
51 DInteger asInteger() { return null; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
52
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
53 int opEquals(Object o)
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
54 {
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
55 if (auto t = cast(DType)o)
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
56 return this.actual is t.actual;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
57 return 0;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
58 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
59
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
60 int opCmp(Object o)
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
61 {
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
62 if (auto t = cast(DType)o)
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
63 return cast(void*)this.actual - cast(void*)t.actual;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
64 return 0;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
65 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
66
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
67 /**
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
68 Hashing is done by casting the reference to a void* and taking that
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
69 value, but this gives a bad distribution of hash-values.
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
70
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
71 Multiple DType's allocated close to each other will only have a
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
72 difference in the lower bits of their hashes.
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
73 */
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
74 hash_t toHash()
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
75 {
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
76 return cast(hash_t)(cast(void*)this);
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
77 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
78
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
79 char[] name() { return id; }
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 27
diff changeset
80 Location getLoc() { return loc; }
39
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
81 int byteSize() { return 0; }
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
82
58
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
83 /**
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
84 Can this type legally be converted to that type with no casts?
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
85 True for short -> int etc.
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
86 */
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
87 bool hasImplicitConversionTo(DType that) { return false; }
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
88
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
89 /**
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
90 Get a type representing a pointer to this type (from int to int*)
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
91 */
80
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
92 DPointer getPointerTo()
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
93 {
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
94 if(myPointer !is null)
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
95 return myPointer;
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
96 myPointer = new DPointer(this);
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
97 return myPointer;
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
98 }
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
99 private DPointer myPointer;
80
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
100
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
101 /**
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
102 Get a type representing a static array of this type with length 'size'
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
103 */
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
104 DArray getAsArray(int size)
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
105 {
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
106 if(size in myArray)
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
107 return myArray[size];
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
108 myArray[size] = new DArray(this, size);
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
109 return myArray[size];
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
110 }
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
111 private DArray[int] myArray;
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
112
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
113 static DInteger
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
114 Bool,
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
115 Byte, UByte, Short, UShort,
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
116 Int, UInt, Long, ULong;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
117
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
118 static DType Void;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
119
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
120 static this()
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
121 {
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
122 Void = new DType("void");
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
123
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
124 Bool = new DInteger("bool", 1, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
125 Byte = new DInteger("byte", 8, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
126 UByte = new DInteger("ubyte", 8, true);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
127 Short = new DInteger("short", 16, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
128 UShort = new DInteger("ushort", 16, true);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
129 Int = new DInteger("int", 32, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
130 UInt = new DInteger("uint", 32, true);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
131 Long = new DInteger("long", 64, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
132 ULong = new DInteger("ulong", 64, true);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
133 }
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
134 }
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
135
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
136 /**
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
137 Class to represent the built-in integer types, from byte to long.
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
138 */
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
139 class DInteger : DType
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
140 {
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
141 this(char[] name, int bits, bool unsigned)
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
142 {
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
143 super(name, null);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
144 this.bits = bits;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
145 this.unsigned = unsigned;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
146 }
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
147
39
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
148 override int byteSize() { return bits / 8; }
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
149
58
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
150 override bool hasImplicitConversionTo(DType that)
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
151 {
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
152 if (auto o = cast(DInteger)that)
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 64
diff changeset
153 return true;
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 64
diff changeset
154 // return this.bits >= o.bits;
58
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
155 return false;
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
156 }
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
157
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
158 override bool isInteger() { return true; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
159 override DInteger asInteger() { return this; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
160
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
161 int bits;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
162 bool unsigned;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
163 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
164
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
165 class DStruct : DType
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
166 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
167 this(Identifier id, DType actual = null)
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
168 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
169 super(id, actual);
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
170 }
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 27
diff changeset
171
39
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
172 int byteSize() { return bytes_total; }
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
173
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
174 override bool isStruct() { return true; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
175 override DStruct asStruct() { return this; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
176
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
177 void addMember(DType type, char[] name)
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 27
diff changeset
178 {
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
179 auto s = DStructMember(type, members.length);
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
180 members[name] = s;
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 27
diff changeset
181
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
182 bytes_total += type.byteSize();
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
183 }
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 27
diff changeset
184
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
185 int indexOf(char[] name)
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
186 {
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
187 if(name in members)
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
188 return members[name].index;
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
189
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
190 return -1;
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
191 }
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
192
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
193 DType typeOf(char[] name)
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
194 {
58
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
195 if (auto res = name in members)
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
196 return res.type;
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
197 return null;
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
198 }
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
199
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
200 DStructMember[char[]] members;
39
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
201 private int bytes_total;
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
202
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
203 struct DStructMember
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
204 {
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
205 DType type;
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
206 int index;
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
207 }
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
208 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
209
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
210 class DArray : DType
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
211 {
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
212 this(DType arrayOf, int size, DType actual = null)
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
213 {
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
214 super(id, actual);
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
215 this.arrayOf = arrayOf;
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
216 this.size = size;
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
217 }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
218
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
219 override bool isArray() { return true; }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
220 override DArray asArray() { return this; }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
221
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
222 int byteSize() { return arrayOf.byteSize * size; }
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
223
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
224 DType arrayOf;
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
225 const int size;
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
226 }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
227
77
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
228 class DPointer : DType
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
229 {
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
230 this(DType pointerOf, DType actual = null)
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
231 {
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
232 super(id, actual);
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
233 this.pointerOf = pointerOf;
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
234 }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
235
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
236 override bool isPointer() { return true; }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
237 override DPointer asPointer() { return this; }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
238
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
239 int byteSize() { return DType.Int.byteSize; }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
240
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
241 DType pointerOf;
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
242 }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
243
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
244 class DFunction : DType
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
245 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
246 this(Identifier id, DType actual = null)
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
247 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
248 super(id, actual);
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
249 }
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
250
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
251 override bool isFunction() { return true; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
252 override DFunction asFunction() { return this; }
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
253
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
254 DType[] params;
63
9f8131676242 Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents: 58
diff changeset
255 DType returnType;
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
256 bool firstParamIsReturnValue = false;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
257 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
258