11package tlc2 .overrides ;
22/*******************************************************************************
33 * Copyright (c) 2019 Microsoft Research. All rights reserved.
4+ * Copyright (c) 2023, Oracle and/or its affiliates.
45 *
56 * The MIT License (MIT)
67 *
4041import tlc2 .value .IBoolValue ;
4142import tlc2 .value .IValue ;
4243import tlc2 .value .Values ;
43- import tlc2 .value .impl .Applicable ;
4444import tlc2 .value .impl .BoolValue ;
4545import tlc2 .value .impl .FcnRcdValue ;
4646import tlc2 .value .impl .IntValue ;
@@ -275,7 +275,7 @@ public static Value foldLeft(final OpValue op, final Value base, final Value val
275275 final Value [] elems = tv .elems ;
276276 for (int i = 0 ; i < elems .length ; i ++) {
277277 args [1 ] = elems [i ];
278- args [0 ] = op .apply (args , EvalControl .Clear );
278+ args [0 ] = op .eval (args , EvalControl .Clear );
279279 }
280280
281281 return args [0 ];
@@ -299,7 +299,7 @@ public static Value foldRight(final OpValue op, final Value val, final Value bas
299299 final Value [] elems = tv .elems ;
300300 for (int i = elems .length - 1 ; i >= 0 ; i --) {
301301 args [0 ] = elems [i ];
302- args [1 ] = op .apply (args , EvalControl .Clear );
302+ args [1 ] = op .eval (args , EvalControl .Clear );
303303 }
304304
305305 return args [1 ];
@@ -381,25 +381,20 @@ public static Value isPrefix(final Value v1, final Value v2) {
381381 }
382382
383383 @ TLAPlusOperator (identifier = "SelectInSeq" , module = "SequencesExt" , warn = false )
384- public static Value selectInSeq (final Value s , final Value test ) {
384+ public static Value selectInSeq (final Value s , final OpValue test ) {
385385 final TupleValue seq = (TupleValue ) s .toTuple ();
386386 if (seq == null ) {
387387 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
388388 new String [] { "first" , "SelectInSeq" , "sequence" , Values .ppr (s .toString ()) });
389389 }
390- if (!(test instanceof Applicable )) {
391- throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
392- new String [] { "third" , "SelectInSeq" , "function" , Values .ppr (test .toString ()) });
393- }
394390 final int len = seq .size ();
395- final Applicable ftest = (Applicable ) test ;
396391 final Value [] args = new Value [1 ];
397392 for (int i = 0 ; i < len ; i ++) {
398393 args [0 ] = seq .elems [i ];
399- final Value val = ftest . apply (args , EvalControl .Clear );
394+ final Value val = test . eval (args , EvalControl .Clear );
400395 if (!(val instanceof IBoolValue )) {
401396 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR , new String [] { "third" , "SelectInSeq" ,
402- "boolean-valued function " , Values .ppr (test .toString ()) });
397+ "boolean-valued operator " , Values .ppr (test .toString ()) });
403398 }
404399 if (((BoolValue ) val ).val ) {
405400 return IntValue .gen (i + 1 );
@@ -409,7 +404,7 @@ public static Value selectInSeq(final Value s, final Value test) {
409404 }
410405
411406 @ TLAPlusOperator (identifier = "SelectInSubSeq" , module = "SequencesExt" , warn = false )
412- public static Value SelectInSubSeq (final Value s , final Value f , final Value t , final Value test ) {
407+ public static Value SelectInSubSeq (final Value s , final Value f , final Value t , final OpValue test ) {
413408 final TupleValue seq = (TupleValue ) s .toTuple ();
414409 if (seq == null ) {
415410 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
@@ -423,10 +418,6 @@ public static Value SelectInSubSeq(final Value s, final Value f, final Value t,
423418 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
424419 new String [] { "third" , "SelectInSubSeq" , "natural" , Values .ppr (t .toString ()) });
425420 }
426- if (!(test instanceof Applicable )) {
427- throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
428- new String [] { "fourth" , "SelectInSubSeq" , "function" , Values .ppr (test .toString ()) });
429- }
430421
431422 int from = ((IntValue ) f ).val ;
432423 final int to = ((IntValue ) t ).val ;
@@ -442,15 +433,14 @@ public static Value SelectInSubSeq(final Value s, final Value f, final Value t,
442433 throw new EvalException (EC .TLC_MODULE_ARGUMENT_NOT_IN_DOMAIN ,
443434 new String [] { "third" , "SelectInSubSeq" , "first" , Values .ppr (s .toString ()), Values .ppr (t .toString ()) });
444435 }
445-
446- final Applicable ftest = (Applicable ) test ;
436+
447437 final Value [] args = new Value [1 ];
448438 for (; from <= to ; from ++) {
449439 args [0 ] = seq .elems [from - 1 ];
450- final Value val = ftest . apply (args , EvalControl .Clear );
440+ final Value val = test . eval (args , EvalControl .Clear );
451441 if (!(val instanceof IBoolValue )) {
452442 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR , new String [] { "fourth" , "SelectInSubSeq" ,
453- "boolean-valued function " , Values .ppr (test .toString ()) });
443+ "boolean-valued operator " , Values .ppr (test .toString ()) });
454444 }
455445 if (((BoolValue ) val ).val ) {
456446 return IntValue .gen (from );
@@ -460,22 +450,17 @@ public static Value SelectInSubSeq(final Value s, final Value f, final Value t,
460450 }
461451
462452 @ TLAPlusOperator (identifier = "SelectLastInSeq" , module = "SequencesExt" , warn = false )
463- public static Value selectLastInSeq (final Value s , final Value test ) {
453+ public static Value selectLastInSeq (final Value s , final OpValue test ) {
464454 final TupleValue seq = (TupleValue ) s .toTuple ();
465455 if (seq == null ) {
466456 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
467457 new String [] { "first" , "SelectLastInSeq" , "sequence" , Values .ppr (s .toString ()) });
468458 }
469- if (!(test instanceof Applicable )) {
470- throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
471- new String [] { "third" , "SelectLastInSeq" , "function" , Values .ppr (test .toString ()) });
472- }
473459 int i = seq .size () - 1 ;
474- final Applicable ftest = (Applicable ) test ;
475460 final Value [] args = new Value [1 ];
476461 for (; i >= 0 ; i --) {
477462 args [0 ] = seq .elems [i ];
478- final Value val = ftest . apply (args , EvalControl .Clear );
463+ final Value val = test . eval (args , EvalControl .Clear );
479464 if (!(val instanceof IBoolValue )) {
480465 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR , new String [] { "third" , "SelectLastInSeq" ,
481466 "boolean-valued function" , Values .ppr (test .toString ()) });
@@ -488,7 +473,7 @@ public static Value selectLastInSeq(final Value s, final Value test) {
488473 }
489474
490475 @ TLAPlusOperator (identifier = "SelectLastInSubSeq" , module = "SequencesExt" , warn = false )
491- public static Value SelectLastInSubSeq (final Value s , final Value f , final Value t , final Value test ) {
476+ public static Value SelectLastInSubSeq (final Value s , final Value f , final Value t , final OpValue test ) {
492477 final TupleValue seq = (TupleValue ) s .toTuple ();
493478 if (seq == null ) {
494479 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
@@ -502,10 +487,6 @@ public static Value SelectLastInSubSeq(final Value s, final Value f, final Value
502487 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
503488 new String [] { "third" , "SelectLastInSubSeq" , "natural" , Values .ppr (t .toString ()) });
504489 }
505- if (!(test instanceof Applicable )) {
506- throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
507- new String [] { "fourth" , "SelectLastInSubSeq" , "function" , Values .ppr (test .toString ()) });
508- }
509490
510491 final int from = ((IntValue ) f ).val ;
511492 int to = ((IntValue ) t ).val ;
@@ -521,12 +502,11 @@ public static Value SelectLastInSubSeq(final Value s, final Value f, final Value
521502 throw new EvalException (EC .TLC_MODULE_ARGUMENT_NOT_IN_DOMAIN ,
522503 new String [] { "third" , "SelectLastInSubSeq" , "first" , Values .ppr (s .toString ()), Values .ppr (t .toString ()) });
523504 }
524-
525- final Applicable ftest = (Applicable ) test ;
505+
526506 final Value [] args = new Value [1 ];
527507 for (; to >= from ; to --) {
528508 args [0 ] = seq .elems [to - 1 ];
529- final Value val = ftest . apply (args , EvalControl .Clear );
509+ final Value val = test . eval (args , EvalControl .Clear );
530510 if (!(val instanceof IBoolValue )) {
531511 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR , new String [] { "fourth" , "SelectLastInSubSeq" ,
532512 "boolean-valued function" , Values .ppr (test .toString ()) });
@@ -561,17 +541,12 @@ public static Value removeFirst(final Value s, final Value e) {
561541 }
562542
563543 @ TLAPlusOperator (identifier = "RemoveFirstMatch" , module = "SequencesExt" , warn = false )
564- public static Value removeFirstMatch (final Value s , final Value test ) {
544+ public static Value removeFirstMatch (final Value s , final OpValue test ) {
565545 final TupleValue seq = (TupleValue ) s .toTuple ();
566546 if (seq == null ) {
567547 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
568548 new String [] { "first" , "RemoveFirstMatch" , "sequence" , Values .ppr (s .toString ()) });
569549 }
570- if (!(test instanceof Applicable )) {
571- throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR ,
572- new String [] { "second" , "RemoveFirstMatch" , "function" , Values .ppr (test .toString ()) });
573- }
574- final Applicable ftest = (Applicable ) test ;
575550 final Value [] args = new Value [1 ];
576551
577552 final ArrayList <Value > val = new ArrayList <>(seq .elems .length );
@@ -580,7 +555,7 @@ public static Value removeFirstMatch(final Value s, final Value test) {
580555 for (int i = 0 ; i < seq .elems .length ; i ++) {
581556 if (!found ) {
582557 args [0 ] = seq .elems [i ];
583- final Value bval = ftest . apply (args , EvalControl .Clear );
558+ final Value bval = test . eval (args , EvalControl .Clear );
584559 if (!(bval instanceof IBoolValue )) {
585560 throw new EvalException (EC .TLC_MODULE_ARGUMENT_ERROR , new String [] { "second" , "RemoveFirstMatch" ,
586561 "boolean-valued function" , Values .ppr (test .toString ()) });
0 commit comments