Mercurial > hg > index.cgi
changeset 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 | d562ecd3ffd8 |
children | e49d24f4a9a5 |
files | lwasm/lwasm.c |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
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 == '$') {