regularize use of indices

This commit is contained in:
Vern Paxson 2024-06-23 15:37:54 -07:00
parent 90c6744c63
commit 5530aee57d
5 changed files with 22 additions and 18 deletions

@ -1 +1 @@
Subproject commit 7aa69b5fd0b435430d35d68a9a93b5d973298e30
Subproject commit 9c5fc71faa56f169131e973a7a47071acdd5f306

View file

@ -67,10 +67,10 @@ op1-read
class VV
op-types V V
eval ValPtr vec = {NewRef{}, $1};
auto slice = Z_AUX->ToListVal(frame);
auto indices = Z_AUX->ToListVal(frame);
ValPtr vals = {NewRef{}, $2};
bool iterators_invalidated;
auto error = assign_to_index(std::move(vec), std::move(slice), std::move(vals), iterators_invalidated);
auto error = assign_to_index(std::move(vec), std::move(indices), std::move(vals), iterators_invalidated);
if ( error )
ERROR(error);
if ( iterators_invalidated )

View file

@ -104,25 +104,27 @@ eval EvalIndexAnyVec($$, $1, $2)
macro EvalVecSlice(lhs, vv)
auto vec = vv;
auto lv = Z_AUX->ToListVal(frame);
auto v = index_slice(vec, lv.get());
auto v = index_slice(vec, indices.get());
Unref(lhs);
lhs = v.release();
internal-op Index-Vec-Slice
class VV
op-types V V
eval EvalVecSlice($$, $1)
eval auto indices = Z_AUX->ToListVal(frame);
EvalVecSlice($$, $1)
internal-op When-Index-Vec-Slice
class VV
op-types V V
eval EvalVecSlice($$, $1)
eval auto indices = Z_AUX->ToListVal(frame);
EvalVecSlice($$, $1)
WhenIndexResCheck($$)
internal-op Table-Index
class VV
eval EvalTableIndex($1, Z_AUX->ToListVal(frame))
eval auto indices = Z_AUX->ToListVal(frame);
EvalTableIndex($1, indices)
if ( v )
AssignTarget($$, BuildVal(v, Z_TYPE))
@ -135,7 +137,8 @@ eval auto vec = ZVal($1->LookupPattern({NewRef{}, $2}));
internal-op When-Table-Index
class VV
eval EvalTableIndex($1, Z_AUX->ToListVal(frame))
eval auto indices = Z_AUX->ToListVal(frame);
EvalTableIndex($1, indices)
if ( v )
{
if ( IndexExprWhen::evaluating > 0 )
@ -151,8 +154,8 @@ macro EvalTableIndex(tbl, index)
internal-op When-PatStr-Index
class VV
op-types X T
eval auto args = Z_AUX->ToListVal(frame);
auto arg0 = args->Idx(0);
eval auto indices = Z_AUX->ToListVal(frame);
auto arg0 = indices->Idx(0);
auto v = $1->LookupPattern({NewRef{}, arg0->AsStringVal()});
if ( IndexExprWhen::evaluating > 0 )
IndexExprWhen::results.emplace_back(v);
@ -190,8 +193,8 @@ internal-op Index-String-Slice
class VV
op-types S S
eval auto str = $1->AsString();
auto lv = Z_AUX->ToListVal(frame);
auto slice = index_string(str, lv.get());
auto indices = Z_AUX->ToListVal(frame);
auto slice = index_string(str, indices.get());
Unref($$);
$$ = new StringVal(slice->ToStdString());

View file

@ -198,8 +198,8 @@ eval $1->Find($2.ToVal(Z_TYPE)) != nullptr
internal-op List-Is-In-Table
classes VV VC
op-types I T
eval auto op1 = Z_AUX->ToListVal(frame);
$$ = $1->Find(std::move(op1)) != nullptr;
eval auto indices = Z_AUX->ToListVal(frame);
$$ = $1->Find(std::move(indices)) != nullptr;
internal-op Val-Is-In-Vector
class VVV

View file

@ -216,7 +216,8 @@ eval if ( $1 ) $2
op AddStmt
op1-read
class VO
eval EvalAddStmt($1, Z_AUX->ToListVal(frame))
eval auto indices = Z_AUX->ToListVal(frame);
EvalAddStmt($1, indices)
method-post z.aux = v->aux;
macro EvalAddStmt(lhs, ind)
@ -250,9 +251,9 @@ op DelTable
op1-read
class VO
op-types T X
eval auto index = Z_AUX->ToListVal(frame);
eval auto indices = Z_AUX->ToListVal(frame);
bool iterators_invalidated = false;
$1->Remove(*index, true, &iterators_invalidated);
$1->Remove(*indices, true, &iterators_invalidated);
if ( iterators_invalidated )
WARN("possible loop/iterator invalidation");
method-post z.aux = v->aux;