gave up the idea of constants.

enhanced namespace handling with selfns and self
uniformified identifier handling related to namespacing
This commit is contained in:
hyunghwan.chung 2017-06-01 15:42:05 +00:00
parent 36c48a8daf
commit 34a5e0cab8
7 changed files with 428 additions and 433 deletions

View File

@ -6,7 +6,7 @@ class(#pointer,#limited) Class(Apex)
{
var spec, selfspec, superclass, subclasses, name, modname.
var instvars, classinstvars, classvars, pooldics.
var instmthdic, classmthdic, nsup, nsdic, cdic.
var instmthdic, classmthdic, nsup, nsdic.
var trsize, initv, initv_ci.
method(#class) initialize { ^self }

View File

@ -217,13 +217,13 @@ extend MethodContext
method isExceptionContext
{
## 12 - MOO_METHOD_PREAMBLE_EXCEPTION in VM.
^self.method preambleCode == 12.
^self.method preambleCode == 13.
}
method isEnsureContext
{
## 13 - MOO_METHOD_PREAMBLE_ENSURE in VM.
^self.method preambleCode == 13
^self.method preambleCode == 14
}
method ensureBlock
@ -236,7 +236,7 @@ extend MethodContext
* instance variables of the method context. As MethodContex has
* 8 instance variables, the ensure block must be at the 9th position
* which translates to index 8 *)
^if (self.method preambleCode == 13) { self basicAt: 8 } else { nil }
^if (self.method preambleCode == 14) { self basicAt: 8 } else { nil }
}

File diff suppressed because it is too large Load Diff

View File

@ -463,6 +463,10 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn)
LOG_INST_0 (moo, "push_process");
break;
case BCODE_PUSH_RECEIVER_NS:
LOG_INST_0 (moo, "push_receiver_ns");
break;
case BCODE_PUSH_NEGONE:
LOG_INST_0 (moo, "push_negone");
break;
@ -479,6 +483,7 @@ int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn)
LOG_INST_0 (moo, "push_two");
break;
case BCODE_PUSH_INTLIT:
FETCH_PARAM_CODE_TO (moo, b1);
LOG_INST_1 (moo, "push_intlit %zu", b1);

View File

@ -3944,6 +3944,18 @@ static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs)
MOO_STACK_SETTOP (moo, (moo_oop_t)moo->processor->active);
break;
case MOO_METHOD_PREAMBLE_RETURN_RECEIVER_NS:
{
moo_oop_t c;
LOG_INST_0 (moo, "preamble_return_receiver_ns");
MOO_STACK_POPS (moo, nargs); /* pop arguments only*/
c = MOO_STACK_GETTOP (moo); /* get receiver */
c = (moo_oop_t)MOO_CLASSOF(moo, c);
if (c == (moo_oop_t)moo->_class) c = MOO_STACK_GETTOP (moo);
MOO_STACK_SETTOP (moo, (moo_oop_t)((moo_oop_class_t)c)->nsup);
break;
}
case MOO_METHOD_PREAMBLE_RETURN_NIL:
LOG_INST_0 (moo, "preamble_return_nil");
MOO_STACK_POPS (moo, nargs);
@ -5030,6 +5042,16 @@ int moo_execute (moo_t* moo)
MOO_STACK_PUSH (moo, (moo_oop_t)moo->processor->active);
break;
case BCODE_PUSH_RECEIVER_NS:
{
register moo_oop_t c;
LOG_INST_0 (moo, "push_receiver_ns");
c = (moo_oop_t)MOO_CLASSOF(moo, moo->active_context->origin->receiver_or_source);
if (c == (moo_oop_t)moo->_class) c = moo->active_context->origin->receiver_or_source;
MOO_STACK_PUSH (moo, (moo_oop_t)((moo_oop_class_t)c)->nsup);
break;
}
case BCODE_PUSH_NEGONE:
LOG_INST_0 (moo, "push_negone");
MOO_STACK_PUSH (moo, MOO_SMOOI_TO_OOP(-1));

View File

