@@ -21,16 +21,16 @@ private enum WordType {
2121}
2222
2323private struct Word {
24- WordType type;
25- bool inline;
26- Node[] inlineNodes;
27- bool error;
28- Type[] params;
24+ WordType type;
25+ bool inline;
26+ Node[] inlineNodes;
27+ bool error;
28+ UsedType[] params;
2929
3030 // for C words
31- Type ret;
32- bool isVoid;
33- string symbolName;
31+ UsedType ret;
32+ bool isVoid;
33+ string symbolName;
3434}
3535
3636class BackendARM64 : CompilerBackend {
@@ -71,24 +71,26 @@ class BackendARM64 : CompilerBackend {
7171
7272 // built in structs
7373 types ~= Type(" Array" , 24 , true , [
74- StructEntry(GetType(" usize" ), " length" ),
75- StructEntry(GetType(" usize" ), " memberSize" ),
76- StructEntry(GetType(" addr" ), " elements" )
74+ StructEntry(UsedType( GetType(" usize" ), false ), " length" ),
75+ StructEntry(UsedType( GetType(" usize" ), false ), " memberSize" ),
76+ StructEntry(UsedType( GetType(" addr" ), false ), " elements" )
7777 ]);
7878 NewConst(" Array.length" , 0 );
7979 NewConst(" Array.memberSize" , 8 );
8080 NewConst(" Array.elements" , 16 );
8181 NewConst(" Array.sizeof" , 8 * 3 );
8282
8383 types ~= Type(" Exception" , 24 + 8 , true , [
84- StructEntry(GetType(" bool" ), " error" ),
85- StructEntry(GetType(" Array" ), " msg" )
84+ StructEntry(UsedType( GetType(" bool" ), false ), " error" ),
85+ StructEntry(UsedType( GetType(" Array" ), false ), " msg" )
8686 ]);
8787 NewConst(" Exception.bool" , 0 );
8888 NewConst(" Exception.msg" , 8 );
8989 NewConst(" Exception.sizeof" , 24 + 8 );
9090
91- globals ~= Global(" _cal_exception" , GetType(" Exception" ), false , 0 );
91+ globals ~= Global(
92+ " _cal_exception" , UsedType(GetType(" Exception" ), false ), false , 0
93+ );
9294
9395 foreach (ref type ; types) {
9496 NewConst(format(" %s.sizeof" , type.name), cast (long ) type.size);
@@ -573,14 +575,14 @@ class BackendARM64 : CompilerBackend {
573575
574576 thisFunc = node.name;
575577
576- Type [] params;
578+ UsedType [] params;
577579
578580 foreach (ref type ; node.paramTypes) {
579- if (! TypeExists(type)) {
580- Error(node.error, " Type '%s' doesn't exist" , type);
581+ if (! TypeExists(type.name )) {
582+ Error(node.error, " Type '%s' doesn't exist" , type.name );
581583 }
582584
583- params ~= GetType(type);
585+ params ~= UsedType( GetType(type.name), type.ptr );
584586 }
585587
586588 if (node.inline) {
@@ -622,10 +624,10 @@ class BackendARM64 : CompilerBackend {
622624 // allocate parameters
623625 size_t paramSize = node.params.length * 8 ;
624626 foreach (ref type ; node.paramTypes) {
625- if (! TypeExists(type)) {
626- Error(node.error, " Type '%s' doesn't exist" , type);
627+ if (! TypeExists(type.name )) {
628+ Error(node.error, " Type '%s' doesn't exist" , type.name );
627629 }
628- if (GetType(type).isStruct) {
630+ if (GetType(type.name ).isStruct && ! type.ptr ) {
629631 Error(node.error, " Structures cannot be used in function parameters" );
630632 }
631633 }
@@ -641,7 +643,8 @@ class BackendARM64 : CompilerBackend {
641643 Variable var;
642644
643645 var.name = param;
644- var.type = GetType(type);
646+ var.type.type = GetType(type.name);
647+ var.type.ptr = type.ptr;
645648 var.offset = cast (uint ) offset;
646649 offset += var.Size();
647650 variables ~= var;
@@ -811,8 +814,8 @@ class BackendARM64 : CompilerBackend {
811814 }
812815
813816 override void CompileLet (LetNode node) {
814- if (! TypeExists(node.varType)) {
815- Error(node.error, " Undefined type '%s'" , node.varType);
817+ if (! TypeExists(node.varType.name )) {
818+ Error(node.error, " Undefined type '%s'" , node.varType.name );
816819 }
817820 if (VariableExists(node.name) || (node.name in words)) {
818821 Error(node.error, " Variable name '%s' already used" , node.name);
@@ -824,7 +827,8 @@ class BackendARM64 : CompilerBackend {
824827 if (inScope) {
825828 Variable var;
826829 var.name = node.name;
827- var.type = GetType(node.varType);
830+ var.type.type = GetType(node.varType.name);
831+ var.type.ptr = node.varType.ptr;
828832 var.offset = 0 ;
829833 var.array = node.array;
830834 var.arraySize = node.arraySize;
@@ -854,7 +858,8 @@ class BackendARM64 : CompilerBackend {
854858 }
855859
856860 Global global;
857- global.type = GetType(node.varType);
861+ global.type.type = GetType(node.varType.name);
862+ global.type.ptr = node.varType.ptr;
858863 global.array = node.array;
859864 global.arraySize = node.arraySize;
860865 global.name = node.name;
@@ -878,13 +883,14 @@ class BackendARM64 : CompilerBackend {
878883 }
879884 }
880885
881- if (! TypeExists(node.arrayType)) {
882- Error(node.error, " Type '%s' doesn't exist" , node.arrayType);
886+ if (! TypeExists(node.arrayType.name )) {
887+ Error(node.error, " Type '%s' doesn't exist" , node.arrayType.name );
883888 }
884889
885- array.type = GetType(node.arrayType);
886- array.global = ! inScope || node.constant;
887- arrays ~= array;
890+ array.type.type = GetType(node.arrayType.name);
891+ array.type.ptr = node.arrayType.ptr;
892+ array.global = ! inScope || node.constant;
893+ arrays ~= array;
888894
889895 if (! inScope || node.constant) {
890896 LoadAddress(" x9" , format(" __array_%d_meta" , arrays.length - 1 ));
@@ -915,9 +921,10 @@ class BackendARM64 : CompilerBackend {
915921 variables ~= var;
916922
917923 // create metadata variable
918- var.type = GetType(" Array" );
919- var.offset = 0 ;
920- var.array = false ;
924+ var.type.type = GetType(" Array" );
925+ var.type.ptr = false ;
926+ var.offset = 0 ;
927+ var.array = false ;
921928
922929 foreach (ref var2 ; variables) {
923930 var2.offset += var.Size();
@@ -942,7 +949,7 @@ class BackendARM64 : CompilerBackend {
942949 override void CompileString (StringNode node) {
943950 auto arrayNode = new ArrayNode(node.error);
944951
945- arrayNode.arrayType = " u8" ;
952+ arrayNode.arrayType = new TypeNode(node.error, " u8" , false ) ;
946953 arrayNode.constant = node.constant;
947954
948955 foreach (ref ch ; node.value) {
@@ -1003,22 +1010,22 @@ class BackendARM64 : CompilerBackend {
10031010 word.type = WordType.C;
10041011
10051012 foreach (ref param ; node.types) {
1006- if (! TypeExists(param)) {
1007- Error(node.error, " Unknown type '%s'" , param);
1013+ if (! TypeExists(param.name )) {
1014+ Error(node.error, " Unknown type '%s'" , param.name );
10081015 }
10091016
1010- word.params ~= GetType(param);
1017+ word.params ~= UsedType( GetType(param.name), param.ptr );
10111018 }
10121019
1013- if (node.retType == " void" ) {
1020+ if (( node.retType.name == " void" ) && ! node.retType.ptr ) {
10141021 word.isVoid = true ;
10151022 }
10161023 else {
1017- if (! TypeExists(node.retType)) {
1018- Error(node.error, " Unknown type '%s'" , node.retType);
1024+ if (! TypeExists(node.retType.name )) {
1025+ Error(node.error, " Unknown type '%s'" , node.retType.name );
10191026 }
10201027
1021- word.ret = GetType(node.retType);
1028+ word.ret = UsedType( GetType(node.retType.name), node.retType.ptr );
10221029 }
10231030
10241031 word.symbolName = node.func;
0 commit comments