aboutsummaryrefslogtreecommitdiffstats
path: root/creole.c
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-02-25 21:01:03 +0000
committerGravatar Peter McGoron 2023-02-25 21:01:03 +0000
commit09d636c02cdbb13d10f1435d918cc36116715fc4 (patch)
treec7099a6c49ffa4521e144c5ed5a19186d08ec1ec /creole.c
parentget rid of unused lablen (diff)
export creole_decode; add db test
Diffstat (limited to 'creole.c')
-rw-r--r--creole.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/creole.c b/creole.c
index 26b0347..d3d51e4 100644
--- a/creole.c
+++ b/creole.c
@@ -99,16 +99,11 @@ static int read_eof(struct creole_reader *r)
* * lower bits are the encoded word.
*/
#define MAX_HIGH_BITS 15
-struct word {
- int len;
- int high_bits;
- creole_word word;
-};
/* Decode a set of continuation bytes directly into the word. This assumes
* that each continuation byte contains no high words.
*/
-static int read_continue(struct creole_reader *r, struct word *w,
+static int read_continue(struct creole_reader *r, struct creole_word *w,
int to_read)
{
int i;
@@ -137,7 +132,7 @@ static int read_continue(struct creole_reader *r, struct word *w,
* byte.
*/
#define START_BYTE_NUM 7
-static int parse_start_byte(unsigned char c, struct word *w)
+static int parse_start_byte(unsigned char c, struct creole_word *w)
{
static const struct {
/* The algorithm compares the mask to the start byte
@@ -200,7 +195,7 @@ static int parse_start_byte(unsigned char c, struct word *w)
/* This parses the first continuation byte if it is special. */
#define SPECIAL_CONTINUE_BYTE_NUM (START_BYTE_NUM - 3)
-static int parse_special_byte(unsigned char c, struct word *w)
+static int parse_special_byte(unsigned char c, struct creole_word *w)
{
/* The index denotes the amount of high bits that were in
* the start byte. This is the amount that the stored value
@@ -232,7 +227,7 @@ static int parse_special_byte(unsigned char c, struct word *w)
}
/* Parse an entire Pseudo-UTF8 sequence. */
-static int decode_seq(struct creole_reader *r, struct word *w)
+int creole_decode(struct creole_reader *r, struct creole_word *w)
{
int r_ret;
int to_read;
@@ -368,11 +363,11 @@ static enum creole_word_flag arg_get_type(unsigned high_bits)
static enum creole_compiler_ret
parse_line(struct creole_env *env, struct ins *ins, struct creole_reader *r)
{
- struct word w = {0};
+ struct creole_word w = {0};
int i;
ins->start = r->p;
- if (!decode_seq(r, &w))
+ if (!creole_decode(r, &w))
return CREOLE_OPCODE_READ_ERROR;
ins->opcode = w.word;
@@ -383,7 +378,7 @@ parse_line(struct creole_env *env, struct ins *ins, struct creole_reader *r)
if (opcode_info[ins->opcode].arglen > CREOLE_MAX_ARG)
return CREOLE_OPCODE_MALFORMED;
for (i = 0; i < opcode_info[ins->opcode].arglen; i++) {
- if (!decode_seq(r, &w))
+ if (!creole_decode(r, &w))
return CREOLE_ARG_READ_ERROR;
if (w.len == 1)
return CREOLE_ARG_MALFORMED;
@@ -399,7 +394,7 @@ parse_line(struct creole_env *env, struct ins *ins, struct creole_reader *r)
if (ins->opcode == CREOLE_DB) {
ins->datapt = r->p;
do {
- if (!decode_seq(r, &w))
+ if (!creole_decode(r, &w))
return CREOLE_ARG_READ_ERROR;
} while (w.len != 1);
if (w.word != 0)
@@ -408,7 +403,7 @@ parse_line(struct creole_env *env, struct ins *ins, struct creole_reader *r)
}
ins->datapt = NULL;
- if (!decode_seq(r, &w))
+ if (!creole_decode(r, &w))
return CREOLE_LAST_READ_ERROR;
if (w.word != 0 || w.len != 1)
return CREOLE_LAST_MALFORMED;
@@ -563,6 +558,8 @@ enum creole_run_ret creole_step(struct creole_env *env, creole_word *sc)
return CREOLE_RUN_DECODE_ERROR;
switch (ins.opcode) {
+ case CREOLE_DB:
+ break;
case CREOLE_PUSH:
check(read_val(env, &ins, 0, &a1));
check(creole_push(env, a1));