Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT/FIX: Picking the right PICK #5

Merged
merged 2 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/core/t-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,15 @@ static struct {
REBINT n = 0;

/* Issues!!!
a/1.3
a/not-found: 10 error or append?
a/not-followed: 10 error or append?
*/

if (IS_INTEGER(pvs->select)) {
n = Int32(pvs->select) + VAL_INDEX(pvs->value) - 1;
if (IS_INTEGER(pvs->select) || IS_DECIMAL(pvs->select)) {
REBINT i = Int32(pvs->select);
if (i == 0) return PE_NONE; // like in case: path/0
if (i < 0) i++;
n = i + VAL_INDEX(pvs->value) - 1;
}
else if (IS_WORD(pvs->select)) {
n = Find_Word(VAL_SERIES(pvs->value), VAL_INDEX(pvs->value), VAL_WORD_CANON(pvs->select));
Expand Down Expand Up @@ -573,6 +575,8 @@ static struct {
REBINT n = 0;

n = Get_Num_Arg(selector);
if (n == 0) return 0;
if (n < 0) n++;
n += VAL_INDEX(block) - 1;
if (n < 0 || (REBCNT)n >= VAL_TAIL(block)) return 0;
return VAL_BLK_SKIP(block, n);
Expand Down
10 changes: 7 additions & 3 deletions src/core/t-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)
REBSER *ser = VAL_SERIES(data);

if (IS_INTEGER(pvs->select)) {
n = Int32(pvs->select) + VAL_INDEX(data) - 1;
i = Int32(pvs->select);
if (i == 0) return PE_NONE; // like in case: path/0
if (i < 0) i++;
n = i + VAL_INDEX(data) - 1;
}
else return PE_BAD_SELECT;

Expand Down Expand Up @@ -542,8 +545,9 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)
case A_PICK:
case A_POKE:
len = Get_Num_Arg(arg); // Position
//if (len > 0) index--;
if (REB_I32_SUB_OF(len, 1, &len)
if (len < 0) REB_I32_ADD_OF(index, 1, &index);
if (len == 0
|| REB_I32_SUB_OF(len, 1, &len)
|| REB_I32_ADD_OF(index, len, &index)
|| index < 0 || index >= tail) {
if (action == A_PICK) goto is_none;
Expand Down
7 changes: 5 additions & 2 deletions src/core/t-vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,13 @@ void Set_Vector_Row(REBSER *ser, REBVAL *blk)
REBINT bits;
REBYTE *vp;
REBI64 i;
REBDEC f;
REBDEC f = 0.0;

if (IS_INTEGER(pvs->select) || IS_DECIMAL(pvs->select))
if (IS_INTEGER(pvs->select) || IS_DECIMAL(pvs->select)) {
n = Int32(pvs->select);
if (n == 0) return PE_NONE;
if (n < 0) n++;
}
else return PE_BAD_SELECT;

n += VAL_INDEX(pvs->value);
Expand Down