aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 20:38:03 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 20:38:03 +0000
commitfa640f13e8a231ec3a619cc360289828cc4fc114 (patch)
tree172b2ab65b0edf5e9abf9fa8c1c12bfacd3e67b5
parent228f548bd9096415d3f9ee6cf0f5355f6c6f133b (diff)
downloadovm-fa640f13e8a231ec3a619cc360289828cc4fc114.tar.gz
ovm-fa640f13e8a231ec3a619cc360289828cc4fc114.tar.bz2
ovm-fa640f13e8a231ec3a619cc360289828cc4fc114.zip
parse_word deals with characters now
Just takes the character literally as a number.
-rw-r--r--asm/parser.c63
1 files changed, 36 insertions, 27 deletions
diff --git a/asm/parser.c b/asm/parser.c
index 8292e39..9d8317d 100644
--- a/asm/parser.c
+++ b/asm/parser.c
@@ -72,39 +72,48 @@ data_type_t parse_data_type(const char *cstr, size_t length)
perr_t parse_word(token_t token, word *ret)
{
- assert(token.type == TOKEN_LITERAL_NUMBER);
- bool is_negative = token.str_size > 1 && token.str[0] == '-';
- word w = 0;
- if (is_negative)
+ if (token.type == TOKEN_LITERAL_NUMBER)
{
- char *end = NULL;
- // TODO: Make a standardised type of the same size as word in
- // base.h
- int64_t i = strtoll(token.str, &end, 0);
- if (!(end && end[0] == '\0'))
- return PERR_NOT_A_NUMBER;
- else if (errno == ERANGE)
+ bool is_negative = token.str_size > 1 && token.str[0] == '-';
+ word w = 0;
+ if (is_negative)
{
- errno = 0;
- return PERR_INTEGER_OVERFLOW;
+ char *end = NULL;
+ // TODO: Make a standardised type of the same size as word in
+ // base.h
+ int64_t i = strtoll(token.str, &end, 0);
+ if (!(end && end[0] == '\0'))
+ return PERR_NOT_A_NUMBER;
+ else if (errno == ERANGE)
+ {
+ errno = 0;
+ return PERR_INTEGER_OVERFLOW;
+ }
+ // Copy bits, do not cast
+ memcpy(&w, &i, sizeof(w));
}
- // Copy bits, do not cast
- memcpy(&w, &i, sizeof(w));
- }
- else
- {
- char *end = NULL;
- w = strtoull(token.str, &end, 0);
- if (!(end && end[0] == '\0'))
- return PERR_NOT_A_NUMBER;
- else if (errno == ERANGE)
+ else
{
- errno = 0;
- return PERR_INTEGER_OVERFLOW;
+ char *end = NULL;
+ w = strtoull(token.str, &end, 0);
+ if (!(end && end[0] == '\0'))
+ return PERR_NOT_A_NUMBER;
+ else if (errno == ERANGE)
+ {
+ errno = 0;
+ return PERR_INTEGER_OVERFLOW;
+ }
}
+ *ret = w;
+ return PERR_OK;
}
- *ret = w;
- return PERR_OK;
+ else if (token.type == TOKEN_LITERAL_CHAR)
+ {
+ *ret = token.str[0];
+ return PERR_OK;
+ }
+ else
+ return PERR_NOT_A_NUMBER;
}
perr_t parse_inst_with_type(token_stream_t *stream, inst_t *ret,