added code that handles pool dictionary defintion
This commit is contained in:
parent
9e720c40d0
commit
5700b57d57
154
stix/lib/comp.c
154
stix/lib/comp.c
@ -2163,13 +2163,14 @@ oops:
|
||||
return STIX_NULL;
|
||||
}
|
||||
|
||||
static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, const stix_ucs_t* fqn, const stix_ioloc_t* fqn_loc, stix_ucs_t* name, stix_oop_set_t* ns_oop)
|
||||
static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, int accept_pooldic_as_ns, const stix_ucs_t* fqn, const stix_ioloc_t* fqn_loc, stix_ucs_t* name, stix_oop_set_t* ns_oop)
|
||||
{
|
||||
const stix_uch_t* ptr, * dot;
|
||||
stix_size_t len;
|
||||
stix_ucs_t seg;
|
||||
stix_oop_set_t dic;
|
||||
stix_oop_association_t ass;
|
||||
int pooldic_gotten = 0;
|
||||
|
||||
dic = stix->sysdic;
|
||||
ptr = fqn->ptr;
|
||||
@ -2182,6 +2183,8 @@ static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, const stix_ucs
|
||||
dot = stix_findchar (ptr, len, '.');
|
||||
if (dot)
|
||||
{
|
||||
if (pooldic_gotten) goto wrong_name;
|
||||
|
||||
seg.len = dot - ptr;
|
||||
|
||||
if (is_reserved_word(&seg)) goto wrong_name;
|
||||
@ -2196,10 +2199,21 @@ static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, const stix_ucs
|
||||
dic = (stix_oop_set_t)ass->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (accept_pooldic_as_ns && STIX_CLASSOF(stix, ass->value) == stix->_pool_dictionary)
|
||||
{
|
||||
/* A pool dictionary is treated as if it's a name space.
|
||||
* However, the pool dictionary can only act as a name space
|
||||
* if it's the second last segment. */
|
||||
dic = (stix_oop_set_t)ass->value;
|
||||
pooldic_gotten = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto wrong_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stix_oop_set_t t;
|
||||
@ -2501,9 +2515,11 @@ static int get_variable_info (stix_t* stix, const stix_ucs_t* name, const stix_i
|
||||
stix_oop_association_t ass;
|
||||
|
||||
/*TODO: handle self.XXX ---------- */
|
||||
/* TOOD: handle pool dictionary ---- */
|
||||
if (preprocess_dotted_name (stix, 1, name, name_loc, &last, &ns_oop) <= -1) return -1;
|
||||
if (preprocess_dotted_name (stix, 1, 1, name, name_loc, &last, &ns_oop) <= -1) return -1;
|
||||
|
||||
printf ("checking variable ");
|
||||
print_ucs (&last);
|
||||
printf ("\n");
|
||||
ass = stix_lookupdic (stix, ns_oop, &last);
|
||||
if (ass)
|
||||
{
|
||||
@ -2579,6 +2595,7 @@ static int get_variable_info (stix_t* stix, const stix_ucs_t* name, const stix_i
|
||||
ass = stix_lookupdic (stix, stix->c->cls.ns_oop, name);
|
||||
if (!ass && stix->c->cls.ns_oop != stix->sysdic)
|
||||
ass = stix_lookupdic (stix, stix->sysdic, name);
|
||||
/* TODO: search in the pool dictionary */
|
||||
if (ass)
|
||||
{
|
||||
var->type = VAR_GLOBAL;
|
||||
@ -2893,7 +2910,7 @@ static int add_to_arlit_buffer (stix_t* stix, stix_oop_t item)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __compile_byte_array_literal (stix_t* stix, stix_oop_t* xlit)
|
||||
static int __read_byte_array_literal (stix_t* stix, stix_oop_t* xlit)
|
||||
{
|
||||
stix_ooi_t tmp;
|
||||
stix_oop_t ba;
|
||||
@ -2945,7 +2962,7 @@ struct arlit_info_t
|
||||
|
||||
typedef struct arlit_info_t arlit_info_t;
|
||||
|
||||
static int __compile_array_literal (stix_t* stix, stix_oop_t* xlit)
|
||||
static int __read_array_literal (stix_t* stix, stix_oop_t* xlit)
|
||||
{
|
||||
stix_oop_t lit, a;
|
||||
stix_size_t i, saved_arlit_count;
|
||||
@ -3018,14 +3035,14 @@ printf ("LARGE NOT IMPLEMENTED IN COMPILE_ARRAY_LITERAL\n");
|
||||
saved_arlit_count = stix->c->mth.arlit_count;
|
||||
/* TODO: get rid of recursion?? */
|
||||
GET_TOKEN (stix);
|
||||
if (__compile_array_literal (stix, &lit) <= -1) return -1;
|
||||
if (__read_array_literal (stix, &lit) <= -1) return -1;
|
||||
stix->c->mth.arlit_count = saved_arlit_count;
|
||||
break;
|
||||
|
||||
case STIX_IOTOK_BPAREN: /* #[ */
|
||||
case STIX_IOTOK_LBRACK: /* [ */
|
||||
GET_TOKEN (stix);
|
||||
if (__compile_byte_array_literal (stix, &lit) <= -1) return -1;
|
||||
if (__read_byte_array_literal (stix, &lit) <= -1) return -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -3058,37 +3075,57 @@ done:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static STIX_INLINE int read_byte_array_literal (stix_t* stix, stix_oop_t* xlit)
|
||||
{
|
||||
GET_TOKEN (stix); /* skip #[ and read the next token */
|
||||
return __read_byte_array_literal(stix, xlit);
|
||||
}
|
||||
|
||||
static int compile_byte_array_literal (stix_t* stix)
|
||||
{
|
||||
stix_oop_t lit;
|
||||
stix_size_t index;
|
||||
|
||||
GET_TOKEN (stix); /* skip #[ and read the next token */
|
||||
if (__compile_byte_array_literal (stix, &lit) <= -1) return -1;
|
||||
|
||||
printf ("\tpush_literal byte_array\n");
|
||||
if (add_literal (stix, lit, &index) <= -1 ||
|
||||
if (read_byte_array_literal(stix, &lit) <= -1 ||
|
||||
add_literal(stix, lit, &index) <= -1 ||
|
||||
emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1;
|
||||
printf ("\tpush_literal byte_array\n");
|
||||
|
||||
GET_TOKEN (stix);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_array_literal (stix_t* stix, stix_oop_t* xlit)
|
||||
{
|
||||
int x;
|
||||
stix_size_t saved_arlit_count;
|
||||
|
||||
stix->c->in_array = 1;
|
||||
if (get_token(stix) <= -1)
|
||||
{
|
||||
/* skip #( and read the next token */
|
||||
stix->c->in_array = 0;
|
||||
return -1;
|
||||
}
|
||||
saved_arlit_count = stix->c->mth.arlit_count;
|
||||
x = __read_array_literal (stix, xlit);
|
||||
stix->c->mth.arlit_count = saved_arlit_count;
|
||||
stix->c->in_array = 0;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static int compile_array_literal (stix_t* stix)
|
||||
{
|
||||
stix_oop_t lit;
|
||||
stix_size_t index;
|
||||
int x;
|
||||
|
||||
stix->c->in_array = 1;
|
||||
GET_TOKEN (stix); /* skip #( and read the next token */
|
||||
x = __compile_array_literal (stix, &lit);
|
||||
stix->c->in_array = 0;
|
||||
if (x <= -1) return -1;
|
||||
STIX_ASSERT (stix->c->mth.arlit_count == 0);
|
||||
|
||||
printf ("\tpush_literal array\n");
|
||||
if (add_literal (stix, lit, &index) <= -1 ||
|
||||
if (read_array_literal(stix, &lit) <= -1 ||
|
||||
add_literal(stix, lit, &index) <= -1 ||
|
||||
emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1;
|
||||
printf ("\tpush_literal array\n");
|
||||
|
||||
GET_TOKEN (stix);
|
||||
return 0;
|
||||
@ -4256,7 +4293,7 @@ static int __compile_class_definition (stix_t* stix, int extend)
|
||||
stix->c->cls.fqn_loc = stix->c->tok.loc;
|
||||
if (stix->c->tok.type == STIX_IOTOK_IDENT_DOTTED)
|
||||
{
|
||||
if (preprocess_dotted_name(stix, extend, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1;
|
||||
if (preprocess_dotted_name(stix, extend, 0, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4298,7 +4335,7 @@ static int __compile_class_definition (stix_t* stix, int extend)
|
||||
{
|
||||
int super_is_nil = 0;
|
||||
|
||||
printf ("DEFININING..");
|
||||
printf ("DEFININING CLASS ");
|
||||
print_ucs (&stix->c->cls.name);
|
||||
printf ("\n");
|
||||
if (stix->c->tok.type == STIX_IOTOK_LPAREN)
|
||||
@ -4327,7 +4364,7 @@ printf ("\n");
|
||||
|
||||
if (stix->c->tok.type == STIX_IOTOK_IDENT_DOTTED)
|
||||
{
|
||||
if (preprocess_dotted_name(stix, 1, &stix->c->cls.superfqn, &stix->c->cls.superfqn_loc, &stix->c->cls.supername, &stix->c->cls.superns_oop) <= -1) return -1;
|
||||
if (preprocess_dotted_name(stix, 1, 0, &stix->c->cls.superfqn, &stix->c->cls.superfqn_loc, &stix->c->cls.supername, &stix->c->cls.superns_oop) <= -1) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4547,7 +4584,7 @@ static int __compile_pooldic_definition (stix_t* stix)
|
||||
|
||||
if (stix->c->tok.type == STIX_IOTOK_IDENT_DOTTED)
|
||||
{
|
||||
if (preprocess_dotted_name(stix, 0, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1;
|
||||
if (preprocess_dotted_name(stix, 0, 0, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4568,6 +4605,10 @@ static int __compile_pooldic_definition (stix_t* stix)
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf ("DEFININING POOL DICTIONARY ");
|
||||
print_ucs (&stix->c->cls.name);
|
||||
printf ("\n");
|
||||
|
||||
GET_TOKEN (stix);
|
||||
|
||||
while (stix->c->tok.type == STIX_IOTOK_SYMLIT)
|
||||
@ -4589,51 +4630,73 @@ static int __compile_pooldic_definition (stix_t* stix)
|
||||
{
|
||||
case STIX_IOTOK_NIL:
|
||||
lit = stix->_nil;
|
||||
goto simple_literal;
|
||||
goto add_literal;
|
||||
|
||||
case STIX_IOTOK_TRUE:
|
||||
lit = stix->_true;
|
||||
goto simple_literal;
|
||||
goto add_literal;
|
||||
|
||||
case STIX_IOTOK_FALSE:
|
||||
lit = stix->_false;
|
||||
goto simple_literal;
|
||||
|
||||
goto add_literal;
|
||||
|
||||
case STIX_IOTOK_CHARLIT:
|
||||
STIX_ASSERT (stix->c->tok.name.len == 1);
|
||||
lit = STIX_OOP_FROM_CHAR(stix->c->tok.name.ptr[0]);
|
||||
goto simple_literal;
|
||||
goto add_literal;
|
||||
|
||||
case STIX_IOTOK_STRLIT:
|
||||
lit = stix_instantiate (stix, stix->_string, stix->c->tok.name.ptr, stix->c->tok.name.len);
|
||||
if (!lit) return -1;
|
||||
goto simple_literal;
|
||||
goto add_literal;
|
||||
|
||||
case STIX_IOTOK_SYMLIT:
|
||||
lit = stix_makesymbol (stix, stix->c->tok.name.ptr, stix->c->tok.name.len);
|
||||
if (!lit) return -1;
|
||||
goto simple_literal;
|
||||
goto add_literal;
|
||||
|
||||
case STIX_IOTOK_NUMLIT:
|
||||
case STIX_IOTOK_RADNUMLIT:
|
||||
goto simple_literal;
|
||||
{
|
||||
stix_ooi_t tmp;
|
||||
|
||||
#if 0
|
||||
case STIX_IOTOK_BPAREN: /* byte array */
|
||||
case STIX_IOTOK_APAREN: /* array */
|
||||
if (string_to_smint(stix, &stix->c->tok.name, stix->c->tok.type == STIX_IOTOK_RADNUMLIT, &tmp) <= -1)
|
||||
{
|
||||
/* the token reader reads a valid token. no other errors
|
||||
* than the range error must not occur */
|
||||
STIX_ASSERT (stix->errnum == STIX_ERANGE);
|
||||
|
||||
printf ("NOT IMPLEMENTED LARGE_INTEGER or ERROR?\n");
|
||||
stix->errnum = STIX_ENOIMPL;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
lit = STIX_OOP_FROM_SMINT(tmp);
|
||||
}
|
||||
|
||||
goto add_literal;
|
||||
}
|
||||
|
||||
case STIX_IOTOK_BPAREN: /* #[ */
|
||||
if (read_byte_array_literal(stix, &lit) <= -1) return -1;
|
||||
goto add_literal;
|
||||
|
||||
case STIX_IOTOK_APAREN: /* #( */
|
||||
if (read_array_literal(stix, &lit) <= -1) return -1;
|
||||
goto add_literal;
|
||||
|
||||
add_literal:
|
||||
/*
|
||||
* for this definition, #pooldic MyPoolDic { #a := 10. #b := 20 },
|
||||
* arlit_buffer contains (#a 10 #b 20) when the 'while' loop is over. */
|
||||
if (add_to_arlit_buffer(stix, lit) <= -1) return -1;
|
||||
GET_TOKEN (stix);
|
||||
break;
|
||||
TODO:
|
||||
#endif
|
||||
|
||||
default:
|
||||
set_syntax_error (stix, STIX_SYNERR_LITERAL, &stix->c->tok.loc, &stix->c->tok.name);
|
||||
return -1;
|
||||
|
||||
simple_literal:
|
||||
if (add_to_arlit_buffer(stix, lit) <= -1) return -1;
|
||||
GET_TOKEN (stix);
|
||||
break;
|
||||
}
|
||||
|
||||
/*if (stix->c->tok.type == STIX_IOTOK_RBRACE) goto done;
|
||||
@ -4686,7 +4749,6 @@ static int compile_pooldic_definition (stix_t* stix)
|
||||
STIX_MEMSET (&stix->c->cls.fqn_loc, 0, STIX_SIZEOF(stix->c->cls.fqn_loc));
|
||||
stix->c->cls.mthdic_oop[0] = STIX_NULL;
|
||||
stix->c->cls.ns_oop = STIX_NULL;
|
||||
stix->c->mth.literal_count = 0;
|
||||
stix->c->mth.balit_count = 0;
|
||||
stix->c->mth.arlit_count = 0;
|
||||
|
||||
@ -4695,9 +4757,9 @@ static int compile_pooldic_definition (stix_t* stix)
|
||||
/* reset these oops plus literal pointers not to confuse gc_compiler() */
|
||||
stix->c->cls.mthdic_oop[0] = STIX_NULL;
|
||||
stix->c->cls.ns_oop = STIX_NULL;
|
||||
stix->c->mth.literal_count = 0;
|
||||
stix->c->mth.balit_count = 0;
|
||||
stix->c->mth.arlit_count = 0;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -4783,16 +4845,12 @@ static void gc_compiler (stix_t* stix)
|
||||
stix->c->cls.superns_oop = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->c->cls.superns_oop);
|
||||
|
||||
for (i = 0; i < stix->c->mth.literal_count; i++)
|
||||
{
|
||||
if (STIX_OOP_IS_POINTER(stix->c->mth.literals[i]))
|
||||
{
|
||||
stix->c->mth.literals[i] = stix_moveoop (stix, stix->c->mth.literals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < stix->c->mth.arlit_count; i++)
|
||||
{
|
||||
if (STIX_OOP_IS_POINTER(stix->c->mth.arlit[i]))
|
||||
stix->c->mth.arlit[i] = stix_moveoop (stix, stix->c->mth.arlit[i]);
|
||||
}
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ static void __dump_object (stix_t* stix, stix_oop_t oop, int depth)
|
||||
printf (" #["); /* TODO: different symbol for word array ?? */
|
||||
for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++)
|
||||
{
|
||||
printf (" %ld", ((stix_oop_word_t)oop)->slot[i]);
|
||||
printf (" %ld", (long int)((stix_oop_word_t)oop)->slot[i]);
|
||||
}
|
||||
printf ("]");
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc)
|
||||
return newbuc;
|
||||
}
|
||||
|
||||
static stix_oop_association_t find_or_insert (stix_t* stix, stix_oop_set_t dic, stix_oop_char_t key, stix_oop_t value)
|
||||
static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic, stix_oop_char_t key, stix_oop_t value)
|
||||
{
|
||||
stix_oow_t index, tally;
|
||||
stix_oop_association_t ass;
|
||||
@ -85,15 +85,18 @@ static stix_oop_association_t find_or_insert (stix_t* stix, stix_oop_set_t dic,
|
||||
if (STIX_OBJ_GET_SIZE(key) == STIX_OBJ_GET_SIZE(ass->key) &&
|
||||
stix_equalchars (key->slot, ((stix_oop_char_t)ass->key)->slot, STIX_OBJ_GET_SIZE(key)))
|
||||
{
|
||||
/* the value of STIX_NULL indicates no insertion or update. */
|
||||
if (value) ass->value = value;
|
||||
return ass;
|
||||
}
|
||||
|
||||
index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket);
|
||||
}
|
||||
|
||||
if (value == STIX_NULL)
|
||||
if (!value)
|
||||
{
|
||||
/* when value is STIX_NULL, perform no insertion */
|
||||
/* when value is STIX_NULL, perform no insertion.
|
||||
* the value of STIX_NULL indicates no insertion or update. */
|
||||
stix->errnum = STIX_ENOENT;
|
||||
return STIX_NULL;
|
||||
}
|
||||
@ -184,13 +187,13 @@ static stix_oop_association_t lookup (stix_t* stix, stix_oop_set_t dic, const st
|
||||
stix_oop_association_t stix_putatsysdic (stix_t* stix, stix_oop_t key, stix_oop_t value)
|
||||
{
|
||||
STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol);
|
||||
return find_or_insert (stix, stix->sysdic, (stix_oop_char_t)key, value);
|
||||
return find_or_upsert (stix, stix->sysdic, (stix_oop_char_t)key, value);
|
||||
}
|
||||
|
||||
stix_oop_association_t stix_getatsysdic (stix_t* stix, stix_oop_t key)
|
||||
{
|
||||
STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol);
|
||||
return find_or_insert (stix, stix->sysdic, (stix_oop_char_t)key, STIX_NULL);
|
||||
return find_or_upsert (stix, stix->sysdic, (stix_oop_char_t)key, STIX_NULL);
|
||||
}
|
||||
|
||||
stix_oop_association_t stix_lookupsysdic (stix_t* stix, const stix_ucs_t* name)
|
||||
@ -201,13 +204,13 @@ stix_oop_association_t stix_lookupsysdic (stix_t* stix, const stix_ucs_t* name)
|
||||
stix_oop_association_t stix_putatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key, stix_oop_t value)
|
||||
{
|
||||
STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol);
|
||||
return find_or_insert (stix, dic, (stix_oop_char_t)key, value);
|
||||
return find_or_upsert (stix, dic, (stix_oop_char_t)key, value);
|
||||
}
|
||||
|
||||
stix_oop_association_t stix_getatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key)
|
||||
{
|
||||
STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol);
|
||||
return find_or_insert (stix, dic, (stix_oop_char_t)key, STIX_NULL);
|
||||
return find_or_upsert (stix, dic, (stix_oop_char_t)key, STIX_NULL);
|
||||
}
|
||||
|
||||
stix_oop_association_t stix_lookupdic (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* name)
|
||||
|
@ -89,8 +89,7 @@ stix_oop_t stix_moveoop (stix_t* stix, stix_oop_t oop)
|
||||
if (!oop) return oop;
|
||||
#endif
|
||||
|
||||
STIX_ASSERT (STIX_OOP_IS_POINTER(oop));
|
||||
/*if (STIX_OOP_IS_POINTER(oop)) return oop;*/
|
||||
if (!STIX_OOP_IS_POINTER(oop)) return oop;
|
||||
|
||||
if (STIX_OBJ_GET_FLAGS_MOVED(oop))
|
||||
{
|
||||
|
@ -31,6 +31,9 @@ stix_t* stix_open (stix_mmgr_t* mmgr, stix_size_t xtnsize, stix_size_t heapsize,
|
||||
{
|
||||
stix_t* stix;
|
||||
|
||||
/* if this assertion fails, correct the type definition in stix.h */
|
||||
STIX_ASSERT (STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_oop_t));
|
||||
|
||||
stix = STIX_MMGR_ALLOC (mmgr, STIX_SIZEOF(*stix) + xtnsize);
|
||||
if (stix)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user