modify reader

This commit is contained in:
Peter McGoron 2023-03-23 18:13:11 +00:00
parent 6d30be57f7
commit 22674528da
2 changed files with 10 additions and 3 deletions

View File

@ -338,6 +338,7 @@ int creole_encode(creole_word i, unsigned encode_to, unsigned high_bits,
struct ins {
unsigned char *start;
unsigned char *datapt;
size_t dataptlen;
enum creole_opcode opcode;
creole_word w[CREOLE_MAX_ARG];
creole_word w_flags[CREOLE_MAX_ARG];
@ -404,10 +405,12 @@ parse_line(struct creole_env *env, struct ins *ins, struct creole_reader *r)
if (ins->opcode == CREOLE_DB) {
ins->datapt = r->p;
ins->dataptlen = 0;
do {
if (!creole_decode(r, &w))
return CREOLE_ARG_READ_ERROR;
} while (w.len != 1);
ins->dataptlen = r->p - ins->datapt - 1;
if (w.word != 0)
return CREOLE_LAST_READ_ERROR;
return CREOLE_COMPILE_OK;
@ -430,7 +433,8 @@ add_to_env(struct creole_env *env, struct ins *ins)
{
switch (ins->opcode) {
case CREOLE_DB:
env->dats[ins->w[0]] = ins->datapt;
env->dats[ins->w[0]].p = ins->datapt;
env->dats[ins->w[0]].left = ins->dataptlen;
break;
default:
;
@ -570,7 +574,8 @@ enum creole_run_ret creole_step(struct creole_env *env, creole_word *sc)
switch (ins.opcode) {
case CREOLE_DB:
env->dats[ins.w[0]] = ins.datapt;
env->dats[ins->w[0]].p = ins->datapt;
env->dats[ins->w[0]].left = ins->dataptlen;
break;
case CREOLE_PUSH:
check(read_val(env, &ins, 0, &a1));

View File

@ -106,7 +106,7 @@ struct creole_reader {
};
struct creole_env {
unsigned char **dats;
struct creole_reader *dats;
size_t datlen;
creole_word *reg;
@ -117,6 +117,8 @@ struct creole_env {
struct creole_reader r_current;
struct creole_reader r_start;
void *send_ctx;
};
int creole_decode(struct creole_reader *r, struct creole_word *w);