From 8e3afebb7bef581a8a43b3fa00ebf550f0d21a66 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 16 Aug 2020 18:00:04 -0700 Subject: [PATCH] Refactor set DAR object --- vvp/vthread.cc | 56 +++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/vvp/vthread.cc b/vvp/vthread.cc index e434902a1..a84800e27 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -5655,14 +5655,28 @@ bool of_SCOPY(vthread_t thr, vvp_code_t) return true; } -/* - * %set/dar/obj/real - */ -bool of_SET_DAR_OBJ_REAL(vthread_t thr, vvp_code_t cp) +static void thread_peek(vthread_t thr, double&value) +{ + value = thr->peek_real(0); +} + +static void thread_peek(vthread_t thr, string&value) +{ + value = thr->peek_str(0); +} + +static void thread_peek(vthread_t thr, vvp_vector4_t&value) +{ + value = thr->peek_vec4(0); +} + +template +static bool set_dar_obj(vthread_t thr, vvp_code_t cp) { unsigned adr = thr->words[cp->number].w_int; - double value = thr->peek_real(0); + ELEM value; + thread_peek(thr, value); vvp_object_t&top = thr->peek_object(); vvp_darray*darray = top.peek(); @@ -5673,20 +5687,11 @@ bool of_SET_DAR_OBJ_REAL(vthread_t thr, vvp_code_t cp) } /* - * %set/dar/obj/str + * %set/dar/obj/real */ -bool of_SET_DAR_OBJ_VEC4(vthread_t thr, vvp_code_t cp) +bool of_SET_DAR_OBJ_REAL(vthread_t thr, vvp_code_t cp) { - unsigned adr = thr->words[cp->number].w_int; - - vvp_vector4_t value = thr->peek_vec4(0); - - vvp_object_t&top = thr->peek_object(); - vvp_darray*darray = top.peek(); - assert(darray); - - darray->set_word(adr, value); - return true; + return set_dar_obj(thr, cp); } /* @@ -5694,16 +5699,15 @@ bool of_SET_DAR_OBJ_VEC4(vthread_t thr, vvp_code_t cp) */ bool of_SET_DAR_OBJ_STR(vthread_t thr, vvp_code_t cp) { - unsigned adr = thr->words[cp->number].w_int; + return set_dar_obj(thr, cp); +} - string value = thr->peek_str(0); - - vvp_object_t&top = thr->peek_object(); - vvp_darray*darray = top.peek(); - assert(darray); - - darray->set_word(adr, value); - return true; +/* + * %set/dar/obj/vec4 + */ +bool of_SET_DAR_OBJ_VEC4(vthread_t thr, vvp_code_t cp) +{ + return set_dar_obj(thr, cp); } /*