From 0a69303164ea5d7a595493fbca902ecad7e289ae Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 16 Aug 2020 19:47:40 -0700 Subject: [PATCH] Refactor array store for string/real and skip saving when given an undefined index --- vvp/vthread.cc | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 87bfddebc..55dac4388 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -6252,18 +6252,26 @@ bool of_STORE_REAL(vthread_t thr, vvp_code_t cp) return store(thr, cp); } +template +static bool storea(vthread_t thr, vvp_code_t cp) +{ + unsigned idx = cp->bit_idx[0]; + unsigned adr = thr->words[idx].w_int; + ELEM val; + pop_value(thr, val, 0); + + if (thr->flags[4] != BIT4_1) + cp->array->set_word(adr, val); + + return true; +} + /* * %store/reala */ bool of_STORE_REALA(vthread_t thr, vvp_code_t cp) { - unsigned idx = cp->bit_idx[0]; - unsigned adr = thr->words[idx].w_int; - - double val = thr->pop_real(); - cp->array->set_word(adr, val); - - return true; + return storea(thr, cp); } bool of_STORE_STR(vthread_t thr, vvp_code_t cp) @@ -6276,13 +6284,7 @@ bool of_STORE_STR(vthread_t thr, vvp_code_t cp) */ bool of_STORE_STRA(vthread_t thr, vvp_code_t cp) { - unsigned idx = cp->bit_idx[0]; - unsigned adr = thr->words[idx].w_int; - - string val = thr->pop_str(); - cp->array->set_word(adr, val); - - return true; + return storea(thr, cp); } /*