From c3b737037ad668ef841ed163ebd9fee81bb0453e Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 30 Mar 2014 14:45:24 +0900 Subject: [PATCH] refactor native_stack_length --- include/picrin/cont.h | 2 +- src/cont.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/picrin/cont.h b/include/picrin/cont.h index 0367bb14..494e042a 100644 --- a/include/picrin/cont.h +++ b/include/picrin/cont.h @@ -16,7 +16,7 @@ struct pic_cont { pic_block *blk; char *stk_pos, *stk_ptr; - size_t stk_len; + ptrdiff_t stk_len; pic_value *st_ptr; size_t sp_offset, st_len; diff --git a/src/cont.c b/src/cont.c index 6248a503..70647fb8 100644 --- a/src/cont.c +++ b/src/cont.c @@ -77,7 +77,7 @@ pic_receive(pic_state *pic, size_t n, pic_value *argv) static void save_cont(pic_state *, struct pic_cont **); static void restore_cont(pic_state *, struct pic_cont *); -static size_t +static ptrdiff_t native_stack_length(pic_state *pic, char **pos) { char t; @@ -87,8 +87,8 @@ native_stack_length(pic_state *pic, char **pos) : pic->native_stack_start; return (pic->native_stack_start > &t) - ? (size_t)(pic->native_stack_start - &t) - : (size_t)(&t - pic->native_stack_start + 1); + ? pic->native_stack_start - &t + : &t - pic->native_stack_start; } static void @@ -106,6 +106,7 @@ save_cont(pic_state *pic, struct pic_cont **c) cont->stk_pos = pos; cont->stk_ptr = pic_alloc(pic, sizeof(pic_value) * cont->stk_len); memcpy(cont->stk_ptr, cont->stk_pos, sizeof(pic_value) * cont->stk_len); + assert(cont->stk_len > 0); cont->sp_offset = pic->sp - pic->stbase; cont->st_len = pic->stend - pic->stbase;