diff lwasm/lwasm.c @ 576:40edb7de3857

Add 0b and 0B as a prefix for binary constants
author William Astle <lost@l-w.ca>
date Fri, 12 Jul 2024 23:02:57 -0600
parents 87f904e2b304
children 10f8fc64481d
line wrap: on
line diff
--- a/lwasm/lwasm.c	Wed Jun 05 11:40:38 2024 -0600
+++ b/lwasm/lwasm.c	Fri Jul 12 23:02:57 2024 -0600
@@ -641,6 +641,25 @@
 		}
 		return lw_expr_build(lw_expr_type_int, val * neg);
 	}
+	if (**p == '0' && (*((*p)+1) == 'b' || *((*p)+1) == 'B'))
+	{
+		val = 0;
+		// binary constant
+		(*p) += 2;
+
+		if (**p != '0' && **p != '1')
+		{
+			(*p)-2;
+			return NULL;
+		}
+
+		while (**p && (**p == '0' || **p == '1'))
+		{
+			val = val * 2 + (**p - '0');
+			(*p)++;
+		}
+		return lw_expr_build(lw_expr_type_int, val);
+	}
 	
 	if (**p == '$')
 	{