more goto-label handling code

This commit is contained in:
hyunghwan.chung 2019-07-18 15:51:55 +00:00
parent 6fddd95dce
commit 05837aef28
3 changed files with 54 additions and 1 deletions

View File

@ -93,8 +93,9 @@ class MyObject(Object)
System log(System.Log.INFO, idx asString, (if (tb value) { " PASS" } else { " FAIL" }), "\n"). System log(System.Log.INFO, idx asString, (if (tb value) { " PASS" } else { " FAIL" }), "\n").
]. ].
(if (true) { a: 10. b: 1p1000. 20000 }) dump. (if (true) { a: 10. b: 1p1000. 20000 }) dump.
[a: 10. b: 1000. ] value class dump. [A01: 10. B02: 1000. ] value class dump.
TODO:
Exception signal: 'experiment with exception signalling'. Exception signal: 'experiment with exception signalling'.

View File

@ -6690,6 +6690,38 @@ oops:
return -1; return -1;
} }
static int add_label (moo_t* moo, const moo_oocs_t* name)
{
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
moo_label_t* lab;
moo_ooch_t* nptr;
/* TODO: name must not have trailing colon? */
lab = cc->mth._label;
while (lab)
{
nptr = (moo_ooch_t*)(lab + 1);
if (moo_comp_oochars_oocstr(name->ptr, name->len, nptr) == 0)
{
/* duplicate label name */
/* TODO: there is a duplicate label... */
return -1;
}
}
lab = (moo_label_t*)moo_allocmem(moo, MOO_SIZEOF(*lab) + (name->len + 1) * MOO_SIZEOF(moo_ooch_t));
if (!lab) return -1;
nptr = (moo_ooch_t*)(lab + 1);
moo_copy_oochars (nptr, name->ptr, name->len);
nptr[name->len] = '\0';
lab->next = cc->mth._label;
cc->mth._label = lab;
return 0;
}
static int compile_special_statement (moo_t* moo) static int compile_special_statement (moo_t* moo)
{ {
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit; moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
@ -6752,6 +6784,7 @@ static int compile_special_statement (moo_t* moo)
/* this is a label */ /* this is a label */
/* remember the label location with the block depth */ /* remember the label location with the block depth */
MOO_DEBUG2 (moo, "LABEL => %.*js\n", TOKEN_NAME_LEN(moo), TOKEN_NAME_PTR(moo)); MOO_DEBUG2 (moo, "LABEL => %.*js\n", TOKEN_NAME_LEN(moo), TOKEN_NAME_PTR(moo));
/* TODO: if (add_label(moo, TOKEN_NAME(moo), level???) <= -1) return -1; */
GET_TOKEN (moo); GET_TOKEN (moo);
return 8888; /* indicates that non-statement has been seen and processed.*/ return 8888; /* indicates that non-statement has been seen and processed.*/
} }

View File

@ -399,6 +399,22 @@ struct moo_loop_t
moo_loop_t* next; moo_loop_t* next;
}; };
typedef struct moo_label_t moo_label_t;
struct moo_label_t
{
moo_ooch_t* name;
moo_oow_t level;
moo_label_t* next;
};
typedef struct moo_goto_t moo_goto_t;
struct moo_goto_t
{
moo_ooch_t* label_name;
moo_oow_t level;
moo_goto_t* next;
};
typedef struct moo_oopbuf_t moo_oopbuf_t; typedef struct moo_oopbuf_t moo_oopbuf_t;
struct moo_oopbuf_t struct moo_oopbuf_t
{ {
@ -532,6 +548,9 @@ struct moo_method_data_t
/* information about loop constructs */ /* information about loop constructs */
moo_loop_t* loop; moo_loop_t* loop;
moo_goto_t* _goto;
moo_label_t* _label;
/* byte code */ /* byte code */
moo_code_t code; moo_code_t code;
}; };