Skip to content

Commit

Permalink
Renaming prep for the elimination of UNWORDs
Browse files Browse the repository at this point in the history
This is essentially just a renaming so that the "_WORDS" list for
objects becomes the "_KEYS" list, and the "_WORDS" list for
functions becomes the "_PARAMS" list.  The series themselves
are called KEYLIST and PARAMLIST respectively.

Motivation for this change is that the special kind of word used in
object frames doesn't have very much in common with WORD!
besides having a symbol number.  It's a lot more like a TYPESET!.
Similarly for params in functions, though they are slightly more
ANY-WORD! like because they store the word subtype to know
how to treat the parameter (get words and lit-words for quoting, for
example.)  In particular, if these words ever leak out to the system
they will crash, e.g. the "x" that escapes and makes it into this error:

     >> foo: func [x [series! any-object!]] []
     >> bind? select to-object try [foo 1] 'arg2
     == Segmentation fault: 11

The nature of the change is to switch these words to typesets which
happen to have an extra symbol.  Hence instead of an OPTS_UNWORD
the cue that it holds a typeset will be that it is actually a REB_TYPESET.
It also goes ahead and commits corrections to when VAL_WORD_SYM
was used when VAL_BIND_SYM was intended, the latter being what
will eventually be VAL_TYPESET_SYM.

It would have been possible to name all the variables "typeset", but as
with the unword it's a little different...so key and param likely are better.
Static typing in the C++ build will be able to smooth over any confusion
about what type the key is.
  • Loading branch information
hostilefork committed Sep 18, 2015
1 parent 500b5ea commit 6c0aefe
Show file tree
Hide file tree
Showing 27 changed files with 365 additions and 318 deletions.
18 changes: 9 additions & 9 deletions src/core/a-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,17 +1108,17 @@ extern int Do_Callback(REBSER *obj, u32 name, RXIARG *args, RXIARG *result);
***********************************************************************/
{
REBCNT index;
u32 *words;
REBVAL *syms;
u32 *syms;
REBVAL *keys;

syms = FRM_WORD(obj, 1);
keys = FRM_KEY(obj, 1);
// One less, because SELF not included.
words = OS_ALLOC_ARRAY(u32, obj->tail);
for (index = 0; index < (obj->tail-1); syms++, index++) {
words[index] = VAL_BIND_CANON(syms);
syms = OS_ALLOC_ARRAY(u32, obj->tail);
for (index = 0; index < (obj->tail - 1); keys++, index++) {
syms[index] = VAL_BIND_CANON(keys);
}
words[index] = 0;
return words;
syms[index] = 0;
return syms;
}


Expand Down Expand Up @@ -1164,7 +1164,7 @@ extern int Do_Callback(REBSER *obj, u32 name, RXIARG *args, RXIARG *result);
REBVAL value;
CLEARS(&value);
if (!(word = Find_Word_Index(obj, word, FALSE))) return 0;
if (VAL_GET_EXT(FRM_WORDS(obj) + word, EXT_WORD_LOCK)) return 0;
if (VAL_GET_EXT(FRM_KEYS(obj) + word, EXT_WORD_LOCK)) return 0;
RXI_To_Value(FRM_VALUES(obj)+word, val, type);
return type;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/b-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ static BOOT_BLK *Boot_Block;
**
***********************************************************************/
{
return FRM_WORD(Lib_Context, Action_Marker+action);
return FRM_KEY(Lib_Context, Action_Marker + action);
}


Expand Down Expand Up @@ -1169,7 +1169,7 @@ static REBCNT Set_Option_Word(REBCHR *str, REBCNT field)
NULL, VAL_BLK_HEAD(&Boot_Block->root), BIND_ALL
);
KEEP_SERIES(PG_Root_Words, "root words");
VAL_FRM_WORDS(ROOT_SELF) = PG_Root_Words;
VAL_FRM_KEYLIST(ROOT_SELF) = PG_Root_Words;

// Create main values:
DOUT("Level 3");
Expand Down
12 changes: 7 additions & 5 deletions src/core/c-do.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ void Trace_Arg(REBINT num, const REBVAL *arg, const REBVAL *path)
#endif

Val_Init_Word_Unbound(
arg, REB_WORD, VAL_WORD_SYM(param)
arg, REB_WORD, VAL_BIND_SYM(param)
);

// skip type check on refinement itself, and let the
Expand Down Expand Up @@ -956,7 +956,7 @@ void Trace_Arg(REBINT num, const REBVAL *arg, const REBVAL *path)
#endif

Val_Init_Word_Unbound(
arg, REB_WORD, VAL_WORD_SYM(param)
arg, REB_WORD, VAL_BIND_SYM(param)
);
break; // will fall through to continue below
}
Expand Down Expand Up @@ -1603,7 +1603,9 @@ void Trace_Arg(REBINT num, const REBVAL *arg, const REBVAL *path)
// OPTIONS_REFINEMENTS_TRUE at function create
SET_TRUE(arg);
} else
Val_Init_Word_Unbound(arg, REB_WORD, VAL_WORD_SYM(param));
Val_Init_Word_Unbound(
arg, REB_WORD, VAL_BIND_SYM(param)
);
#endif
}
else {
Expand Down Expand Up @@ -1907,8 +1909,8 @@ void Trace_Arg(REBINT num, const REBVAL *arg, const REBVAL *path)
struct Reb_Call *call;
REBVAL *arg;

wsrc = VAL_FUNC_WORDS(DSF_FUNC(DSF));
wnew = VAL_FUNC_WORDS(func_val);
wsrc = VAL_FUNC_PARAMLIST(DSF_FUNC(DSF));
wnew = VAL_FUNC_PARAMLIST(func_val);

// As part of the "Redo" we are not adding a new function location,
// label, or place to write the output. We are substituting new code
Expand Down
18 changes: 16 additions & 2 deletions src/core/c-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@
if (code >= 0 && n < SERIES_TAIL(cats) &&
(cat = VAL_ERR_OBJECT(BLK_SKIP(cats, n)))
) {
Val_Init_Word(&error->type, REB_WORD, FRM_WORD_SYM(cats, n), cats, n);
Val_Init_Word(&error->type, REB_WORD, FRM_KEY_SYM(cats, n), cats, n);

// Find word related to the error itself:

n = code % 100 + 3;
if (n < SERIES_TAIL(cat))
Val_Init_Word(&error->id, REB_WORD, FRM_WORD_SYM(cat, n), cat, n);
Val_Init_Word(&error->id, REB_WORD, FRM_KEY_SYM(cat, n), cat, n);
}
}

Expand Down Expand Up @@ -781,6 +781,20 @@
}


/***********************************************************************
**
*/ ATTRIBUTE_NO_RETURN void Error_Protected_Key(REBVAL *key)
/*
***********************************************************************/
{
REBVAL key_name;
assert(IS_TYPESET(key));
Val_Init_Word_Unbound(&key_name, REB_WORD, VAL_BIND_SYM(key));

Error_1(RE_LOCKED_WORD, &key_name);
}


/***********************************************************************
**
*/ ATTRIBUTE_NO_RETURN void Error_Illegal_Action(REBCNT type, REBCNT action)
Expand Down
Loading

0 comments on commit 6c0aefe

Please sign in to comment.