@@ -80,9 +80,10 @@ class BackendX86_64 : CompilerBackend {
8080 types ~= Type(" u64" , 8 , false );
8181 types ~= Type(" i64" , 8 , true );
8282 types ~= Type(" addr" , 8 , false );
83- types ~= Type(" size " , 8 , true );
83+ types ~= Type(" isize " , 8 , true );
8484 types ~= Type(" usize" , 8 , false );
8585 types ~= Type(" cell" , 8 , false );
86+ types ~= Type(" icell" , 8 , true );
8687 types ~= Type(" bool" , 8 , false );
8788
8889 // built in structs
@@ -534,52 +535,44 @@ class BackendX86_64 : CompilerBackend {
534535 size = var.type.Size();
535536 }
536537
537- if (size != 8 ) {
538- output ~= " xor rax, rax\n " ;
539- }
540-
541538 string symbol = format(" __global_%s" , var.name.Sanitise());
539+ char op = var.type.isSigned? ' s' : ' z' ;
542540
543541 if (deref) {
544542 output ~= format(" mov rbx, [%s]\n " , symbol);
545-
546- if (var.type.isSigned) {
547- switch (size) {
548- case 1 : output ~= format(" movsx rax, byte [rbx + %d]\n " , offset); break ;
549- case 2 : output ~= format(" movsx rax, word [rbx + %d]\n " , offset); break ;
550- case 4 : output ~= format(" movsxd rax, dword [rbx + %d]\n " , offset); break ;
551- case 8 : output ~= format(" mov rax, [rbx + %d]\n " , offset); break ;
552- default : Error (node.error, " Bad variable type size" );
543+ switch (size) {
544+ case 1 : {
545+ output ~= format(" mov%cx rax, $(BYTE) [rbx + %d]\n " , op, offset);
546+ break ;
553547 }
554- }
555- else {
556- switch (size) {
557- case 1 : output ~= format(" mov al, [rbx + %d]\n " , offset); break ;
558- case 2 : output ~= format(" mov ax, [rbx + %d]\n " , offset); break ;
559- case 4 : output ~= format(" mov eax, [rbx + %d]\n " , offset); break ;
560- case 8 : output ~= format(" mov rax, [rbx + %d]\n " , offset); break ;
561- default : Error (node.error, " Bad variable type size" );
548+ case 2 : {
549+ output ~= format(" mov%cx rax, $(WORD) [rbx + %d]\n " , op, offset);
550+ break ;
551+ }
552+ case 4 : {
553+ output ~= format(" mov%cxd rax, $(DWORD) [rbx + %d]\n " , op, offset);
554+ break ;
562555 }
556+ case 8 : output ~= format(" mov rax, [rbx + %d]\n " , offset); break ;
557+ default : Error (node.error, " Bad variable type size" );
563558 }
564559 }
565560 else {
566- if (var.type.isSigned) {
567- switch (size) {
568- case 1 : output ~= format(" movsx rax, byte [%s + %d]\n " , symbol, offset); break ;
569- case 2 : output ~= format(" movsx rax, word [%s + %d]\n " , symbol, offset); break ;
570- case 4 : output ~= format(" movsxd rax, dword [%s + %d]\n " , symbol, offset); break ;
571- case 8 : output ~= format(" mov rax, [%s + %d]\n " , symbol, offset); break ;
572- default : Error (node.error, " Bad variable type size" );
561+ switch (size) {
562+ case 1 : {
563+ output ~= format(" mov%cx rax, byte [%s + %d]\n " , op, symbol, offset);
564+ break ;
573565 }
574- }
575- else {
576- switch (size) {
577- case 1 : output ~= format(" mov al, [%s + %d]\n " , symbol, offset); break ;
578- case 2 : output ~= format(" mov ax, [%s + %d]\n " , symbol, offset); break ;
579- case 4 : output ~= format(" mov eax, [%s + %d]\n " , symbol, offset); break ;
580- case 8 : output ~= format(" mov rax, [%s + %d]\n " , symbol, offset); break ;
581- default : Error (node.error, " Bad variable type size" );
566+ case 2 : {
567+ output ~= format(" mov%cx rax, word [%s + %d]\n " , op, symbol, offset);
568+ break ;
569+ }
570+ case 4 : {
571+ output ~= format(" mov%cxd rax, dword [%s + %d]\n " , op, symbol, offset);
572+ break ;
582573 }
574+ case 8 : output ~= format(" mov rax, [%s + %d]\n " , symbol, offset); break ;
575+ default : Error (node.error, " Bad variable type size" );
583576 }
584577 }
585578
0 commit comments