shithub: rgbds

Download patch

ref: 045a9e8b93048379b60afc9992d6f245d5129a89
parent: 0836f67d429d2f545f43e203023d174ca4442779
author: Jakub Kądziołka <[email protected]>
date: Sun Oct 11 23:32:49 EDT 2020

Report only one error when invalid shift has argument

Not to mention that incrementing a variable in a loop is kinda dumb.

--- a/include/asm/macro.h
+++ b/include/asm/macro.h
@@ -29,7 +29,7 @@
 char const *macro_GetUniqueIDStr(void);
 void macro_SetUniqueID(uint32_t id);
 uint32_t macro_UseNewUniqueID(void);
-void macro_ShiftCurrentArgs(void);
+void macro_ShiftCurrentArgs(int32_t count);
 uint32_t macro_NbArgs(void);
 
 #endif
--- a/src/asm/macro.c
+++ b/src/asm/macro.c
@@ -128,12 +128,15 @@
 	return maxUniqueID;
 }
 
-void macro_ShiftCurrentArgs(void)
+void macro_ShiftCurrentArgs(int32_t count)
 {
 	if (!macroArgs)
 		error("Cannot shift macro arguments outside of a macro\n");
-	else if (macroArgs->shift != macroArgs->nbArgs)
-		macroArgs->shift++;
+	else if (macroArgs->shift < macroArgs->nbArgs) {
+		macroArgs->shift += count;
+		if (macroArgs->shift > macroArgs->nbArgs)
+			macroArgs->shift = macroArgs->nbArgs;
+	}
 }
 
 uint32_t macro_NbArgs(void)
--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -579,13 +579,8 @@
 		}
 ;
 
-shift		: T_POP_SHIFT		{ macro_ShiftCurrentArgs(); }
-		| T_POP_SHIFT uconst
-		{
-			int32_t i = $2;
-			while (i--)
-				macro_ShiftCurrentArgs();
-		}
+shift		: T_POP_SHIFT		{ macro_ShiftCurrentArgs(1); }
+		| T_POP_SHIFT uconst	{ macro_ShiftCurrentArgs($2); }
 ;
 
 load		: T_POP_LOAD string ',' sectiontype sectorg sectattrs {
--- a/test/asm/shift-outside-macro.asm
+++ b/test/asm/shift-outside-macro.asm
@@ -1,1 +1,2 @@
 shift
+shift 3
--- a/test/asm/shift-outside-macro.err
+++ b/test/asm/shift-outside-macro.err
@@ -1,3 +1,5 @@
 ERROR: shift-outside-macro.asm(1):
     Cannot shift macro arguments outside of a macro
-error: Assembly aborted (1 errors)!
+ERROR: shift-outside-macro.asm(2):
+    Cannot shift macro arguments outside of a macro
+error: Assembly aborted (2 errors)!