From 52de9e860a63a6267fef7880171d2f2d30b01905 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 10 Aug 2015 23:53:36 +0900 Subject: [PATCH] inline codegen_call_vm --- extlib/benz/codegen.c | 44 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/extlib/benz/codegen.c b/extlib/benz/codegen.c index 05173135..2b280cd5 100644 --- a/extlib/benz/codegen.c +++ b/extlib/benz/codegen.c @@ -990,21 +990,29 @@ codegen_quote(pic_state *pic, codegen_context *cxt, pic_value obj, bool tailpos) } } -static bool -codegen_call_vm(pic_state *pic, codegen_context *cxt, pic_value proc, size_t len, bool tailpos) -{ - if (pic_sym_ptr(pic_list_ref(pic, proc, 0)) == pic->sGREF) { - pic_sym *sym; - - sym = pic_sym_ptr(pic_list_ref(pic, proc, 1)); - #define VM(uid, op) \ if (sym == uid) { \ - emit_i(pic, cxt, op, len); \ + emit_i(pic, cxt, op, len - 1); \ emit_ret(pic, cxt, tailpos); \ - return true; \ + return; \ } +static void +codegen_call(pic_state *pic, codegen_context *cxt, pic_value obj, bool tailpos) +{ + int len = (int)pic_length(pic, obj); + pic_value elt, it, functor; + + pic_for_each (elt, pic_cdr(pic, obj), it) { + codegen(pic, cxt, elt, false); + } + + functor = pic_list_ref(pic, obj, 1); + if (pic_sym_ptr(pic_list_ref(pic, functor, 0)) == pic->sGREF) { + pic_sym *sym; + + sym = pic_sym_ptr(pic_list_ref(pic, functor, 1)); + VM(pic->uCONS, OP_CONS) VM(pic->uCAR, OP_CAR) VM(pic->uCDR, OP_CDR) @@ -1022,22 +1030,6 @@ codegen_call_vm(pic_state *pic, codegen_context *cxt, pic_value proc, size_t len VM(pic->uMUL, OP_MUL) VM(pic->uDIV, OP_DIV) } - return false; -} - -static void -codegen_call(pic_state *pic, codegen_context *cxt, pic_value obj, bool tailpos) -{ - int len = (int)pic_length(pic, obj); - pic_value elt, it; - - pic_for_each (elt, pic_cdr(pic, obj), it) { - codegen(pic, cxt, elt, false); - } - - if (codegen_call_vm(pic, cxt, pic_list_ref(pic, obj, 1), len - 1, tailpos)) { - return; - } emit_i(pic, cxt, (tailpos ? OP_TAILCALL : OP_CALL), len - 1); }