@ -320,6 +320,7 @@ struct moo_iotok_t
MOO_IOTOK_NUMLIT,
MOO_IOTOK_RADNUMLIT,
MOO_IOTOK_ERRLIT, /* error(NN) */
MOO_IOTOK_ERROR, /* error */
MOO_IOTOK_NIL,
MOO_IOTOK_SELF,
@ -328,13 +329,25 @@ struct moo_iotok_t
MOO_IOTOK_FALSE,
MOO_IOTOK_THIS_CONTEXT,
MOO_IOTOK_THIS_PROCESS,
MOO_IOTOK_SELFNS,
MOO_IOTOK_IF,
MOO_IOTOK_ELSE,
MOO_IOTOK_ELSIF,
MOO_IOTOK_WHILE,
MOO_IOTOK_UNTIL,
MOO_IOTOK_DO,
MOO_IOTOK_BREAK,
MOO_IOTOK_CONTINUE,
MOO_IOTOK_IDENT,
MOO_IOTOK_IDENT_DOTTED,
MOO_IOTOK_BINSEL,
MOO_IOTOK_KEYWORD,
MOO_IOTOK_ASSIGN,
MOO_IOTOK_COLON,
MOO_IOTOK_RETURN, /* ^ */
MOO_IOTOK_RETURN, /* ^ */
MOO_IOTOK_LOCAL_RETURN, /* ^^ */
MOO_IOTOK_LBRACE,
MOO_IOTOK_RBRACE,
@ -348,17 +361,7 @@ struct moo_iotok_t
MOO_IOTOK_DICBRACE, /* :{ - dictionary expression */
MOO_IOTOK_PERIOD,
MOO_IOTOK_COMMA,
MOO_IOTOK_SEMICOLON,
MOO_IOTOK_IF,
MOO_IOTOK_ELSE,
MOO_IOTOK_ELSIF,
MOO_IOTOK_WHILE,
MOO_IOTOK_UNTIL,
MOO_IOTOK_DO,
MOO_IOTOK_BREAK,
MOO_IOTOK_CONTINUE
MOO_IOTOK_SEMICOLON
} type;
moo_oocs_t name;
@ -425,6 +428,9 @@ struct moo_pooldic_t
moo_oop_dic_t pd_oop;
moo_oop_nsdic_t ns_oop;
moo_oow_t start;
moo_oow_t end;
};
typedef struct moo_oopbuf_t moo_oopbuf_t;
@ -443,6 +449,13 @@ struct moo_oobbuf_t
moo_oow_t capa;
};
typedef struct moo_initv_t moo_initv_t;
struct moo_initv_t
{
moo_oop_t v;
int flags;
};
struct moo_compiler_t
{
/* input handler */
@ -490,9 +503,6 @@ struct moo_compiler_t
moo_oop_class_t self_oop;
moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */
#if 0
moo_oop_dic_t pooldic_oop; /* used when compiling a pooldic definition */
#endif
moo_oop_nsdic_t ns_oop;
moo_oocs_t fqn;
moo_oocs_t name;
@ -508,10 +518,11 @@ struct moo_compiler_t
moo_oocs_t modname; /* module name after 'from' */
moo_oow_t modname_capa;
/* instance variable, class variable, class instance variable
/* instance variable, class variable, class instance variable, constant
* var[0] - named instance variables
* var[1] - class instance variables
* var[2] - class variables */
* var[2] - class variables
*/
struct
{
moo_oocs_t str; /* long string containing all variables declared delimited by a space */
@ -520,7 +531,7 @@ struct moo_compiler_t
moo_oow_t count; /* the number of variables declared in this class only */
moo_oow_t total_count; /* the number of variables declared in this class and superclasses */
moo_oop_t* initv;
moo_initv_t* initv;
moo_oow_t initv_capa;
/* initv_count holds the index to the last variable with a
* default initial value defined in this class only plus one.
@ -545,7 +556,6 @@ struct moo_compiler_t
moo_oop_dic_t* oops;
moo_oow_t oops_capa;
} pooldic_imp;
} cls;
/* pooldic declaration */
@ -611,27 +621,6 @@ struct moo_compiler_t
moo_oow_t code_capa;
} mth;
};
/*
typedef struct moo_bchbuf_t moo_bchbuf_t;
struct moo_bchbuf_t
{
moo_bch_t buf[128];
moo_bch_t* ptr;
moo_oow_t capa;
};
typedef struct moo_oochbuf_t moo_oochbuf_t;
struct moo_oochbuf_t
{
moo_ooch_t buf[128];
moo_ooch_t* ptr;
moo_oow_t capa;
};
*/
#endif
#if defined(MOO_USE_METHOD_TRAILER)
@ -891,13 +880,14 @@ enum moo_bcode_t
BCODE_PUSH_FALSE = 0x84, /* 132 */
BCODE_PUSH_CONTEXT = 0x85, /* 133 */
BCODE_PUSH_PROCESS = 0x86, /* 134 */
BCODE_PUSH_NEGONE = 0x87, /* 135 */
BCODE_PUSH_RECEIVER_NS = 0x87, /* 135 */
BCODE_POP_INTO_INSTVAR_X = 0x88, /* 136 ## */
BCODE_PUSH_ZERO = 0x89, /* 137 */
BCODE_PUSH_ONE = 0x8A, /* 138 */
BCODE_PUSH_TWO = 0x8B, /* 139 */
BCODE_PUSH_NEGONE = 0x89, /* 137 */
BCODE_PUSH_ZERO = 0x8A, /* 138 */
BCODE_PUSH_ONE = 0x8B, /* 139 */
BCODE_PUSH_TWO = 0x8C, /* 140 */
BCODE_PUSH_INSTVAR_X = 0x90, /* 144 ## */
BCODE_PUSH_TEMPVAR_X = 0x98, /* 152 ## */

