added some vm code

This commit is contained in:
hyunghwan.chung 2015-06-04 18:34:37 +00:00
parent 3added1316
commit 7a751d7cc0
9 changed files with 359 additions and 67 deletions

View File

@ -2407,7 +2407,7 @@ static int add_compiled_method (stix_t* stix)
for (i = 0; i < stix->c->mth.literal_count; i++)
{
/* let's do the variadic data initialization here */
mth->literal[i] = stix->c->mth.literals[i];
mth->slot[i] = stix->c->mth.literals[i];
}
stix_pushtmp (stix, (stix_oop_t*)&mth); tmp_count++;
@ -2513,7 +2513,9 @@ static int make_defined_class (stix_t* stix)
spec = STIX_CLASS_SPEC_MAKE (stix->c->cls.var_count[VAR_INSTANCE],
((stix->c->cls.flags & CLASS_INDEXED)? 1: 0),
stix->c->cls.indexed_type);
self_spec = STIX_CLASS_SELFSPEC_MAKE(stix->c->cls.var_count[VAR_CLASS], stix->c->cls.var_count[VAR_CLASSINST]);
self_spec = STIX_CLASS_SELFSPEC_MAKE (stix->c->cls.var_count[VAR_CLASS],
stix->c->cls.var_count[VAR_CLASSINST]);
#if 0
printf ("MAKING ... ");
@ -2581,12 +2583,12 @@ printf (" CONFLICTING CLASS DEFINITION %lu %lu %lu %lu\n",
stix->c->cls.self_oop->classinstvars = (stix_oop_char_t)tmp;
/* TOOD: good dictionary size */
tmp = stix_makedic (stix, stix->_method_dictionary, INSTANCE_METHOD_DICTIONARY_SIZE);
tmp = (stix_oop_t)stix_makedic (stix, stix->_method_dictionary, INSTANCE_METHOD_DICTIONARY_SIZE);
if (!tmp) return -1;
stix->c->cls.mthdic_oop[MTH_INSTANCE] = (stix_oop_set_t)tmp;
/* TOOD: good dictionary size */
tmp = stix_makedic (stix, stix->_method_dictionary, CLASS_METHOD_DICTIONARY_SIZE);
tmp = (stix_oop_t)stix_makedic (stix, stix->_method_dictionary, CLASS_METHOD_DICTIONARY_SIZE);
if (!tmp) return -1;
stix->c->cls.mthdic_oop[MTH_CLASS] = (stix_oop_set_t)tmp;
@ -2720,7 +2722,7 @@ printf ("\n");
GET_TOKEN (stix);
ass = (stix_oop_association_t)stix_lookupsysdic(stix, &stix->c->cls.name);
ass = stix_lookupsysdic(stix, &stix->c->cls.name);
if (ass)
{
if (STIX_CLASSOF(stix, ass->value) != stix->_class ||
@ -2748,7 +2750,7 @@ printf ("\n");
}
else
{
ass = (stix_oop_association_t)stix_lookupsysdic(stix, &stix->c->cls.supername);
ass = stix_lookupsysdic(stix, &stix->c->cls.supername);
if (ass &&
STIX_CLASSOF(stix, ass->value) == stix->_class &&
STIX_OBJ_GET_FLAGS_KERNEL(ass->value) != 1)
@ -2783,7 +2785,7 @@ printf ("\n");
stix->c->cls.flags |= CLASS_EXTENDED;
ass = (stix_oop_association_t)stix_lookupsysdic(stix, &stix->c->cls.name);
ass = stix_lookupsysdic(stix, &stix->c->cls.name);
if (ass &&
STIX_CLASSOF(stix, ass->value) != stix->_class &&
STIX_OBJ_GET_FLAGS_KERNEL(ass->value) != 1)

View File

@ -61,13 +61,12 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc)
return newbuc;
}
static stix_oop_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_insert (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;
stix_oow_t tmp_count = 0;
/* the system dictionary is not a generic dictionary.
* it accepts only a symbol as a key. */
STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol);
@ -86,7 +85,7 @@ static stix_oop_t find_or_insert (stix_t* stix, stix_oop_set_t dic, stix_oop_cha
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)))
{
return (stix_oop_t)ass;
return ass;
}
index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket);
@ -136,18 +135,19 @@ static stix_oop_t find_or_insert (stix_t* stix, stix_oop_set_t dic, stix_oop_cha
ass->key = (stix_oop_t)key;
ass->value = value;
STIX_ASSERT (tally < STIX_SMINT_MAX);
dic->tally = STIX_OOP_FROM_SMINT(tally + 1);
dic->bucket->slot[index] = (stix_oop_t)ass;
stix_poptmps (stix, tmp_count);
return (stix_oop_t)ass;
return ass;
oops:
stix_poptmps (stix, tmp_count);
return STIX_NULL;
}
static stix_oop_t lookup (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* name)
static stix_oop_association_t lookup (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* name)
{
/* this is special version of stix_getatsysdic() that performs
* lookup using a plain string specified */
@ -170,7 +170,7 @@ static stix_oop_t lookup (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* na
if (name->len == STIX_OBJ_GET_SIZE(ass->key) &&
stix_equalchars(name->ptr, ((stix_oop_char_t)ass->key)->slot, name->len))
{
return (stix_oop_t)ass;
return ass;
}
index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket);
@ -181,41 +181,41 @@ static stix_oop_t lookup (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* na
return STIX_NULL;
}
stix_oop_t stix_putatsysdic (stix_t* stix, stix_oop_t key, stix_oop_t value)
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);
}
stix_oop_t stix_getatsysdic (stix_t* stix, stix_oop_t key)
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);
}
stix_oop_t stix_lookupsysdic (stix_t* stix, const stix_ucs_t* name)
stix_oop_association_t stix_lookupsysdic (stix_t* stix, const stix_ucs_t* name)
{
return lookup (stix, stix->sysdic, name);
}
stix_oop_t stix_putatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key, stix_oop_t value)
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);
}
stix_oop_t stix_getatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key)
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);
}
stix_oop_t stix_lookupdic (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* name)
stix_oop_association_t stix_lookupdic (stix_t* stix, stix_oop_set_t dic, const stix_ucs_t* name)
{
return lookup (stix, dic, name);
}
stix_oop_t stix_makedic (stix_t* stix, stix_oop_t cls, stix_oow_t size)
stix_oop_set_t stix_makedic (stix_t* stix, stix_oop_t cls, stix_oow_t size)
{
stix_oop_set_t dic;
stix_oop_t tmp;
@ -238,5 +238,5 @@ stix_oop_t stix_makedic (stix_t* stix, stix_oop_t cls, stix_oow_t size)
STIX_ASSERT (STIX_OBJ_GET_SIZE(dic) == STIX_SET_NAMED_INSTVARS);
STIX_ASSERT (STIX_OBJ_GET_SIZE(dic->bucket) == size);
return (stix_oop_t)dic;
return dic;
}

