Mercurial > projects > dang
annotate sema/DType.d @ 116:0cd8d6ab3f89
Add in the types for float and co.
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sun, 25 May 2008 18:19:09 +0200 |
parents | 189c049cbfcc |
children | 54585ad7e426 |
rev | line source |
---|---|
26 | 1 module sema.DType; |
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 | 5 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
6 public |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
7 import sema.Operation; |
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
|
8 |
26 | 9 class DType |
10 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
11 private char[] id; |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
12 private SourceLocation loc; |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
13 public DType actual; |
26 | 14 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
15 this(Identifier id, DType actual = null) |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
16 { |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
17 this.id = id.name; |
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
18 this.loc = id.startLoc(); |
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 | 23 { |
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 | 26 } |
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 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
48 /// Returns true for integers, reals and complex numbers |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
49 bool isArithmetic() { return false; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
50 |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
51 /// 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
|
52 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
|
53 /// 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
|
54 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
|
55 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
56 /// Is this type a DReal |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
57 bool isReal() { return false; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
58 /// Return a DReal if this is one, otherwise return null |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
59 DReal asReal() { return null; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
60 |
26 | 61 int opEquals(Object o) |
62 { | |
63 if (auto t = cast(DType)o) | |
64 return this.actual is t.actual; | |
65 return 0; | |
66 } | |
67 | |
68 int opCmp(Object o) | |
69 { | |
70 if (auto t = cast(DType)o) | |
71 return cast(void*)this.actual - cast(void*)t.actual; | |
72 return 0; | |
73 } | |
74 | |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
75 /** |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
76 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
|
77 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
|
78 |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
79 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
|
80 difference in the lower bits of their hashes. |
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
81 */ |
26 | 82 hash_t toHash() |
83 { | |
84 return cast(hash_t)(cast(void*)this); | |
85 } | |
86 | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
87 char[] name() { return id; } |
88
eb5b2c719a39
Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents:
83
diff
changeset
|
88 SourceLocation getLoc() { return loc; } |
39
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
89 int byteSize() { return 0; } |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
90 |
58 | 91 /** |
92 Can this type legally be converted to that type with no casts? | |
93 True for short -> int etc. | |
94 */ | |
95 bool hasImplicitConversionTo(DType that) { return false; } | |
96 | |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
97 /** |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
98 Get an Operation describing how to use the supplied operator on the two |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
99 types given. |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
100 */ |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
101 Operation getOperationWith(Operator op, DType other) |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
102 { |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
103 Operation res; |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
104 return res; |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
105 } |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
106 |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
107 /** |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
108 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
|
109 */ |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
110 DPointer getPointerTo() |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
111 { |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
112 if(myPointer !is null) |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
113 return myPointer; |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
114 myPointer = new DPointer(this); |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
115 return myPointer; |
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
116 } |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
117 private DPointer myPointer; |
80
682e20aa224f
Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents:
77
diff
changeset
|
118 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
119 /** |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
120 Mangle the DType following the specs at http://digitalmars.com/d/1.0/abi.html |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
121 **/ |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
122 char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
123 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
124 /// expects to be void |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
125 return "v"; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
126 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
127 |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
128 /** |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
129 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
|
130 */ |
81 | 131 DArray getAsArray(int size) |
132 { | |
133 if(size in myArray) | |
134 return myArray[size]; | |
135 myArray[size] = new DArray(this, size); | |
136 return myArray[size]; | |
137 } | |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
81
diff
changeset
|
138 private DArray[int] myArray; |
81 | 139 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
140 static DInteger |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
141 Bool, |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
142 Byte, UByte, Short, UShort, |
103
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
143 Int, UInt, Long, ULong, |
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
144 Char, WChar, DChar; |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
145 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
146 static DReal Float, Double, Real; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
147 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
148 // Ignore - we dont support complex numbers yet |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
149 static DReal CFloat, CDouble, CReal; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
150 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
151 static DType Void; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
152 |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
153 static this() |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
154 { |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
155 Void = new DType("void"); |
26 | 156 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
157 Bool = new DInteger("bool", 1, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
158 Byte = new DInteger("byte", 8, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
159 UByte = new DInteger("ubyte", 8, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
160 Short = new DInteger("short", 16, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
161 UShort = new DInteger("ushort", 16, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
162 Int = new DInteger("int", 32, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
163 UInt = new DInteger("uint", 32, true); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
164 Long = new DInteger("long", 64, false); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
165 ULong = new DInteger("ulong", 64, true); |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
166 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
167 Float = new DReal("float", 32); |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
168 Double = new DReal("double", 64); |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
169 Real = Double; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
170 |
103
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
171 Char = new DInteger("char", 8, true); |
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
172 WChar = new DInteger("wchar", 16, true); |
09b4d74cb3f5
Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents:
96
diff
changeset
|
173 DChar = new DInteger("dchar", 32, true); |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
174 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
175 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
176 |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
177 /** |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
178 Class to represent the built-in numerical types, from byte to long, reals and |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
179 complex numbers. |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
180 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
181 Should not actually use this, but DInteger, DReal or DComplex. |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
182 */ |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
183 class DArithmetic : DType |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
184 { |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
185 private static char[][DArithmetic] mangle_types; |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
186 |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
187 static this() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
188 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
189 mangle_types = |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
190 [ |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
191 cast(DArithmetic) |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
192 Bool : "b", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
193 Byte : "g", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
194 UByte : "h", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
195 Short : "s", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
196 UShort : "t", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
197 Int : "i", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
198 UInt : "k", |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
199 Long : "l", |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
200 ULong : "m", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
201 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
202 Float : "f", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
203 Double : "d", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
204 Real : "e", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
205 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
206 /* |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
207 CFloat : "q", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
208 CDouble : "r", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
209 CReal : "c", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
210 */ |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
211 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
212 Char : "a", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
213 WChar : "u", |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
214 DChar : "w" |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
215 ]; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
216 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
217 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
218 this(char[] name, int bits, bool unsigned) |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
219 { |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
220 super(name, null); |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
221 this.bits = bits; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
222 this.unsigned = unsigned; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
223 } |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
224 |
39
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
225 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
|
226 |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
227 bool isArithmetic() { return true; } |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
228 |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
229 override Operation getOperationWith(Operator op, DType that) |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
230 { |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
231 Operation operation; |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
232 if (this is that) |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
233 operation = Operation.builtin(op, unsigned, isReal()); |
107
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
234 return operation; |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
235 } |
189c049cbfcc
Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents:
103
diff
changeset
|
236 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
237 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
238 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
239 return mangle_types[this]; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
240 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
241 |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
242 int bits; |
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
243 bool unsigned; |
26 | 244 } |
245 | |
116
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
246 class DInteger : DArithmetic |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
247 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
248 this(char[] name, int bits, bool unsigned) |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
249 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
250 super(name, bits, unsigned); |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
251 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
252 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
253 override bool hasImplicitConversionTo(DType that) |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
254 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
255 if (auto o = cast(DInteger)that) |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
256 return true; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
257 return false; |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
258 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
259 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
260 override bool isInteger() { return true; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
261 override DInteger asInteger() { return this; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
262 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
263 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
264 class DReal : DArithmetic |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
265 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
266 this(char[] name, int bits) |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
267 { |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
268 super(name, bits, false); |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
269 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
270 |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
271 override bool isReal() { return true; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
272 override DReal asReal() { return this; } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
273 } |
0cd8d6ab3f89
Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents:
107
diff
changeset
|
274 |
26 | 275 class DStruct : DType |
276 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
277 this(Identifier id, DType actual = null) |
26 | 278 { |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
279 super(id, actual); |
26 | 280 } |
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
|
281 |
39
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
282 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
|
283 |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
284 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
|
285 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
|
286 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
287 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
|
288 { |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
289 auto s = DStructMember(type, members.length); |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
290 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
|
291 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
292 bytes_total += type.byteSize(); |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
293 } |
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
|
294 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
295 int indexOf(char[] name) |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
296 { |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
297 if(name in members) |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
298 return members[name].index; |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
299 |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
300 return -1; |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
301 } |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
302 |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
303 DType typeOf(char[] name) |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
304 { |
58 | 305 if (auto res = name in members) |
306 return res.type; | |
307 return null; | |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
308 } |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
309 |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
310 DStructMember[char[]] members; |
39
1a7a308f75b2
Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
311 private int bytes_total; |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
312 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
313 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
314 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
315 return "S"~Integer.toString(name.length)~name; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
316 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
317 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
318 struct DStructMember |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
319 { |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
320 DType type; |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
321 int index; |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
49
diff
changeset
|
322 } |
26 | 323 } |
324 | |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
325 class DArray : DType |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
326 { |
81 | 327 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
|
328 { |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
329 super(id, actual); |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
330 this.arrayOf = arrayOf; |
81 | 331 this.size = size; |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
332 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
333 |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
334 override bool isArray() { return true; } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
335 override DArray asArray() { return this; } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
336 |
81 | 337 int byteSize() { return arrayOf.byteSize * size; } |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
338 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
339 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
340 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
341 return "G"~Integer.toString(size)~arrayOf.mangle; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
342 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
343 |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
344 DType arrayOf; |
81 | 345 const int size; |
72
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
346 } |
628cb46ab13b
First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
347 |
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
|
348 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
|
349 { |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
350 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
|
351 { |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
352 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
|
353 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
|
354 } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
355 |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
356 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
|
357 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
|
358 |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
359 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
|
360 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
361 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
362 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
363 return "P"~pointerOf.mangle; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
364 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
365 |
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
|
366 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
|
367 } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
72
diff
changeset
|
368 |
26 | 369 class DFunction : DType |
370 { | |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
371 this(Identifier id, DType actual = null) |
26 | 372 { |
27
9031487e97d7
Various changes related to DType
Anders Halager <halager@gmail.com>
parents:
26
diff
changeset
|
373 super(id, actual); |
26 | 374 } |
49
c7cde6af0095
Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents:
39
diff
changeset
|
375 |
64
91f10c34cd7b
Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents:
63
diff
changeset
|
376 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
|
377 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
|
378 |
96
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
379 override char[] mangle() |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
380 { |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
381 char[] res; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
382 res ~= "F"; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
383 |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
384 foreach(param ; params) |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
385 res ~= "J" ~ param.mangle; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
386 |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
387 res ~= "Z" ~ returnType.mangle; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
388 |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
389 return res; |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
390 } |
438e6ed4cda1
Now D-Mangling the function types. Still need to mangle "scopes" - by that i mean structs, classes and modules.
Anders Johnsen <skabet@gmail.com>
parents:
88
diff
changeset
|
391 |
26 | 392 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
|
393 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
|
394 bool firstParamIsReturnValue = false; |
26 | 395 } |
396 |