View File

@ -494,7 +494,7 @@ struct moo_dic_t
typedef struct moo_nsdic_t moo_nsdic_t;
typedef struct moo_nsdic_t* moo_oop_nsdic_t;
#define MOO_CLASS_NAMED_INSTVARS 18
#define MOO_CLASS_NAMED_INSTVARS 17
typedef struct moo_class_t moo_class_t;
typedef struct moo_class_t* moo_oop_class_t;
@ -537,8 +537,6 @@ struct moo_class_t
moo_oop_nsdic_t nsup; /* pointer to the upper namespace */
moo_oop_nsdic_t nsdic; /* dictionary used for namespacing - may be nil when there are no subitems underneath */
moo_oop_dic_t cdic; /* constant dictionary */
moo_oop_t trsize; /* trailer size for new instances */
/* [0] - initial values for instance variables of new instances
@ -619,7 +617,7 @@ struct moo_method_t
*
* The code can be one of the following values:
* 0 - no special action
* 1 - return self
* 1 - return self (receiver)
* 2 - return thisContext (not used)
* 3 - return thisProcess
* 4 - return nil
@ -627,11 +625,12 @@ struct moo_method_t
* 6 - return false
* 7 - return index.
* 8 - return -index.
* 9 - return instvar[index]
* 10 - do primitive[index]
* 11 - do named primitive[index]
* 12 - exception handler
* 13 - ensure block
* 9 - return selfns
* 10 - return instvar[index]
* 11 - do primitive[index]
* 12 - do named primitive[index]
* 13 - exception handler
* 14 - ensure block
*/
/* [NOTE] changing preamble code bit structure requires changes to CompiledMethod>>preambleCode */
@ -645,17 +644,17 @@ struct moo_method_t
#define MOO_METHOD_PREAMBLE_RETURN_RECEIVER 1
#define MOO_METHOD_PREAMBLE_RETURN_CONTEXT 2
#define MOO_METHOD_PREAMBLE_RETURN_PROCESS 3
#define MOO_METHOD_PREAMBLE_RETURN_NIL 4
#define MOO_METHOD_PREAMBLE_RETURN_TRUE 5
#define MOO_METHOD_PREAMBLE_RETURN_FALSE 6
#define MOO_METHOD_PREAMBLE_RETURN_INDEX 7
#define MOO_METHOD_PREAMBLE_RETURN_NEGINDEX 8
#define MOO_METHOD_PREAMBLE_RETURN_INSTVAR 9
#define MOO_METHOD_PREAMBLE_PRIMITIVE 10
#define MOO_METHOD_PREAMBLE_NAMED_PRIMITIVE 11 /* index is an index to the symbol table */
#define MOO_METHOD_PREAMBLE_EXCEPTION 12 /* NOTE changing this requires changes in Except.st */
#define MOO_METHOD_PREAMBLE_ENSURE 13 /* NOTE changing this requires changes in Except.st */
#define MOO_METHOD_PREAMBLE_RETURN_RECEIVER_NS 4
#define MOO_METHOD_PREAMBLE_RETURN_NIL 5
#define MOO_METHOD_PREAMBLE_RETURN_TRUE 6
#define MOO_METHOD_PREAMBLE_RETURN_FALSE 7
#define MOO_METHOD_PREAMBLE_RETURN_INDEX 8
#define MOO_METHOD_PREAMBLE_RETURN_NEGINDEX 9
#define MOO_METHOD_PREAMBLE_RETURN_INSTVAR 10
#define MOO_METHOD_PREAMBLE_PRIMITIVE 11
#define MOO_METHOD_PREAMBLE_NAMED_PRIMITIVE 12 /* index is an index to the symbol table */
#define MOO_METHOD_PREAMBLE_EXCEPTION 13 /* NOTE changing this requires changes in Except.st */
#define MOO_METHOD_PREAMBLE_ENSURE 14 /* NOTE changing this requires changes in Except.st */
/* the index is an 16-bit unsigned integer. */
#define MOO_METHOD_PREAMBLE_INDEX_MIN 0x0000