176
stix/lib/exec.c Normal file
View File

@ -0,0 +1,176 @@
/*
* $Id$
*
Copyright (c) 2014-2015 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAfRRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "stix-prv.h"
static int activate_new_method (stix_t* stix, stix_oop_method_t mth)
{
stix_oow_t stack_size;
stix_oop_context_t ctx;
stix_ooi_t i, j;
stix_ooi_t sp, ntmprs, nargs;
stack_size = 256; /* TODO: make the stack size configurable or let the compiler choose the rightr value and store it in the compiled method. if it's stored in the compiled method, the code here can take it*/
stix_pushtmp (stix, (stix_oop_t*)&mth);
ctx = (stix_oop_context_t)stix_instantiate (stix, stix->_context, STIX_NULL, stack_size);
stix_poptmp (stix);
if (!ctx) return -1;
/* message sending requires a receiver to be pushed.
* the stack pointer of the sending context cannot be -1 */
sp = STIX_OOP_TO_SMINT (stix->active_context->sp);
STIX_ASSERT (sp >= 0);
ntmprs = STIX_OOP_TO_SMINT (mth->tmpr_count);
STIX_ASSERT (ntmprs >= 0);
nargs = STIX_OOP_TO_SMINT (mth->tmpr_nargs);
STIX_ASSERT (nargs <= ntmprs);
STIX_ASSERT (sp >= ntmprs + 1);
ctx->sender = (stix_oop_t)stix->active_context;
ctx->ip = 0;
/* the stack front has temporary variables including arguments */
ctx->sp = STIX_OOP_FROM_SMINT(ntmprs - 1);
ctx->method = mth;
/*
* This message sending expression is compiled to
* obj1 do: #this with: #that with: #it
*
* the logical byte-code sequences shown below:
* push obj1
* push #this
* push #that
* push #it
* send #do:with:
*
* After three pushes, the stack looks like this.
*
* | #it | <- sp
* | #that | sp - 1
* | #this | sp - 2
* | obj1 | sp - nargs
*
* Since the number of arguments is 3, stack[sp - 3] points to
* the receiver. When the stack is empty, sp is -1.
*/
j = sp - nargs;
ctx->receiver = stix->active_context->slot[j++];
for (i = 0; i < nargs; i++)
{
/* copy an argument */
ctx->slot[i] = stix->active_context->slot[++j];
}
STIX_ASSERT (j == sp);
/* TODO: store the contennts of internal registers to stix->active_context */
stix->active_context = ctx;
/* TODO: copy the contens of ctx to internal registers */
return 0;
}
static stix_oop_method_t find_method (stix_t* stix, stix_oop_t obj, const stix_ucs_t* mthname)
{
stix_oop_class_t cls;
cls = (stix_oop_class_t)STIX_CLASSOF(stix, obj);
if (cls == stix->_class)
{
}
else
{
}
stix->errnum = STIX_ENOENT;
return STIX_NULL;
}
static int activate_initial_context (stix_t* stix, const stix_ucs_t* objname, const stix_ucs_t* mthname)
{
/* the initial context is a fake context */
stix_oow_t stack_size;
stix_oop_context_t ctx;
stix_oop_association_t ass;
stix_oop_method_t mth;
stack_size = 1; /* grow it if you want to pass arguments */
ctx = (stix_oop_context_t)stix_instantiate (stix, stix->_context, STIX_NULL, stack_size);
if (!ctx) return -1;
ass = stix_lookupsysdic (stix, objname);
if (!ass) return -1;
mth = find_method (stix, ass->value, mthname);
if (!mth) return -1;
ctx->slot[0] = ass->value;
ctx->sp = STIX_OOP_FROM_SMINT(1);
stix->active_context = ctx;
return activate_new_method (stix, mth);
}
#if 0
static stix_oop_process_t make_process (stix_t* stix, stix_oop_context_t ctx)
{
stix_oop_process_t proc;
stix_pushtmp (stix, (stix_oop_t*)&ctx);
proc = (stix_oop_process_t)stix_instantiate (stix, stix->_process, STIX_NULL, 0);
stix_poptmp (stix);
if (!proc) return STIX_NULL;
proc->context = ctx;
return proc;
}
#endif
int stix_execute (stix_t* stix)
{
while (1)
{
}
return 0;
}
int stix_invoke (stix_t* stix, const stix_ucs_t* objname, const stix_ucs_t* mthname)
{
if (activate_initial_context (stix, objname, mthname) <= -1) return -1;
return stix_execute (stix);
}

