From d5e324fd538f3a1a0d97ddcbc1543dd7ad61e09c Mon Sep 17 00:00:00 2001 From: Dibyendu Majumdar Date: Sun, 21 Feb 2021 23:30:49 +0000 Subject: [PATCH] issue #217 fix the ravicomp compiler to use the same typecodes as Ravi --- ravicomp/src/linearizer.c | 3 ++ ravicomp/src/linearizer.h | 2 +- ravicomp/src/parser.h | 70 ++++++++++++++++++++++++++++++++------- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/ravicomp/src/linearizer.c b/ravicomp/src/linearizer.c index 45134df..cce8b2e 100644 --- a/ravicomp/src/linearizer.c +++ b/ravicomp/src/linearizer.c @@ -228,6 +228,7 @@ static const Constant *allocate_constant(Proc *proc, AstNode *node) { assert(node->type == EXPR_LITERAL); Constant c = {.type = node->literal_expr.type.type_code}; + assert(c.type == node->literal_expr.type.type_code); if (c.type == RAVI_TNUMINT) c.i = node->literal_expr.u.i; else if (c.type == RAVI_TNUMFLT) @@ -240,6 +241,7 @@ static const Constant *allocate_constant(Proc *proc, AstNode *node) static const Constant *allocate_integer_constant(Proc *proc, int i) { Constant c = {.type = RAVI_TNUMINT, .i = i}; + assert(c.type == RAVI_TNUMINT); return add_constant(proc, &c); } @@ -290,6 +292,7 @@ Instruction *raviX_last_instruction(BasicBlock *block) static const Constant *allocate_string_constant(Proc *proc, const StringObject *s) { Constant c = {.type = RAVI_TSTRING, .s = s}; + assert(c.type == RAVI_TSTRING); return add_constant(proc, &c); } diff --git a/ravicomp/src/linearizer.h b/ravicomp/src/linearizer.h index ad8165e..4809fd3 100644 --- a/ravicomp/src/linearizer.h +++ b/ravicomp/src/linearizer.h @@ -204,7 +204,7 @@ typedef struct PseudoGenerator { } PseudoGenerator; struct Constant { - uint8_t type; /* ravitype_t RAVI_TNUMINT, RAVI_TNUMFLT or RAVI_TSTRING */ + uint16_t type; /* ravitype_t RAVI_TNUMINT, RAVI_TNUMFLT or RAVI_TSTRING */ uint16_t index; /* index number starting from 0 assigned to each constant - acts like a reg num. * Each type will be assigned separate range */ union { diff --git a/ravicomp/src/parser.h b/ravicomp/src/parser.h index 29196b7..ace05fe 100644 --- a/ravicomp/src/parser.h +++ b/ravicomp/src/parser.h @@ -113,18 +113,64 @@ DECLARE_PTR_LIST(AstNodeList, AstNode); ** other types appear then they are all treated as ANY **/ typedef enum { - RAVI_TANY = 0, /* Lua dynamic type */ - RAVI_TNUMINT = 1, /* integer number */ - RAVI_TNUMFLT, /* floating point number */ - RAVI_TARRAYINT, /* array of ints */ - RAVI_TARRAYFLT, /* array of doubles */ - RAVI_TFUNCTION, /* Lua or C Function */ - RAVI_TTABLE, /* Lua table */ - RAVI_TSTRING, /* string */ - RAVI_TNIL, /* NIL */ - RAVI_TBOOLEAN, /* boolean */ - RAVI_TUSERDATA, /* userdata or lightuserdata */ - RAVI_TVARARGS /* Not a real type - represents ... */ + RAVI_TI_NIL, + RAVI_TI_FALSE, + RAVI_TI_TRUE, + RAVI_TI_INTEGER, + RAVI_TI_FLOAT, + RAVI_TI_INTEGER_ARRAY, + RAVI_TI_FLOAT_ARRAY, + RAVI_TI_TABLE, + RAVI_TI_STRING, + RAVI_TI_FUNCTION, + RAVI_TI_USERDATA, + RAVI_TI_OTHER, + RAVI_TI_VARARGS, +} ravi_type_index; + +typedef uint32_t ravi_type_map; + +#define RAVI_TM_NIL (((ravi_type_map)1)<