annotate sema/DType.d @ 160:6cb2f4201e2a

Improved static arrays Here is a list of some stuff that works char[3] s = "hey" char[3] s2 = s; s2[1] = 98 // no support for chars, but 98 = 'b' :) int[2] i; i[0] = 2; Still can't pass static arrays to functions
author Anders Halager <halager@gmail.com>
date Tue, 22 Jul 2008 13:29:20 +0200
parents 6e6355fb5f0f
children dc9bf56b7ace
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
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
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 120
diff changeset
9 ///
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
10 class DType
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
11 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
12 private char[] id;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 83
diff changeset
13 private SourceLocation loc;
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
14 public DType actual;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
15
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
16 this(Identifier id, DType actual = null)
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
17 {
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 83
diff changeset
18 this.id = id.name;
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 83
diff changeset
19 this.loc = id.startLoc();
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
20 this.actual = actual is null? this : actual;
27
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
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
23 this(char[] id, DType actual = null)
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
24 {
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
25 this.id = id;
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
26 this.actual = actual is null? this : actual;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
27 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
28
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
29 /// 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
30 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
31 /// 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
32 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
33
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
34 /// Is this type a DClass
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
35 bool isClass() { return false; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
36 /// Return a DClass if this is one, otherwise return null
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
37 DClass asClass() { return null; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
38
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
39 /// Is this type a DInterface
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
40 bool isInterface() { return false; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
41 /// Return a DInterface if this is one, otherwise return null
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
42 DInterface asInterface() { return null; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
43
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
44 /// Is this type a DStaticArray
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
45 bool isStaticArray() { return false; }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
46 /// Return a DStaticArray if this is one, otherwise return null
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
47 DStaticArray asStaticArray() { return null; }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
48
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
49 /// Is this type a DArray
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
50 bool isArray() { return false; }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
51 /// 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
52 DArray asArray() { return null; }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
53
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
54 /// 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
55 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
56 /// 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
57 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
58
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
59 /// 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
60 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
61 /// 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
62 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
63
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
64 /// 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
65 bool isArithmetic() { return false; }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
66
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
67 /// 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
68 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
69 /// 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
70 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
71
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
72 /// Is this type a DReal
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
73 bool isReal() { return false; }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
74 /// 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
75 DReal asReal() { return null; }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
76
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
77 int opEquals(Object o)
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
78 {
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
79 if (auto t = cast(DType)o)
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
80 return this.actual is t.actual;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
81 return 0;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
82 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
83
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
84 int opCmp(Object o)
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
85 {
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
86 if (auto t = cast(DType)o)
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
87 return cast(void*)this.actual - cast(void*)t.actual;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
88 return 0;
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
89 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
90
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
91 /**
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
92 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
93 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
94
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
95 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
96 difference in the lower bits of their hashes.
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
97 */
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
98 hash_t toHash()
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
99 {
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
100 return cast(hash_t)(cast(void*)this);
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
101 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
102
160
6cb2f4201e2a Improved static arrays
Anders Halager <halager@gmail.com>
parents: 144
diff changeset
103 char[] toString()
6cb2f4201e2a Improved static arrays
Anders Halager <halager@gmail.com>
parents: 144
diff changeset
104 {
6cb2f4201e2a Improved static arrays
Anders Halager <halager@gmail.com>
parents: 144
diff changeset
105 return id;
6cb2f4201e2a Improved static arrays
Anders Halager <halager@gmail.com>
parents: 144
diff changeset
106 }
6cb2f4201e2a Improved static arrays
Anders Halager <halager@gmail.com>
parents: 144
diff changeset
107
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
108 char[] name() { return id; }
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 83
diff changeset
109 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
110 int byteSize() { return 0; }
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
111
58
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
112 /**
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
113 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
114 True for short -> int etc.
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
115 */
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
116 bool hasImplicitConversionTo(DType that) { return false; }
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
117
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
118 /**
107
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
119 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
120 types given.
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
121 */
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
122 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
123 {
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
124 Operation res;
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
125 return res;
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
126 }
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
127
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
128 /**
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
129 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
130 */
80
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
131 DPointer getPointerTo()
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
132 {
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
133 if(myPointer !is null)
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
134 return myPointer;
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
135 myPointer = new DPointer(this);
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
136 return myPointer;
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
137 }
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
138 private DPointer myPointer;
80
682e20aa224f Pointers working now - big YAY
Anders Johnsen <skabet@gmail.com>
parents: 77
diff changeset
139
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
140 /**
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
141 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
142 **/
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
143 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
144 {
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
145 /// 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
146 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
147 }
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
148
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
149 /**
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 81
diff changeset
150 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
151 */
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
152 DStaticArray getAsStaticArray(int size)
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
153 {
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
154 if(size in myStaticArray)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
155 return myStaticArray[size];
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
156 myStaticArray[size] = new DStaticArray(this, size);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
157 return myStaticArray[size];
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
158 }
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
159 private DStaticArray[int] myStaticArray;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
160
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
161 DArray getAsArray()
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
162 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
163 if(myArray !is null)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
164 return myArray;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
165 myArray = new DArray(this);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
166 return myArray;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
167 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
168 private DArray myArray;
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
169
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
170 static DInteger
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
171 Bool,
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
172 Byte, UByte, Short, UShort,
103
09b4d74cb3f5 Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents: 96
diff changeset
173 Int, UInt, Long, ULong,
09b4d74cb3f5 Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents: 96
diff changeset
174 Char, WChar, DChar;
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
175
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
176 static DReal Float, Double, Real;
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
177
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
178 // 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
179 static DReal CFloat, CDouble, CReal;
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
180
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
181 static DType Void;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
182
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
183 static this()
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
184 {
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
185 Void = new DType("void");
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
186
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 120
diff changeset
187 Bool = new DInteger("bool", 1, true);
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
188 Byte = new DInteger("byte", 8, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
189 UByte = new DInteger("ubyte", 8, true);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
190 Short = new DInteger("short", 16, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
191 UShort = new DInteger("ushort", 16, true);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
192 Int = new DInteger("int", 32, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
193 UInt = new DInteger("uint", 32, true);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
194 Long = new DInteger("long", 64, false);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
195 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
196
118
54585ad7e426 Added the DType -> llvm type mapping for some more types
Anders Halager <halager@gmail.com>
parents: 116
diff changeset
197 Float = new DReal("float", 32);
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
198 Double = new DReal("double", 64);
118
54585ad7e426 Added the DType -> llvm type mapping for some more types
Anders Halager <halager@gmail.com>
parents: 116
diff changeset
199 Real = new DReal("real", 80);
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
200
103
09b4d74cb3f5 Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents: 96
diff changeset
201 Char = new DInteger("char", 8, true);
09b4d74cb3f5 Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents: 96
diff changeset
202 WChar = new DInteger("wchar", 16, true);
09b4d74cb3f5 Parsing char, wchar and dchar as basic types.
Anders Johnsen <skabet@gmail.com>
parents: 96
diff changeset
203 DChar = new DInteger("dchar", 32, true);
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
204 }
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
205 }
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
206
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
207 /**
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
208 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
209 complex numbers.
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 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
212 */
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
213 class DArithmetic : DType
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
214 {
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
215 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
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 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
218 {
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
219 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
220 [
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 Long : "l",
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
230 ULong : "m",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
231
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
232 Float : "f",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
233 Double : "d",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
234 Real : "e",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
235
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
236 /*
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
237 CFloat : "q",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
238 CDouble : "r",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
239 CReal : "c",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
240 */
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
241
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
242 Char : "a",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
243 WChar : "u",
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
244 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
245 ];
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
246 }
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
247
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
248 this(char[] name, int bits, bool unsigned)
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
249 {
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
250 super(name, null);
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
251 this.bits = bits;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
252 this.unsigned = unsigned;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
253 }
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
254
39
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
255 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
256
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
257 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
258
107
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
259 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
260 {
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
261 Operation operation;
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
262 if (this is that)
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
263 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
264 return operation;
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
265 }
189c049cbfcc Cleanup of codegen, better support for operators a few bugfixes
Anders Halager <halager@gmail.com>
parents: 103
diff changeset
266
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
267 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
268 {
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
269 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
270 }
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
271
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
272 int bits;
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
273 bool unsigned;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
274 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
275
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
276 class DInteger : DArithmetic
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
277 {
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
278 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
279 {
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
280 super(name, bits, unsigned);
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
281 }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
282
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
283 override bool hasImplicitConversionTo(DType that)
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
284 {
120
7d0898f77685 Implement the cast expression - works for integers and real/float/double
Anders Halager <halager@gmail.com>
parents: 119
diff changeset
285 if (that.isInteger() || that.isReal())
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
286 return true;
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
287 return false;
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
288 }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
289
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
290 override bool isInteger() { return true; }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
291 override DInteger asInteger() { return this; }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
292 }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
293
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
294 class DReal : DArithmetic
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
295 {
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
296 this(char[] name, int bits)
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
297 {
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
298 super(name, bits, false);
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
299 }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
300
119
c0b531362ca6 Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents: 118
diff changeset
301 override bool hasImplicitConversionTo(DType that)
c0b531362ca6 Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents: 118
diff changeset
302 {
120
7d0898f77685 Implement the cast expression - works for integers and real/float/double
Anders Halager <halager@gmail.com>
parents: 119
diff changeset
303 if (that.isInteger() || that.isReal())
119
c0b531362ca6 Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents: 118
diff changeset
304 return true;
c0b531362ca6 Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents: 118
diff changeset
305 return false;
c0b531362ca6 Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents: 118
diff changeset
306 }
c0b531362ca6 Non compileing commit. Work on floating points and casts
Anders Johnsen <skabet@gmail.com>
parents: 118
diff changeset
307
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
308 override bool isReal() { return true; }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
309 override DReal asReal() { return this; }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
310 }
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 107
diff changeset
311
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
312 class DStruct : DType
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
313 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
314 this(Identifier id, DType actual = null)
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
315 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
316 super(id, actual);
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
317 }
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
318
39
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
319 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
320
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
321 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
322 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
323
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
324 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
325 {
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
326 auto s = DStructMember(type, members.length);
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
327 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
328
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
329 bytes_total += type.byteSize();
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
330 }
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
331
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
332 int indexOf(char[] name)
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
333 {
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
334 if(name in members)
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
335 return members[name].index;
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
336
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
337 return -1;
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
338 }
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
339
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
340 DType typeOf(char[] name)
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
341 {
58
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
342 if (auto res = name in members)
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
343 return res.type;
fc62c5296a1c Add types to our Exp
Anders Halager <halager@gmail.com>
parents: 55
diff changeset
344 return null;
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
345 }
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
346
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
347 DStructMember[char[]] members;
39
1a7a308f75b2 Added some struct tests, and implemented a wrong struct assignment
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
348 private int bytes_total;
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
349
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
350 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
351 {
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
352 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
353 }
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
354
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
355 struct DStructMember
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
356 {
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
357 DType type;
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
358 int index;
132
a101853eaae0 Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents: 129
diff changeset
359
a101853eaae0 Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents: 129
diff changeset
360 char[] toString()
a101853eaae0 Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents: 129
diff changeset
361 {
a101853eaae0 Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents: 129
diff changeset
362 return type.toString();
a101853eaae0 Better scope-building. Still an error with structs and forward ref though.
Anders Johnsen <skabet@gmail.com>
parents: 129
diff changeset
363 }
55
79cb0afafabe Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents: 49
diff changeset
364 }
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
365 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
366
144
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
367 class DClass : DType
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
368 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
369 this(Identifier id, DType actual = null)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
370 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
371 super(id, actual);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
372 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
373
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
374 int byteSize() { return bytes_total; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
375
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
376 override bool isClass() { return true; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
377 override DClass asClass() { return this; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
378
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
379 void addMember(DType type, char[] name)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
380 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
381 auto s = DClassMember(type, members.length);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
382 members[name] = s;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
383
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
384 bytes_total += type.byteSize();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
385 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
386
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
387 int indexOf(char[] name)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
388 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
389 if(name in members)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
390 return members[name].index;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
391
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
392 return -1;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
393 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
394
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
395 DType typeOf(char[] name)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
396 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
397 if (auto res = name in members)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
398 return res.type;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
399 return null;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
400 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
401
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
402 DClassMember[char[]] members;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
403 private int bytes_total;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
404
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
405 override char[] mangle()
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
406 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
407 return "S"~Integer.toString(name.length)~name;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
408 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
409
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
410 struct DClassMember
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
411 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
412 DType type;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
413 int index;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
414
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
415 char[] toString()
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
416 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
417 return type.toString();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
418 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
419 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
420 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
421
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
422 class DInterface : DType
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
423 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
424 this(Identifier id, DType actual = null)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
425 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
426 super(id, actual);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
427 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
428
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
429 int byteSize() { return bytes_total; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
430
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
431 override bool isInterface() { return true; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
432 override DInterface asInterface() { return this; }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
433
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
434 void addMember(DType type, char[] name)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
435 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
436 auto s = DInterfaceMember(type, members.length);
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
437 members[name] = s;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
438
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
439 bytes_total += type.byteSize();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
440 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
441
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
442 int indexOf(char[] name)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
443 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
444 if(name in members)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
445 return members[name].index;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
446
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
447 return -1;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
448 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
449
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
450 DType typeOf(char[] name)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
451 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
452 if (auto res = name in members)
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
453 return res.type;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
454 return null;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
455 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
456
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
457 DInterfaceMember[char[]] members;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
458 private int bytes_total;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
459
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
460 override char[] mangle()
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
461 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
462 return "S"~Integer.toString(name.length)~name;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
463 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
464
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
465 struct DInterfaceMember
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
466 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
467 DType type;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
468 int index;
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
469
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
470 char[] toString()
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
471 {
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
472 return type.toString();
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
473 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
474 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
475 }
6e6355fb5f0f - Parsing nested attributes.
Anders Johnsen <skabet@gmail.com>
parents: 136
diff changeset
476
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
477 class DStaticArray : DType
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
478 {
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
479 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
480 {
160
6cb2f4201e2a Improved static arrays
Anders Halager <halager@gmail.com>
parents: 144
diff changeset
481 super(arrayOf.id ~ "[" ~ Integer.toString(size) ~ "]", actual);
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
482 this.arrayOf = arrayOf;
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
483 this.size = size;
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
484 }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
485
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
486 override bool isStaticArray() { return true; }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
487 override DStaticArray asStaticArray() { return this; }
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
488
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
489 int byteSize() { return arrayOf.byteSize * size; }
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
490
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
491 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
492 {
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
493 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
494 }
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
495
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
496 DType arrayOf;
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
497 const int size;
72
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
498 }
628cb46ab13b First update on the way to Arrays! :)
Anders Johnsen <skabet@gmail.com>
parents: 68
diff changeset
499
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
500 class DArray : DType
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
501 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
502 this(DType arrayOf, DType actual = null)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
503 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
504 super(id, actual);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
505 this.arrayOf = arrayOf;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
506 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
507
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
508 override bool isArray() { return true; }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
509 override DArray asArray() { return this; }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
510
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
511 int byteSize() { return 8; } // FIXME: Size is a pointer + on size. (platform depend)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
512
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
513 override char[] mangle()
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
514 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
515 return "G"~arrayOf.mangle; // FIXME: Need correct mangling
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
516 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
517
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
518 DType arrayOf;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
519 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
520
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
521 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
522 {
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
523 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
524 {
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
525 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
526 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
527 }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
528
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
529 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
530 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
531
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
532 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
533
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
534 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
535 {
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
536 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
537 }
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
538
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
539 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
540 }
13eea2c4e60d Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents: 72
diff changeset
541
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
542 class DFunction : DType
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
543 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
544 this(Identifier id, DType actual = null)
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
545 {
27
9031487e97d7 Various changes related to DType
Anders Halager <halager@gmail.com>
parents: 26
diff changeset
546 super(id, actual);
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
547 }
49
c7cde6af0095 Seperated the AST from LLVM
Anders Halager <halager@gmail.com>
parents: 39
diff changeset
548
64
91f10c34cd7b Fixed some bugs, removed the function gathering pass in codegen and types are
Anders Halager <halager@gmail.com>
parents: 63
diff changeset
549 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
550 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
551
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
552 override bool hasImplicitConversionTo(DType that)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
553 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
554 return returnType.hasImplicitConversionTo(that);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
555 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 132
diff changeset
556
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
557 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
558 {
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
559 char[] res;
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 120
diff changeset
560
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
561 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
562
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
563 foreach(param ; params)
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 120
diff changeset
564 res ~= param.mangle;
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
565
129
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 120
diff changeset
566 res ~= "Z";
ed815b31479b Added a Symbol
Anders Halager <halager@gmail.com>
parents: 120
diff changeset
567 res ~= returnType.mangle;
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
568
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
569 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
570 }
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
571
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
572 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
573 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
574 bool firstParamIsReturnValue = false;
26
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
575 }
b4dc2b2c0e38 Added a DType class
Anders Halager <halager@gmail.com>
parents:
diff changeset
576