View File

@ -86,6 +86,7 @@ wprintf (L">> DISPOSING %d [%S] from the symbol table\n", (int)index, sym->slot)
tally--;
}
STIX_ASSERT (tally <= STIX_SMINT_MAX);
stix->symtab->tally = STIX_OOP_FROM_SMINT(tally);
}
@ -214,6 +215,9 @@ void stix_gc (stix_t* stix)
stix->_method_dictionary = stix_moveoop (stix, stix->_method_dictionary);
stix->_method = stix_moveoop (stix, stix->_method);
stix->_association = stix_moveoop (stix, stix->_association);
stix->_context = stix_moveoop (stix, stix->_context);
stix->_block_context = stix_moveoop (stix, stix->_block_context);
/*stix->_process = stix_moveoop (stix, stix->_process);*/
stix->_true_class = stix_moveoop (stix, stix->_true_class);
stix->_false_class = stix_moveoop (stix, stix->_false_class);
stix->_character = stix_moveoop (stix, stix->_character);

View File

@ -127,21 +127,27 @@ static int ignite_1 (stix_t* stix)
stix->_method_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP));
stix->_method = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_METHOD_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP));
stix->_association = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_ASSOCIATION_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP));
stix->_context = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_CONTEXT_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP));
stix->_block_context = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_BLOCK_CONTEXT_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP));
/*stix->_process = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_PROCESS_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP));*/
stix->_true_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP));
stix->_false_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP));
/* TOOD: what is a proper spec for Character and SmallInteger?
* If the fixed part is 0, its instance must be an object of 0 payload fields.
* Does this make sense? */
stix->_character = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP));
stix->_small_integer = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP));
if (!stix->_stix || !stix->_nil_object || !stix->_object ||
!stix->_array || !stix->_byte_array ||
!stix->_string || !stix->_symbol ||
!stix->_symbol_set || !stix->_system_dictionary || !stix->_method_dictionary ||
!stix->_association || !stix->_true_class || !stix->_false_class ||
if (!stix->_stix || !stix->_nil_object ||
!stix->_object || !stix->_array ||
!stix->_byte_array || !stix->_string ||
!stix->_symbol || !stix->_symbol_set ||
!stix->_system_dictionary || !stix->_method_dictionary ||
!stix->_association || !stix->_context ||
!stix->_block_context || /*!stix->_process ||*/
!stix->_true_class || !stix->_false_class ||
!stix->_character || !stix->_small_integer) return -1;
STIX_OBJ_SET_CLASS (stix->_nil, stix->_nil_object);
return 0;
}
@ -171,7 +177,7 @@ static int ignite_2 (stix_t* stix)
stix->symtab->bucket = (stix_oop_oop_t)tmp;
/* Create the system dictionary */
tmp = stix_makedic (stix, stix->_system_dictionary, stix->option.dfl_sysdic_size);
tmp = (stix_oop_t)stix_makedic (stix, stix->_system_dictionary, stix->option.dfl_sysdic_size);
if (!tmp) return -1;
stix->sysdic = (stix_oop_set_t)tmp;
@ -195,14 +201,20 @@ static int ignite_3 (stix_t* stix)
{ 5, { 'C','l','a','s','s' } },
{ 6, { 'O','b','j','e','c','t' } },
{ 6, { 'S','t','r','i','n','g' } },
{ 6, { 'S','y','m','b','o','l' } },
{ 5, { 'A','r','r','a','y' } },
{ 9, { 'B','y','t','e','A','r','r','a','y' } },
{ 9, { 'S','y','m','b','o','l','S','e','t' } },
{ 16, { 'S','y','s','t','e','m','D','i','c','t','i','o','n','a','r','y' } },
{ 16, { 'M','e','t','h','o','d','D','i','c','t','i','o','n','a','r','y' } },
{ 14, { 'C','o','m','p','i','l','e','d','M','e','t','h','o','d' } },
{ 11, { 'A','s','s','o','c','i','a','t','i','o','n' } },
{ 13, { 'M','e','t','h','o','d','C','o','n','t','e','x','t' } },
{ 12, { 'B','l','o','c','k','C','o','n','t','e','x','t' } },
/*{ 7, { 'P','r','o','c','e','s','s' } },*/
{ 4, { 'T','r','u','e' } },
{ 5, { 'F','a','l','s','e' } },
{ 9, { 'C','h','a','r','a','c','t','e','r' } },

