@@ -438,7 +438,7 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
438438 DISPATCH ();
439439
440440 OP (RANDOM) :
441- if (( READ_REG (0 , 2 )->type () == Value::Type::Integer) && ( READ_REG (1 , 2 )->type () == Value::Type::Integer )) REPLACE_RET_VALUE (rng->randint (READ_REG (0 , 2 )->toInt (), READ_REG (1 , 2 )->toInt ()), 2 );
441+ if (READ_REG (0 , 2 )->isInt () && READ_REG (1 , 2 )->isInt ( )) REPLACE_RET_VALUE (rng->randint (READ_REG (0 , 2 )->toInt (), READ_REG (1 , 2 )->toInt ()), 2 );
442442 else REPLACE_RET_VALUE (rng->randintDouble (READ_REG (0 , 2 )->toDouble (), READ_REG (1 , 2 )->toDouble ()), 2 );
443443 FREE_REGS (1 );
444444 DISPATCH ();
@@ -621,7 +621,10 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
621621 const Value *indexValue = READ_LAST_REG ();
622622 size_t index;
623623 List *list = lists[*++pos];
624- if (indexValue->isString ()) {
624+ if (indexValue->isValidNumber ()) {
625+ index = indexValue->toLong ();
626+ FIX_LIST_INDEX (index, list->size ());
627+ } else {
625628 const std::string &str = indexValue->toString ();
626629 if (str == " last" ) {
627630 index = list->size ();
@@ -633,9 +636,6 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
633636 index = size == 0 ? 0 : rng->randint (1 , size);
634637 } else
635638 index = 0 ;
636- } else {
637- index = indexValue->toLong ();
638- FIX_LIST_INDEX (index, list->size ());
639639 }
640640 if (index != 0 )
641641 list->removeAt (index - 1 );
@@ -652,7 +652,10 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
652652 const Value *indexValue = READ_REG (1 , 2 );
653653 size_t index;
654654 List *list = lists[*++pos];
655- if (indexValue->isString ()) {
655+ if (indexValue->isValidNumber ()) {
656+ index = indexValue->toLong ();
657+ FIX_LIST_INDEX (index, list->size ());
658+ } else {
656659 const std::string &str = indexValue->toString ();
657660 if (str == " last" ) {
658661 list->push_back (*READ_REG (0 , 2 ));
@@ -662,9 +665,6 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
662665 index = size == 0 ? 1 : rng->randint (1 , size);
663666 } else
664667 index = 0 ;
665- } else {
666- index = indexValue->toLong ();
667- FIX_LIST_INDEX (index, list->size ());
668668 }
669669 if ((index != 0 ) || list->empty ()) {
670670 if (list->empty ())
@@ -681,7 +681,10 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
681681 const Value *indexValue = READ_REG (0 , 2 );
682682 size_t index;
683683 List *list = lists[*++pos];
684- if (indexValue->isString ()) {
684+ if (indexValue->isValidNumber ()) {
685+ index = indexValue->toLong ();
686+ FIX_LIST_INDEX (index, list->size ());
687+ } else {
685688 std::string str = indexValue->toString ();
686689 if (str == " last" )
687690 index = list->size ();
@@ -690,9 +693,6 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
690693 index = size == 0 ? 0 : rng->randint (1 , size);
691694 } else
692695 index = 0 ;
693- } else {
694- index = indexValue->toLong ();
695- FIX_LIST_INDEX (index, list->size ());
696696 }
697697 if (index != 0 )
698698 list->operator [](index - 1 ) = *READ_REG (1 , 2 );
@@ -705,7 +705,10 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
705705 const Value *indexValue = READ_LAST_REG ();
706706 size_t index;
707707 List *list = lists[*++pos];
708- if (indexValue->isString ()) {
708+ if (indexValue->isValidNumber ()) {
709+ index = indexValue->toLong ();
710+ FIX_LIST_INDEX (index, list->size ());
711+ } else {
709712 std::string str = indexValue->toString ();
710713 if (str == " last" )
711714 index = list->size ();
@@ -714,9 +717,6 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
714717 index = size == 0 ? 0 : rng->randint (1 , size);
715718 } else
716719 index = 0 ;
717- } else {
718- index = indexValue->toLong ();
719- FIX_LIST_INDEX (index, list->size ());
720720 }
721721 if (index == 0 ) {
722722 REPLACE_RET_VALUE (" " , 1 );
0 commit comments