View File

@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
typedef struct xtn_t xtn_t;
struct xtn_t
{
@ -262,6 +263,17 @@ int main (int argc, char* argv[])
(unsigned long int)STIX_MAX_CLASSVARS,
(unsigned long int)STIX_MAX_CLASSINSTVARS);
{
stix_oop_t k;
k = STIX_OOP_FROM_SMINT(-1);
printf ("%ld %ld %ld %lX\n", (long int)STIX_OOP_TO_SMINT(k), (long int)STIX_SMINT_MIN, (long int)STIX_SMINT_MAX, (long)LONG_MIN);
k = STIX_OOP_FROM_SMINT(STIX_SMINT_MAX);
printf ("%ld\n", (long int)STIX_OOP_TO_SMINT(k));
k = STIX_OOP_FROM_SMINT(STIX_SMINT_MIN);
printf ("%ld\n", (long int)STIX_OOP_TO_SMINT(k));
}
#if !defined(macintosh)
if (argc != 2)
@ -387,8 +399,18 @@ printf ("%p\n", a);
return -1;
}
/*
if (stix_execute (stix) <= -1)
{
printf ("ERROR: cannot execute code - %d\n", stix_geterrnum(stix));
stix_close (stix);
return -1;
}
*/
dump_system_dictionary(stix);
stix_close (stix);
return 0;
}

View File

@ -104,13 +104,14 @@
((((stix_oow_t)(spec)) >> 1) & STIX_LBMASK(stix_oow_t, STIX_OBJ_FLAGS_TYPE_BITS))
/* What is the maximum number of named instance variables?
* 2 ^ ((BITS-IN-OOW - STIX_OOP_TAG_BITS) - STIX_OBJ_TYPE_BITS - 1) - 1
* This limit is set because the number must be encoded into the spec field
* This limit is set so because the number must be encoded into the spec field
* of the class with limited number of bits assigned to the number of
* named instance variables.
* named instance variables. the trailing -1 in the calculation of number of
* bits is to consider the signness of a small-integer which is a typical
* type of the spec field in the class object.
*/
#define STIX_MAX_NAMED_INSTVARS \
STIX_BITS_MAX(stix_oow_t, STIX_OOW_BITS - STIX_OOP_TAG_BITS - (STIX_OBJ_FLAGS_TYPE_BITS + 1))
STIX_BITS_MAX(stix_oow_t, STIX_OOW_BITS - STIX_OOP_TAG_BITS - (STIX_OBJ_FLAGS_TYPE_BITS + 1) - 1)
/* Given the number of named instance variables, what is the maximum number
* of indexed instance variables? The number of indexed instance variables
@ -128,8 +129,12 @@
#define STIX_CLASS_SELFSPEC_CLASSVAR(spec) ((stix_oow_t)spec >> ((STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2))
#define STIX_CLASS_SELFSPEC_CLASSINSTVAR(spec) (((stix_oow_t)spec) & STIX_LBMASK(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2))
#define STIX_MAX_CLASSVARS STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2)
#define STIX_MAX_CLASSINSTVARS STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2)
/*
* yet another -1 in the calculation of the bit numbers for signed nature of
* a small-integer
*/
#define STIX_MAX_CLASSVARS STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS - 1) / 2)
#define STIX_MAX_CLASSINSTVARS STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS - 1) / 2)
#if defined(STIX_INCLUDE_COMPILER)
@ -563,42 +568,42 @@ stix_oop_t stix_makestring (
/* ========================================================================= */
/* dic.c */
/* ========================================================================= */
stix_oop_t stix_putatsysdic (
stix_oop_association_t stix_putatsysdic (
stix_t* stix,
stix_oop_t key,
stix_oop_t value
);
stix_oop_t stix_getatsysdic (
stix_oop_association_t stix_getatsysdic (
stix_t* stix,
stix_oop_t key
);
stix_oop_t stix_lookupsysdic (
stix_oop_association_t stix_lookupsysdic (
stix_t* stix,
const stix_ucs_t* name
);
stix_oop_t stix_putatdic (
stix_oop_association_t stix_putatdic (
stix_t* stix,
stix_oop_set_t dic,
stix_oop_t key,
stix_oop_t value
);
stix_oop_t stix_getatdic (
stix_oop_association_t stix_getatdic (
stix_t* stix,
stix_oop_set_t dic,
stix_oop_t key
);
stix_oop_t stix_lookupdic (
stix_oop_association_t stix_lookupdic (
stix_t* stix,
stix_oop_set_t dic,
const stix_ucs_t* name
);
stix_oop_t stix_makedic (
stix_oop_set_t stix_makedic (
stix_t* stix,
stix_oop_t cls,
stix_oow_t size

View File

@ -50,6 +50,7 @@ typedef signed short int stix_int16_t;
#endif
typedef unsigned long int stix_uintptr_t;
typedef signed long int stix_intptr_t;
typedef unsigned long int stix_size_t;
typedef signed long int stix_ssize_t;
@ -306,6 +307,7 @@ typedef enum stix_trait_t stix_trait_t;
/* NOTE: sizeof(stix_oop_t) must be equal to sizeof(stix_oow_t) */
typedef stix_uintptr_t stix_oow_t;
typedef stix_intptr_t stix_ooi_t;
typedef struct stix_obj_t stix_obj_t;
typedef struct stix_obj_t* stix_oop_t;
@ -348,13 +350,24 @@ typedef struct stix_obj_word_t* stix_oop_word_t;
#define STIX_OOP_IS_POINTER(oop) (!STIX_OOP_IS_NUMERIC(oop))
#define STIX_OOP_GET_TAG(oop) (((stix_oow_t)oop) & STIX_LBMASK(stix_oow_t, STIX_OOP_TAG_BITS))
#define STIX_OOP_IS_SMINT(oop) (((stix_oow_t)oop) & STIX_OOP_TAG_SMINT)
#define STIX_OOP_IS_SMINT(oop) (((stix_ooi_t)oop) & STIX_OOP_TAG_SMINT)
#define STIX_OOP_IS_CHAR(oop) (((stix_oow_t)oop) & STIX_OOP_TAG_CHAR)
#define STIX_OOP_FROM_SMINT(num) ((stix_oop_t)((((stix_oow_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_SMINT))
#define STIX_OOP_TO_SMINT(oop) (((stix_oow_t)oop) >> STIX_OOP_TAG_BITS)
#define STIX_OOP_FROM_SMINT(num) ((stix_oop_t)((((stix_ooi_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_SMINT))
#define STIX_OOP_TO_SMINT(oop) (((stix_ooi_t)oop) >> STIX_OOP_TAG_BITS)
#define STIX_OOP_FROM_CHAR(num) ((stix_oop_t)((((stix_oow_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_CHAR))
#define STIX_OOP_TO_CHAR(oop) (((stix_oow_t)oop) >> STIX_OOP_TAG_BITS)
#define STIX_SMINT_BITS (STIX_SIZEOF(stix_ooi_t) * 8 - STIX_OOP_TAG_BITS)
#define STIX_SMINT_MAX ((stix_ooi_t)(~((stix_oow_t)0) >> (STIX_OOP_TAG_BITS + 1)))
#define STIX_SMINT_MIN (-STIX_SMINT_MAX - 1)
#define STIX_OOI_IN_SMINT_RANGE(ooi) ((ooi) >= STIX_SMINT_MIN && (ooi) <= STIX_SMINT_MAX)
/* TODO: There are untested code where smint is converted to stix_oow_t.
* for example, the spec making macro treats the number as stix_oow_t instead of stix_ooi_t.
* as of this writing, i skip testing that part with the spec value exceeding STIX_SMINT_MAX.
* later, please verify it works, probably by limiting the value ranges in such macros
*/
/*
* Object structure
*/
@ -491,16 +504,18 @@ struct stix_obj_word_t
};
#define STIX_SET_NAMED_INSTVARS 2
typedef struct stix_set_t stix_set_t;
typedef struct stix_set_t* stix_oop_set_t;
struct stix_set_t
{
STIX_OBJ_HEADER;
stix_oop_t tally; /* SmallInteger */
stix_oop_oop_t bucket; /* Array */
};
typedef struct stix_set_t stix_set_t;
typedef struct stix_set_t* stix_oop_set_t;
#define STIX_CLASS_NAMED_INSTVARS 10
typedef struct stix_class_t stix_class_t;
typedef struct stix_class_t* stix_oop_class_t;
struct stix_class_t
{
STIX_OBJ_HEADER;
@ -525,20 +540,20 @@ struct stix_class_t
/* indexed part afterwards */
stix_oop_t slot[1]; /* class instance variables and class variables. */
};
typedef struct stix_class_t stix_class_t;
typedef struct stix_class_t* stix_oop_class_t;
#define STIX_ASSOCIATION_NAMED_INSTVARS 2
typedef struct stix_association_t stix_association_t;
typedef struct stix_association_t* stix_oop_association_t;
struct stix_association_t
{
STIX_OBJ_HEADER;
stix_oop_t key;
stix_oop_t value;
};
typedef struct stix_association_t stix_association_t;
typedef struct stix_association_t* stix_oop_association_t;
#define STIX_METHOD_NAMED_INSTVARS 5
typedef struct stix_method_t stix_method_t;
typedef struct stix_method_t* stix_oop_method_t;
struct stix_method_t
{
STIX_OBJ_HEADER;
@ -554,10 +569,60 @@ struct stix_method_t
stix_oop_t source; /* TODO: what should I put? */
/* variable indexed part */
stix_oop_t literal[1];
stix_oop_t slot[1]; /* it stores literals */
};
typedef struct stix_method_t stix_method_t;
typedef struct stix_method_t* stix_oop_method_t;
#define STIX_CONTEXT_NAMED_INSTVARS 6
typedef struct stix_context_t stix_context_t;
typedef struct stix_context_t* stix_oop_context_t;
struct stix_context_t
{
STIX_OBJ_HEADER;
stix_oop_t sender;
stix_oop_t ip; /* instruction pointer */
stix_oop_t sp; /* stack pointer */
stix_oop_method_t method; /* CompiledMethod */
stix_oop_t unused;
stix_oop_t receiver;
/* variable indexed part */
stix_oop_t slot[1]; /* stack contents */
};
#define STIX_BLOCK_CONTEXT_NAMED_INSTVARS 6
typedef struct stix_block_context_t stix_block_context_t;
typedef struct stix_block_context_t* stix_oop_block_context_t;
struct stix_block_context_t
{
STIX_OBJ_HEADER;
stix_oop_t caller;
stix_oop_t ip; /* SmallInteger. instruction pointer */
stix_oop_t sp; /* SmallInteger. stack pointer */
stix_oop_t nargs; /* SmallInteger */
stix_oop_t iip; /* SmallInteger. initial instruction pointer */
stix_oop_context_t home;
/* variable indexed part */
stix_oop_t slot[1]; /* stack */
};
#if 0
#define STIX_PROCESS_NAMED_INSTVARS 4
typedef struct stix_process_t stix_process_t;
typedef struct stix_process_t* stix_oop_process_t;
struct stix_process_t
{
STIX_OBJ_HEADER;
stix_oop_context_t context;
stix_oop_t state; /* SmallInteger */
stix_oop_process_t prev;
stix_oop_process_t next;
};
#endif
/**
* The STIX_CLASSOF() macro return the class of an object including a numeric
@ -644,6 +709,9 @@ struct stix_t
stix_oop_t _method_dictionary; /* MethodDictionary */
stix_oop_t _method; /* CompiledMethod */
stix_oop_t _association; /* Association */
stix_oop_t _context; /* MethodContext */
stix_oop_t _block_context; /* BlockContext */
/*stix_oop_t _process; */ /* Process */
stix_oop_t _true_class; /* True */
stix_oop_t _false_class; /* False */
stix_oop_t _character; /* Character */
@ -656,6 +724,15 @@ struct stix_t
stix_oop_t* tmp_stack[256]; /* stack for temporaries */
stix_oow_t tmp_count;
/* == EXECUTION REGISTERS == */
stix_oop_context_t active_context; /* TODO: this could be either MethodContext or BlockContext. Some redefintion of stix_oop_context_t might be needed after having removed stix-oop_block-context. */
stix_oop_context_t home_context;
stix_oop_t method;
stix_oop_t receiver;
stix_oop_t ip; /* SmallInteger */
stix_oop_t sp; /* SmallInteger */
/* == END EXECUTION REGISTERS == */
#if defined(STIX_INCLUDE_COMPILER)
stix_compiler_t* c;
#endif
@ -749,20 +826,6 @@ STIX_EXPORT void stix_gc (
stix_t* stix
);
/**
* The stix_findclass() function searchs the root system dictionary
* for a class named \a name. The class object pointer is set to the
* memory location pointed to by \a oop.
*
* \return 0 if found, -1 if not found.
*/
STIX_EXPORT int stix_findclass (
stix_t* vm,
const stix_uch_t* name,
stix_oop_t* oop
);
/**
* The stix_instantiate() function creates a new object of the class
* \a _class. The size of the fixed part is taken from the information
@ -787,6 +850,13 @@ STIX_EXPORT int stix_ignite (
);
/**
* The stix_executes() function creates key initial objects.
*/
STIX_EXPORT int stix_execute (
stix_t* stix
);
/* Temporary OOP management */
STIX_EXPORT void stix_pushtmp (
stix_t* stix,

View File

@ -124,6 +124,7 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_uch_t* ptr, stix
symbol = (stix_oop_char_t)stix_instantiate(stix, stix->_symbol, ptr, len);
if (symbol)
{
STIX_ASSERT (tally < STIX_SMINT_MAX);
stix->symtab->tally = STIX_OOP_FROM_SMINT(tally + 1);
stix->symtab->bucket->slot[index] = (stix_oop_t)symbol;
}