pic_errorf -> pic_error
This commit is contained in:
		
							parent
							
								
									42d0ecc633
								
							
						
					
					
						commit
						fae7ef0376
					
				| 
						 | 
				
			
			@ -18,7 +18,7 @@ pic_load_load(pic_state *pic)
 | 
			
		|||
 | 
			
		||||
  fp = fopen(fn, "r");
 | 
			
		||||
  if (fp == NULL) {
 | 
			
		||||
    pic_errorf(pic, "load: could not open file %s", fn);
 | 
			
		||||
    pic_error(pic, "load: could not open file", 1, pic_cstr_value(pic, fn));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  port = pic_open_port(pic, xfopen_file(pic, fp, "r"));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -194,7 +194,7 @@ pic_rl_read_history(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "z", &filename);
 | 
			
		||||
 | 
			
		||||
  if(read_history(filename))
 | 
			
		||||
    pic_errorf(pic, "cannot read history file : %s", filename);
 | 
			
		||||
    pic_error(pic, "cannot read history file", 1, pic_cstr_value(pic, filename));
 | 
			
		||||
  
 | 
			
		||||
  return pic_undef_value(pic);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -207,7 +207,7 @@ pic_rl_write_history(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "z", &filename);
 | 
			
		||||
 | 
			
		||||
  if(write_history(filename))
 | 
			
		||||
    pic_errorf(pic, "cannot write history file: %s", filename);
 | 
			
		||||
    pic_error(pic, "cannot write history file", 1, pic_cstr_value(pic, filename));
 | 
			
		||||
  
 | 
			
		||||
  return pic_undef_value(pic);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -235,7 +235,7 @@ pic_rl_history_expand(pic_state *pic)
 | 
			
		|||
  
 | 
			
		||||
  status = history_expand(input,  &result);
 | 
			
		||||
  if(status == -1 || status == 2)
 | 
			
		||||
    pic_errorf(pic, "%s\n", result);
 | 
			
		||||
    pic_error(pic, result, 0);
 | 
			
		||||
 | 
			
		||||
  return pic_cstr_value(pic, result);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,7 +57,7 @@ pic_regexp_regexp(pic_state *pic)
 | 
			
		|||
    regerror(err, ®->reg, errbuf, sizeof errbuf);
 | 
			
		||||
    regexp_dtor(pic, ®->reg);
 | 
			
		||||
 | 
			
		||||
    pic_errorf(pic, "regexp compilation error: %s", errbuf);
 | 
			
		||||
    pic_error(pic, "regexp compilation error", 1, pic_cstr_value(pic, errbuf));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return pic_data_value(pic, reg, ®exp_type);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ PIC_INLINE void
 | 
			
		|||
ensure_socket_is_open(pic_state *pic, struct pic_socket_t *sock)
 | 
			
		||||
{
 | 
			
		||||
  if (sock != NULL && sock->fd == -1) {
 | 
			
		||||
    pic_errorf(pic, "the socket is already closed");
 | 
			
		||||
    pic_error(pic, "the socket is already closed", 0);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -87,9 +87,9 @@ pic_socket_make_socket(pic_state *pic)
 | 
			
		|||
  } while (result == EAI_AGAIN);
 | 
			
		||||
  if (result) {
 | 
			
		||||
    if (result == EAI_SYSTEM) {
 | 
			
		||||
      pic_errorf(pic, "%s", strerror(errno));
 | 
			
		||||
      pic_error(pic, strerror(errno), 0);
 | 
			
		||||
    }
 | 
			
		||||
    pic_errorf(pic, "%s", gai_strerror(result));
 | 
			
		||||
    pic_error(pic, gai_strerror(result), 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (it = ai; it != NULL; it = it->ai_next) {
 | 
			
		||||
| 
						 | 
				
			
			@ -129,7 +129,7 @@ pic_socket_make_socket(pic_state *pic)
 | 
			
		|||
  freeaddrinfo(ai);
 | 
			
		||||
 | 
			
		||||
  if (sock->fd == -1) {
 | 
			
		||||
    pic_errorf(pic, "%s", strerror(errno));
 | 
			
		||||
    pic_error(pic, strerror(errno), 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return pic_data_value(pic, sock, &socket_type);
 | 
			
		||||
| 
						 | 
				
			
			@ -158,7 +158,7 @@ pic_socket_socket_accept(pic_state *pic)
 | 
			
		|||
      } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
 | 
			
		||||
        continue;
 | 
			
		||||
      } else {
 | 
			
		||||
        pic_errorf(pic, "%s", strerror(errno));
 | 
			
		||||
        pic_error(pic, strerror(errno), 0);
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      break;
 | 
			
		||||
| 
						 | 
				
			
			@ -191,7 +191,7 @@ pic_socket_socket_send(pic_state *pic)
 | 
			
		|||
      } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
 | 
			
		||||
        break;
 | 
			
		||||
      } else {
 | 
			
		||||
        pic_errorf(pic, "%s", strerror(errno));
 | 
			
		||||
        pic_error(pic, strerror(errno), 0);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    cursor += len;
 | 
			
		||||
| 
						 | 
				
			
			@ -214,7 +214,7 @@ pic_socket_socket_recv(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "ui|i", &sock, &socket_type, &size, &flags);
 | 
			
		||||
 | 
			
		||||
  if (size < 0) {
 | 
			
		||||
    pic_errorf(pic, "size must not be negative");
 | 
			
		||||
    pic_error(pic, "size must not be negative", 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ensure_socket_is_open(pic, sock);
 | 
			
		||||
| 
						 | 
				
			
			@ -227,7 +227,7 @@ pic_socket_socket_recv(pic_state *pic)
 | 
			
		|||
  } while (len < 0 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
 | 
			
		||||
 | 
			
		||||
  if (len < 0) {
 | 
			
		||||
    pic_errorf(pic, "%s", strerror(errno));
 | 
			
		||||
    pic_error(pic, strerror(errno), 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return pic_blob_value(pic, buf, len);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,7 +56,7 @@ pic_blob_bytevector(pic_state *pic)
 | 
			
		|||
    pic_assert_type(pic, argv[i], int);
 | 
			
		||||
 | 
			
		||||
    if (pic_int(pic, argv[i]) < 0 || pic_int(pic, argv[i]) > 255) {
 | 
			
		||||
      pic_errorf(pic, "byte out of range");
 | 
			
		||||
      pic_error(pic, "byte out of range", 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    *data++ = (unsigned char)pic_int(pic, argv[i]);
 | 
			
		||||
| 
						 | 
				
			
			@ -74,10 +74,10 @@ pic_blob_make_bytevector(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "i|i", &k, &b);
 | 
			
		||||
 | 
			
		||||
  if (b < 0 || b > 255)
 | 
			
		||||
    pic_errorf(pic, "byte out of range");
 | 
			
		||||
    pic_error(pic, "byte out of range", 0);
 | 
			
		||||
 | 
			
		||||
  if (k < 0) {
 | 
			
		||||
    pic_errorf(pic, "make-bytevector: negative length given %d", k);
 | 
			
		||||
    pic_error(pic, "make-bytevector: negative length given", 1, pic_int_value(pic, k));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  blob = pic_blob_value(pic, 0, k);
 | 
			
		||||
| 
						 | 
				
			
			@ -119,7 +119,7 @@ pic_blob_bytevector_u8_set(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "bii", &buf, &len, &k, &v);
 | 
			
		||||
 | 
			
		||||
  if (v < 0 || v > 255)
 | 
			
		||||
    pic_errorf(pic, "byte out of range");
 | 
			
		||||
    pic_error(pic, "byte out of range", 0);
 | 
			
		||||
 | 
			
		||||
  VALID_INDEX(pic, len, k);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -216,7 +216,7 @@ pic_blob_list_to_bytevector(pic_state *pic)
 | 
			
		|||
    pic_assert_type(pic, e, int);
 | 
			
		||||
 | 
			
		||||
    if (pic_int(pic, e) < 0 || pic_int(pic, e) > 255)
 | 
			
		||||
      pic_errorf(pic, "byte out of range");
 | 
			
		||||
      pic_error(pic, "byte out of range", 0);
 | 
			
		||||
 | 
			
		||||
    *data++ = (unsigned char)pic_int(pic, e);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,7 +72,7 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, int depth, khash_t(m)
 | 
			
		|||
 | 
			
		||||
  if (depth > 10) {
 | 
			
		||||
    if (depth > 200) {
 | 
			
		||||
      pic_errorf(pic, "Stack overflow in equal\n");
 | 
			
		||||
      pic_error(pic, "stack overflow in equal", 0);
 | 
			
		||||
    }
 | 
			
		||||
    if (pic_pair_p(pic, x) || pic_vec_p(pic, x)) {
 | 
			
		||||
      int ret;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,7 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
#include "picrin.h"
 | 
			
		||||
#include "picrin/extra.h"
 | 
			
		||||
 | 
			
		||||
static pic_value
 | 
			
		||||
pic_char_char_p(pic_state *pic)
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +33,7 @@ pic_char_integer_to_char(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "i", &i);
 | 
			
		||||
 | 
			
		||||
  if (i < 0 || i > 255) {
 | 
			
		||||
    pic_errorf(pic, "integer->char: integer out of char range: %d", i);
 | 
			
		||||
    pic_error(pic, "integer->char: integer out of char range", 1, pic_int_value(pic, i));
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return pic_char_value(pic, (char)i);
 | 
			
		||||
| 
						 | 
				
			
			@ -49,15 +50,13 @@ pic_char_integer_to_char(pic_state *pic)
 | 
			
		|||
    pic_get_args(pic, "cc*", &c, &d, &argc, &argv);	\
 | 
			
		||||
    							\
 | 
			
		||||
    if (! (c op d))					\
 | 
			
		||||
      return pic_false_value(pic);				\
 | 
			
		||||
    							\
 | 
			
		||||
    for (i = 0; i < argc; ++i) {			\
 | 
			
		||||
      return pic_false_value(pic);                      \
 | 
			
		||||
                                                        \
 | 
			
		||||
    for (i = 0; i < argc; ++i) {                        \
 | 
			
		||||
      c = d;                                            \
 | 
			
		||||
      if (pic_char_p(pic, argv[i]))                          \
 | 
			
		||||
        d = pic_char(pic, argv[i]);                          \
 | 
			
		||||
      else						\
 | 
			
		||||
	pic_errorf(pic, #op ": char required");         \
 | 
			
		||||
      							\
 | 
			
		||||
      pic_assert_type(pic, argv[i], char);              \
 | 
			
		||||
      d = pic_char(pic, argv[i]);                       \
 | 
			
		||||
                                                        \
 | 
			
		||||
      if (! (c op d))					\
 | 
			
		||||
	return pic_false_value(pic);			\
 | 
			
		||||
    }							\
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -131,7 +131,7 @@ cont_call(pic_state *pic)
 | 
			
		|||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (cc == NULL) {
 | 
			
		||||
    pic_errorf(pic, "calling dead escape continuation");
 | 
			
		||||
    pic_error(pic, "calling dead escape continuation", 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  cont->retc = argc;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,7 @@ pic_dict_ref(pic_state *pic, pic_value dict, pic_value key)
 | 
			
		|||
 | 
			
		||||
  it = kh_get(dict, h, pic_sym_ptr(pic, key));
 | 
			
		||||
  if (it == kh_end(h)) {
 | 
			
		||||
    pic_errorf(pic, "element not found for a key: ~s", key);
 | 
			
		||||
    pic_error(pic, "element not found for given key", 1, key);
 | 
			
		||||
  }
 | 
			
		||||
  return kh_val(h, it);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +64,7 @@ pic_dict_del(pic_state *pic, pic_value dict, pic_value key)
 | 
			
		|||
 | 
			
		||||
  it = kh_get(dict, h, pic_sym_ptr(pic, key));
 | 
			
		||||
  if (it == kh_end(h)) {
 | 
			
		||||
    pic_errorf(pic, "no slot named ~s found in dictionary", key);
 | 
			
		||||
    pic_error(pic, "element not found for given key", 1, key);
 | 
			
		||||
  }
 | 
			
		||||
  kh_del(dict, h, it);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,19 +37,16 @@ pic_warnf(pic_state *pic, const char *fmt, ...)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
pic_errorf(pic_state *pic, const char *fmt, ...)
 | 
			
		||||
pic_error(pic_state *pic, const char *msg, int n, ...)
 | 
			
		||||
{
 | 
			
		||||
  va_list ap;
 | 
			
		||||
  const char *msg;
 | 
			
		||||
  pic_value err;
 | 
			
		||||
  pic_value irrs;
 | 
			
		||||
 | 
			
		||||
  va_start(ap, fmt);
 | 
			
		||||
  err = pic_vstrf_value(pic, fmt, ap);
 | 
			
		||||
  va_start(ap, n);
 | 
			
		||||
  irrs = pic_vlist(pic, n, ap);
 | 
			
		||||
  va_end(ap);
 | 
			
		||||
 | 
			
		||||
  msg = pic_str(pic, err);
 | 
			
		||||
 | 
			
		||||
  pic_raise(pic, pic_make_error(pic, "", msg, pic_nil_value(pic)));
 | 
			
		||||
  pic_raise(pic, pic_make_error(pic, "", msg, irrs));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
| 
						 | 
				
			
			@ -151,7 +148,7 @@ pic_raise(pic_state *pic, pic_value err)
 | 
			
		|||
 | 
			
		||||
  pic_pop_handler(pic);
 | 
			
		||||
 | 
			
		||||
  pic_errorf(pic, "error handler returned with ~s on error ~s", val, err);
 | 
			
		||||
  pic_error(pic, "error handler returned", 2, val, err);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static pic_value
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -159,7 +159,7 @@ expand_defmacro(pic_state *pic, pic_value expr, pic_value env)
 | 
			
		|||
 | 
			
		||||
  val = pic_call(pic, pic_compile(pic, pic_expand(pic, pic_list_ref(pic, expr, 2), env)), 0);
 | 
			
		||||
  if (! pic_proc_p(pic, val)) {
 | 
			
		||||
    pic_errorf(pic, "macro definition \"~s\" evaluates to non-procedure object", pic_list_ref(pic, expr, 1));
 | 
			
		||||
    pic_error(pic, "macro definition evaluates to non-procedure object", 1, pic_list_ref(pic, expr, 1));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  define_macro(pic, uid, val);
 | 
			
		||||
| 
						 | 
				
			
			@ -179,7 +179,7 @@ expand_node(pic_state *pic, pic_value expr, pic_value env, pic_value deferred)
 | 
			
		|||
    pic_value mac;
 | 
			
		||||
 | 
			
		||||
    if (! pic_list_p(pic, expr)) {
 | 
			
		||||
      pic_errorf(pic, "cannot expand improper list: ~s", expr);
 | 
			
		||||
      pic_error(pic, "cannot expand improper list", 1, expr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (pic_id_p(pic, pic_car(pic, expr))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -516,7 +516,7 @@ analyze_node(pic_state *pic, analyze_scope *scope, pic_value obj)
 | 
			
		|||
    pic_value proc;
 | 
			
		||||
 | 
			
		||||
    if (! pic_list_p(pic, obj)) {
 | 
			
		||||
      pic_errorf(pic, "invalid expression given: ~s", obj);
 | 
			
		||||
      pic_error(pic, "invalid expression given", 1, obj);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    proc = pic_list_ref(pic, obj, 0);
 | 
			
		||||
| 
						 | 
				
			
			@ -1023,7 +1023,7 @@ codegen(pic_state *pic, codegen_context *cxt, pic_value obj, bool tailpos)
 | 
			
		|||
    codegen_call(pic, cxt, obj, tailpos);
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    pic_errorf(pic, "codegen: unknown AST type ~s", obj);
 | 
			
		||||
    pic_error(pic, "codegen: unknown AST type", 1, obj);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -100,7 +100,7 @@ typedef void (*pic_panicf)(pic_state *, const char *msg);
 | 
			
		|||
 | 
			
		||||
pic_panicf pic_atpanic(pic_state *, pic_panicf f);
 | 
			
		||||
PIC_NORETURN void pic_panic(pic_state *, const char *msg);
 | 
			
		||||
PIC_NORETURN void pic_errorf(pic_state *, const char *fmt, ...);
 | 
			
		||||
PIC_NORETURN void pic_error(pic_state *, const char *msg, int n, ...);
 | 
			
		||||
PIC_NORETURN void pic_raise(pic_state *, pic_value v);
 | 
			
		||||
pic_value pic_make_error(pic_state *, const char *type, const char *msg, pic_value irrs);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,9 +59,9 @@ pic_value pic_fdisplay(pic_state *, pic_value, xFILE *);
 | 
			
		|||
#define pic_push(pic, item, place) (place = pic_cons(pic, item, place))
 | 
			
		||||
#define pic_pop(pic, place) (place = pic_cdr(pic, place))
 | 
			
		||||
 | 
			
		||||
#define pic_assert_type(pic, v, type) do {                      \
 | 
			
		||||
    if (! pic_##type##_p(pic, v))                               \
 | 
			
		||||
      pic_errorf(pic, "expected " #type ", but got ~s", v);     \
 | 
			
		||||
#define pic_assert_type(pic, v, type) do {      \
 | 
			
		||||
    if (! pic_##type##_p(pic, v))               \
 | 
			
		||||
      pic_error(pic, #type " required", 1, v);  \
 | 
			
		||||
  } while (0)
 | 
			
		||||
 | 
			
		||||
#define pic_void(exec) pic_void_(PIC_GENSYM(ai), exec)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -159,16 +159,16 @@ pic_value pic_obj_value(void *ptr);
 | 
			
		|||
struct object *pic_obj_alloc(pic_state *, size_t, int type);
 | 
			
		||||
 | 
			
		||||
#define VALID_INDEX(pic, len, i) do {                                   \
 | 
			
		||||
    if (i < 0 || len <= i) pic_errorf(pic, "index out of range: %d", i); \
 | 
			
		||||
    if (i < 0 || len <= i) pic_error(pic, "index out of range", 1, pic_int_value(pic, i)); \
 | 
			
		||||
  } while (0)
 | 
			
		||||
#define VALID_RANGE(pic, len, s, e) do {                                \
 | 
			
		||||
    if (s < 0 || len < s) pic_errorf(pic, "invalid start index: %d", s); \
 | 
			
		||||
    if (e < s || len < e) pic_errorf(pic, "invalid end index: %d", e);  \
 | 
			
		||||
    if (s < 0 || len < s) pic_error(pic, "invalid start index", 1, pic_int_value(pic, s)); \
 | 
			
		||||
    if (e < s || len < e) pic_error(pic, "invalid end index", 1, pic_int_value(pic, e)); \
 | 
			
		||||
  } while (0)
 | 
			
		||||
#define VALID_ATRANGE(pic, tolen, at, fromlen, s, e) do {       \
 | 
			
		||||
    VALID_INDEX(pic, tolen, at);                                \
 | 
			
		||||
    VALID_RANGE(pic, fromlen, s, e);                            \
 | 
			
		||||
    if (tolen - at < e - s) pic_errorf(pic, "invalid range");   \
 | 
			
		||||
#define VALID_ATRANGE(pic, tolen, at, fromlen, s, e) do {               \
 | 
			
		||||
    VALID_INDEX(pic, tolen, at);                                        \
 | 
			
		||||
    VALID_RANGE(pic, fromlen, s, e);                                    \
 | 
			
		||||
    if (tolen - at < e - s) pic_error(pic, "invalid range", 0);        \
 | 
			
		||||
  } while (0)
 | 
			
		||||
 | 
			
		||||
pic_value pic_make_identifier(pic_state *, pic_value id, pic_value env);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -127,7 +127,7 @@ get_library(pic_state *pic, const char *lib)
 | 
			
		|||
  struct lib *libp;
 | 
			
		||||
 | 
			
		||||
  if ((libp = get_library_opt(pic, lib)) == NULL) {
 | 
			
		||||
    pic_errorf(pic, "library not found: %s", lib);
 | 
			
		||||
    pic_error(pic, "library not found", 1, pic_cstr_value(pic, lib));
 | 
			
		||||
  }
 | 
			
		||||
  return libp;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -175,7 +175,7 @@ pic_make_library(pic_state *pic, const char *lib)
 | 
			
		|||
 | 
			
		||||
  it = kh_put(ltable, h, pic_str(pic, name), &ret);
 | 
			
		||||
  if (ret == 0) {               /* if exists */
 | 
			
		||||
    pic_errorf(pic, "library name already in use: %s", lib);
 | 
			
		||||
    pic_error(pic, "library name already in use", pic_cstr_value(pic, lib));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  kh_val(h, it).name = pic_str_ptr(pic, name);
 | 
			
		||||
| 
						 | 
				
			
			@ -223,7 +223,7 @@ pic_import(pic_state *pic, const char *lib)
 | 
			
		|||
  while (pic_dict_next(pic, pic_obj_value(libp->exports), &it, &name, &realname)) {
 | 
			
		||||
    uid = pic_find_identifier(pic, realname, pic_obj_value(libp->env));
 | 
			
		||||
    if (! pic_weak_has(pic, pic->globals, uid) && ! pic_weak_has(pic, pic->macros, uid)) {
 | 
			
		||||
      pic_errorf(pic, "attempted to export undefined variable '~s'", realname);
 | 
			
		||||
      pic_error(pic, "attempted to export undefined variable", 1, realname);
 | 
			
		||||
    }
 | 
			
		||||
    pic_put_identifier(pic, name, uid, pic_obj_value(pic->lib->env));
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -292,14 +292,14 @@ pic_lib_library_import(pic_state *pic)
 | 
			
		|||
  libp = get_library(pic, lib);
 | 
			
		||||
 | 
			
		||||
  if (! pic_dict_has(pic, pic_obj_value(libp->exports), name)) {
 | 
			
		||||
    pic_errorf(pic, "library-import: variable is not exported '~s'", name);
 | 
			
		||||
    pic_error(pic, "library-import: variable is not exported", 1, name);
 | 
			
		||||
  } else {
 | 
			
		||||
    realname = pic_dict_ref(pic, pic_obj_value(libp->exports), name);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  uid = pic_find_identifier(pic, realname, pic_obj_value(libp->env));
 | 
			
		||||
  if (! pic_weak_has(pic, pic->globals, uid) && ! pic_weak_has(pic, pic->macros, uid)) {
 | 
			
		||||
    pic_errorf(pic, "attempted to export undefined variable '~s'", realname);
 | 
			
		||||
    pic_error(pic, "attempted to export undefined variable", 1, realname);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pic_put_identifier(pic, alias, uid, pic_obj_value(pic->lib->env));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,7 +59,6 @@ pic_number_exact(pic_state *pic)
 | 
			
		|||
  pic_value                                                             \
 | 
			
		||||
  name(pic_state *pic, pic_value a, pic_value b)                        \
 | 
			
		||||
  {                                                                     \
 | 
			
		||||
    PIC_NORETURN void pic_errorf(pic_state *, const char *, ...);       \
 | 
			
		||||
    double f;                                                           \
 | 
			
		||||
    if (pic_int_p(pic, a) && pic_int_p(pic, b)) {                       \
 | 
			
		||||
      f = (double)pic_int(pic, a) op (double)pic_int(pic, b);           \
 | 
			
		||||
| 
						 | 
				
			
			@ -73,7 +72,7 @@ pic_number_exact(pic_state *pic)
 | 
			
		|||
    } else if (pic_float_p(pic, a) && pic_int_p(pic, b)) {              \
 | 
			
		||||
      return pic_float_value(pic, pic_float(pic, a) op pic_int(pic, b)); \
 | 
			
		||||
    } else {                                                            \
 | 
			
		||||
      pic_errorf(pic, #name ": non-number operand given");              \
 | 
			
		||||
      pic_error(pic, #name ": non-number operand given", 0);              \
 | 
			
		||||
    }                                                                   \
 | 
			
		||||
    PIC_UNREACHABLE();                                                  \
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -87,7 +86,6 @@ pic_define_aop(pic_div, /, f == (int)f)
 | 
			
		|||
  bool                                                                  \
 | 
			
		||||
  name(pic_state *pic, pic_value a, pic_value b)                        \
 | 
			
		||||
  {                                                                     \
 | 
			
		||||
    PIC_NORETURN void pic_errorf(pic_state *, const char *, ...);       \
 | 
			
		||||
    if (pic_int_p(pic, a) && pic_int_p(pic, b)) {                       \
 | 
			
		||||
      return pic_int(pic, a) op pic_int(pic, b);                        \
 | 
			
		||||
    } else if (pic_float_p(pic, a) && pic_float_p(pic, b)) {            \
 | 
			
		||||
| 
						 | 
				
			
			@ -97,7 +95,7 @@ pic_define_aop(pic_div, /, f == (int)f)
 | 
			
		|||
    } else if (pic_float_p(pic, a) && pic_int_p(pic, b)) {              \
 | 
			
		||||
      return pic_float(pic, a) op pic_int(pic, b);                      \
 | 
			
		||||
    } else {                                                            \
 | 
			
		||||
      pic_errorf(pic, #name ": non-number operand given");              \
 | 
			
		||||
      pic_error(pic, #name ": non-number operand given", 0);              \
 | 
			
		||||
    }                                                                   \
 | 
			
		||||
    PIC_UNREACHABLE();                                                  \
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -165,10 +163,10 @@ DEFINE_AOP(mul, argv[0], do {
 | 
			
		|||
    return pic_int_value(pic, 1);
 | 
			
		||||
  } while (0))
 | 
			
		||||
DEFINE_AOP(sub, pic_sub(pic, pic_int_value(pic, 0), argv[0]), do {
 | 
			
		||||
    pic_errorf(pic, "-: at least one argument required");
 | 
			
		||||
    pic_error(pic, "-: at least one argument required", 0);
 | 
			
		||||
  } while (0))
 | 
			
		||||
DEFINE_AOP(div, pic_div(pic, pic_int_value(pic, 1), argv[0]), do {
 | 
			
		||||
    pic_errorf(pic, "/: at least one argument required");
 | 
			
		||||
    pic_error(pic, "/: at least one argument required", 0);
 | 
			
		||||
  } while (0))
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
| 
						 | 
				
			
			@ -224,7 +222,7 @@ pic_number_number_to_string(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "F|i", &f, &e, &radix);
 | 
			
		||||
 | 
			
		||||
  if (radix < 2 || radix > 36) {
 | 
			
		||||
    pic_errorf(pic, "number->string: invalid radix %d (between 2 and 36, inclusive)", radix);
 | 
			
		||||
    pic_error(pic, "number->string: invalid radix (between 2 and 36, inclusive)", 1, pic_int_value(pic, radix));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (e) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,7 +22,7 @@ pic_value
 | 
			
		|||
pic_car(pic_state *pic, pic_value obj)
 | 
			
		||||
{
 | 
			
		||||
  if (! pic_pair_p(pic, obj)) {
 | 
			
		||||
    pic_errorf(pic, "car: pair required, but got ~s", obj);
 | 
			
		||||
    pic_error(pic, "car: pair required", 1, obj);
 | 
			
		||||
  }
 | 
			
		||||
  return pic_pair_ptr(pic, obj)->car;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ pic_value
 | 
			
		|||
pic_cdr(pic_state *pic, pic_value obj)
 | 
			
		||||
{
 | 
			
		||||
  if (! pic_pair_p(pic, obj)) {
 | 
			
		||||
    pic_errorf(pic, "cdr: pair required, but got ~s", obj);
 | 
			
		||||
    pic_error(pic, "cdr: pair required", 1, obj);
 | 
			
		||||
  }
 | 
			
		||||
  return pic_pair_ptr(pic, obj)->cdr;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +40,7 @@ void
 | 
			
		|||
pic_set_car(pic_state *pic, pic_value obj, pic_value val)
 | 
			
		||||
{
 | 
			
		||||
  if (! pic_pair_p(pic, obj)) {
 | 
			
		||||
    pic_errorf(pic, "pair required");
 | 
			
		||||
    pic_error(pic, "pair required", 0);
 | 
			
		||||
  }
 | 
			
		||||
  pic_pair_ptr(pic, obj)->car = val;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -49,7 +49,7 @@ void
 | 
			
		|||
pic_set_cdr(pic_state *pic, pic_value obj, pic_value val)
 | 
			
		||||
{
 | 
			
		||||
  if (! pic_pair_p(pic, obj)) {
 | 
			
		||||
    pic_errorf(pic, "pair required");
 | 
			
		||||
    pic_error(pic, "pair required", 0);
 | 
			
		||||
  }
 | 
			
		||||
  pic_pair_ptr(pic, obj)->cdr = val;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -171,15 +171,10 @@ pic_length(pic_state *pic, pic_value obj)
 | 
			
		|||
{
 | 
			
		||||
  int c = 0;
 | 
			
		||||
 | 
			
		||||
  if (! pic_list_p(pic, obj)) {
 | 
			
		||||
    pic_errorf(pic, "length: expected list, but got ~s", obj);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  while (! pic_nil_p(pic, obj)) {
 | 
			
		||||
    obj = pic_cdr(pic, obj);
 | 
			
		||||
    ++c;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -477,7 +472,7 @@ pic_pair_map(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "l*", &proc, &argc, &args);
 | 
			
		||||
 | 
			
		||||
  if (argc == 0)
 | 
			
		||||
    pic_errorf(pic, "map: wrong number of arguments (1 for at least 2)");
 | 
			
		||||
    pic_error(pic, "map: wrong number of arguments (1 for at least 2)", 0);
 | 
			
		||||
 | 
			
		||||
  arg_list = pic_alloca(pic, sizeof(pic_value) * argc);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,7 +36,7 @@ pic_close_port(pic_state *pic, pic_value port)
 | 
			
		|||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if (xfclose(pic, file) == EOF) {
 | 
			
		||||
    pic_errorf(pic, "close-port: failure");
 | 
			
		||||
    pic_error(pic, "close-port: failure", 0);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -123,13 +123,13 @@ pic_port_close_port(pic_state *pic)
 | 
			
		|||
    if ((pic_fileno(pic, port)->flag & (flags)) != (flags)) {                      \
 | 
			
		||||
      switch (flags) {                                                  \
 | 
			
		||||
      case X_WRITE:                                                     \
 | 
			
		||||
        pic_errorf(pic, caller ": expected output port");               \
 | 
			
		||||
        pic_error(pic, caller ": output port required", 0);               \
 | 
			
		||||
      case X_READ:                                                      \
 | 
			
		||||
        pic_errorf(pic, caller ": expected input port");                \
 | 
			
		||||
        pic_error(pic, caller ": input port required", 0);                \
 | 
			
		||||
      }                                                                 \
 | 
			
		||||
    }                                                                   \
 | 
			
		||||
    if (pic_fileno(pic, port)->flag == 0) {                                        \
 | 
			
		||||
      pic_errorf(pic, caller ": expected open port");                   \
 | 
			
		||||
      pic_error(pic, caller ": open port required", 0);                   \
 | 
			
		||||
    }                                                                   \
 | 
			
		||||
  } while (0)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -164,7 +164,7 @@ pic_port_get_output_bytevector(pic_state *pic)
 | 
			
		|||
  assert_port_profile(port, X_WRITE, "get-output-bytevector");
 | 
			
		||||
 | 
			
		||||
  if (xfget_buf(pic, pic_fileno(pic, port), &buf, &len) < 0) {
 | 
			
		||||
    pic_errorf(pic, "port was not created by open-output-bytevector");
 | 
			
		||||
    pic_error(pic, "port was not created by open-output-bytevector", 0);
 | 
			
		||||
  }
 | 
			
		||||
  return pic_blob_value(pic, (unsigned char *)buf, len);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,16 @@
 | 
			
		|||
 | 
			
		||||
#define MIN(x,y) ((x) < (y) ? (x) : (y))
 | 
			
		||||
 | 
			
		||||
PIC_NORETURN static void
 | 
			
		||||
arg_error(pic_state *pic, int actual, bool varg, int expected)
 | 
			
		||||
{
 | 
			
		||||
  const char *msg;
 | 
			
		||||
 | 
			
		||||
  msg = pic_str(pic, pic_strf_value(pic, "wrong number of arguments (%d for %s%d)", actual, (varg ? "at least " : ""), expected));
 | 
			
		||||
 | 
			
		||||
  pic_error(pic, msg, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define GET_OPERAND(pic,n) ((pic)->ci->fp[(n)])
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -80,7 +90,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  if (argc < paramc || (paramc + optc < argc && ! rest)) {
 | 
			
		||||
    pic_errorf(pic, "pic_get_args: wrong number of arguments (%d for %s%d)", argc, rest? "at least " : "", paramc);
 | 
			
		||||
    arg_error(pic, argc, rest, paramc);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  va_start(ap, format);
 | 
			
		||||
| 
						 | 
				
			
			@ -121,7 +131,9 @@ pic_get_args(pic_state *pic, const char *format, ...)
 | 
			
		|||
        *data = pic_data(pic, v);
 | 
			
		||||
      }
 | 
			
		||||
      else {
 | 
			
		||||
        pic_errorf(pic, "pic_get_args: expected data type \"%s\", but got ~s", type->type_name, v);
 | 
			
		||||
        const char *msg;
 | 
			
		||||
        msg = pic_str(pic, pic_strf_value(pic, "pic_get_args: data type \"%s\" required", type->type_name));
 | 
			
		||||
        pic_error(pic, msg, 1, v);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -139,7 +151,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
 | 
			
		|||
        if (buf) *buf = tmp;
 | 
			
		||||
      }
 | 
			
		||||
      else {
 | 
			
		||||
        pic_errorf(pic, "pic_get_args: expected bytevector, but got ~s", v);
 | 
			
		||||
        pic_error(pic, "pic_get_args: bytevector required", 1, v);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -155,16 +167,16 @@ pic_get_args(pic_state *pic, const char *format, ...)
 | 
			
		|||
                                                                        \
 | 
			
		||||
        v = GET_OPERAND(pic, i);                                        \
 | 
			
		||||
        switch (pic_type(pic, v)) {                                     \
 | 
			
		||||
        case PIC_TYPE_FLOAT:                                              \
 | 
			
		||||
        case PIC_TYPE_FLOAT:                                            \
 | 
			
		||||
          *n = pic_float(pic, v);                                       \
 | 
			
		||||
          *e = false;                                                   \
 | 
			
		||||
          break;                                                        \
 | 
			
		||||
        case PIC_TYPE_INT:                                                \
 | 
			
		||||
        case PIC_TYPE_INT:                                              \
 | 
			
		||||
          *n = pic_int(pic, v);                                         \
 | 
			
		||||
          *e = true;                                                    \
 | 
			
		||||
          break;                                                        \
 | 
			
		||||
        default:                                                        \
 | 
			
		||||
          pic_errorf(pic, "pic_get_args: expected float or int, but got ~s", v); \
 | 
			
		||||
          pic_error(pic, "pic_get_args: float or int required", 1, v);  \
 | 
			
		||||
        }                                                               \
 | 
			
		||||
        break;                                                          \
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -183,7 +195,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
 | 
			
		|||
          *ptr = conv;                                                  \
 | 
			
		||||
        }                                                               \
 | 
			
		||||
        else {                                                          \
 | 
			
		||||
          pic_errorf(pic, "pic_get_args: expected " #type ", but got ~s", v); \
 | 
			
		||||
          pic_error(pic, "pic_get_args: " #type " required", 1, v);     \
 | 
			
		||||
        }                                                               \
 | 
			
		||||
        break;                                                          \
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -202,7 +214,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
 | 
			
		|||
    OBJ_CASE('r', rec)
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
      pic_errorf(pic, "pic_get_args: invalid argument specifier '%c' given", c);
 | 
			
		||||
      pic_error(pic, "pic_get_args: invalid argument specifier given", 1, pic_char_value(pic, c));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (format[1] == '+') {
 | 
			
		||||
| 
						 | 
				
			
			@ -232,11 +244,11 @@ vm_gref(pic_state *pic, pic_value uid)
 | 
			
		|||
  pic_value val;
 | 
			
		||||
 | 
			
		||||
  if (! pic_weak_has(pic, pic->globals, uid)) {
 | 
			
		||||
    pic_errorf(pic, "undefined variable ~s", uid);
 | 
			
		||||
    pic_error(pic, "undefined variable", 1, uid);
 | 
			
		||||
  }
 | 
			
		||||
  val = pic_weak_ref(pic, pic->globals, uid);;
 | 
			
		||||
  if (pic_invalid_p(pic, val)) {
 | 
			
		||||
    pic_errorf(pic, "uninitialized global variable: ~s", uid);
 | 
			
		||||
    pic_error(pic, "uninitialized global variable", 1, uid);
 | 
			
		||||
  }
 | 
			
		||||
  return val;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -245,7 +257,7 @@ static void
 | 
			
		|||
vm_gset(pic_state *pic, pic_value uid, pic_value value)
 | 
			
		||||
{
 | 
			
		||||
  if (! pic_weak_has(pic, pic->globals, uid)) {
 | 
			
		||||
    pic_errorf(pic, "undefined variable ~s", uid);
 | 
			
		||||
    pic_error(pic, "undefined variable", 1, uid);
 | 
			
		||||
  }
 | 
			
		||||
  pic_weak_set(pic, pic->globals, uid, value);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -488,7 +500,7 @@ pic_apply(pic_state *pic, pic_value proc, int argc, pic_value *argv)
 | 
			
		|||
    L_CALL:
 | 
			
		||||
      x = pic->sp[-c.a];
 | 
			
		||||
      if (! pic_proc_p(pic, x)) {
 | 
			
		||||
	pic_errorf(pic, "invalid application: ~s", x);
 | 
			
		||||
	pic_error(pic, "invalid application", 1, x);
 | 
			
		||||
      }
 | 
			
		||||
      proc = pic_proc_ptr(pic, x);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -521,7 +533,7 @@ pic_apply(pic_state *pic, pic_value proc, int argc, pic_value *argv)
 | 
			
		|||
        ci->irep = irep;
 | 
			
		||||
	if (ci->argc != irep->argc) {
 | 
			
		||||
	  if (! (irep->varg && ci->argc >= irep->argc)) {
 | 
			
		||||
            pic_errorf(pic, "wrong number of arguments (%d for %s%d)", ci->argc - 1, (irep->varg ? "at least " : ""), irep->argc - 1);
 | 
			
		||||
            arg_error(pic, ci->argc - 1, irep->varg, irep->argc - 1);
 | 
			
		||||
	  }
 | 
			
		||||
	}
 | 
			
		||||
	/* prepare rest args */
 | 
			
		||||
| 
						 | 
				
			
			@ -909,7 +921,7 @@ pic_closure_ref(pic_state *pic, int n)
 | 
			
		|||
  assert(pic_func_p(self));
 | 
			
		||||
 | 
			
		||||
  if (n < 0 || pic_proc_ptr(pic, self)->u.f.localc <= n) {
 | 
			
		||||
    pic_errorf(pic, "pic_closure_ref: index out of range (%d)", n);
 | 
			
		||||
    pic_error(pic, "pic_closure_ref: index out of range", 1, pic_int_value(pic, n));
 | 
			
		||||
  }
 | 
			
		||||
  return pic_proc_ptr(pic, self)->locals[n];
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -922,7 +934,7 @@ pic_closure_set(pic_state *pic, int n, pic_value v)
 | 
			
		|||
  assert(pic_func_p(self));
 | 
			
		||||
 | 
			
		||||
  if (n < 0 || pic_proc_ptr(pic, self)->u.f.localc <= n) {
 | 
			
		||||
    pic_errorf(pic, "pic_closure_ref: index out of range (%d)", n);
 | 
			
		||||
    pic_error(pic, "pic_closure_ref: index out of range", 1, pic_int_value(pic, n));
 | 
			
		||||
  }
 | 
			
		||||
  pic_proc_ptr(pic, self)->locals[n] = v;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1019,7 +1031,7 @@ pic_proc_apply(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "l*", &proc, &argc, &args);
 | 
			
		||||
 | 
			
		||||
  if (argc == 0) {
 | 
			
		||||
    pic_errorf(pic, "apply: wrong number of arguments");
 | 
			
		||||
    pic_error(pic, "apply: wrong number of arguments", 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  n = argc - 1 + pic_length(pic, args[argc - 1]);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -276,7 +276,7 @@ pic_str_ref(pic_state *pic, pic_value str, int i)
 | 
			
		|||
 | 
			
		||||
  c = rope_at(pic_str_ptr(pic, str)->rope, i);
 | 
			
		||||
  if (c == -1) {
 | 
			
		||||
    pic_errorf(pic, "index out of range %d", i);
 | 
			
		||||
    pic_error(pic, "index out of range", 1, pic_int_value(pic, i));
 | 
			
		||||
  }
 | 
			
		||||
  return (char)c;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -453,7 +453,7 @@ pic_str_make_string(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "i|c", &len, &c);
 | 
			
		||||
 | 
			
		||||
  if (len < 0) {
 | 
			
		||||
    pic_errorf(pic, "make-string: negative length given %d", len);
 | 
			
		||||
    pic_error(pic, "make-string: negative length given", 1, pic_int_value(pic, len));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  buf = pic_alloca(pic, len);
 | 
			
		||||
| 
						 | 
				
			
			@ -647,7 +647,7 @@ pic_str_string_map(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "l*", &proc, &argc, &argv);
 | 
			
		||||
 | 
			
		||||
  if (argc == 0) {
 | 
			
		||||
    pic_errorf(pic, "string-map: one or more strings expected, but got zero");
 | 
			
		||||
    pic_error(pic, "string-map: one or more strings expected, but got zero", 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  len = INT_MAX;
 | 
			
		||||
| 
						 | 
				
			
			@ -684,7 +684,7 @@ pic_str_string_for_each(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "l*", &proc, &argc, &argv);
 | 
			
		||||
 | 
			
		||||
  if (argc == 0) {
 | 
			
		||||
    pic_errorf(pic, "string-map: one or more strings expected, but got zero");
 | 
			
		||||
    pic_error(pic, "string-map: one or more strings expected, but got zero", 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  len = INT_MAX;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -146,7 +146,7 @@ pic_symbol_identifier_base(pic_state *pic)
 | 
			
		|||
  pic_assert_type(pic, id, id);
 | 
			
		||||
 | 
			
		||||
  if (pic_sym_p(pic, id)) {
 | 
			
		||||
    pic_errorf(pic, "expected non-symbol identifier, but got symbol ~s", id);
 | 
			
		||||
    pic_error(pic, "non-symbol identifier required", 1, id);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return pic_obj_value(pic_id_ptr(pic, id)->u.id);
 | 
			
		||||
| 
						 | 
				
			
			@ -162,7 +162,7 @@ pic_symbol_identifier_environment(pic_state *pic)
 | 
			
		|||
  pic_assert_type(pic, id, id);
 | 
			
		||||
 | 
			
		||||
  if (pic_sym_p(pic, id)) {
 | 
			
		||||
    pic_errorf(pic, "expected non-symbol identifier, but got symbol ~s", id);
 | 
			
		||||
    pic_error(pic, "non-symbol identifier required", 1, id);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return pic_obj_value(pic_id_ptr(pic, id)->env);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -256,6 +256,6 @@ pic_typename(pic_state *pic, int type)
 | 
			
		|||
  case PIC_TYPE_CP:
 | 
			
		||||
    return "checkpoint";
 | 
			
		||||
  default:
 | 
			
		||||
    pic_errorf(pic, "pic_typename: invalid type given %d", type);
 | 
			
		||||
    pic_error(pic, "pic_typename: invalid type given", 1, pic_int_value(pic, type));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,7 +73,7 @@ pic_vec_make_vector(pic_state *pic)
 | 
			
		|||
  n = pic_get_args(pic, "i|o", &k, &init);
 | 
			
		||||
 | 
			
		||||
  if (k < 0) {
 | 
			
		||||
    pic_errorf(pic, "make-vector: negative length given %d", k);
 | 
			
		||||
    pic_error(pic, "make-vector: negative length given", 1, pic_int_value(pic, k));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  vec = pic_make_vec(pic, k, NULL);
 | 
			
		||||
| 
						 | 
				
			
			@ -231,7 +231,7 @@ pic_vec_vector_map(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "l*", &proc, &argc, &argv);
 | 
			
		||||
 | 
			
		||||
  if (argc == 0) {
 | 
			
		||||
    pic_errorf(pic, "vector-map: wrong number of arguments (1 for at least 2)");
 | 
			
		||||
    pic_error(pic, "vector-map: wrong number of arguments (1 for at least 2)", 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  len = INT_MAX;
 | 
			
		||||
| 
						 | 
				
			
			@ -265,7 +265,7 @@ pic_vec_vector_for_each(pic_state *pic)
 | 
			
		|||
  pic_get_args(pic, "l*", &proc, &argc, &argv);
 | 
			
		||||
 | 
			
		||||
  if (argc == 0) {
 | 
			
		||||
    pic_errorf(pic, "vector-for-each: wrong number of arguments (1 for at least 2)");
 | 
			
		||||
    pic_error(pic, "vector-for-each: wrong number of arguments (1 for at least 2)", 0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  len = INT_MAX;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ pic_weak_ref(pic_state *pic, pic_value weak, pic_value key)
 | 
			
		|||
 | 
			
		||||
  it = kh_get(weak, h, pic_obj_ptr(key));
 | 
			
		||||
  if (it == kh_end(h)) {
 | 
			
		||||
    pic_errorf(pic, "element not found for a key: ~s", key);
 | 
			
		||||
    pic_error(pic, "element not found for given key", 1, key);
 | 
			
		||||
  }
 | 
			
		||||
  return kh_val(h, it);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +59,7 @@ pic_weak_del(pic_state *pic, pic_value weak, pic_value key)
 | 
			
		|||
 | 
			
		||||
  it = kh_get(weak, h, pic_obj_ptr(key));
 | 
			
		||||
  if (it == kh_end(h)) {
 | 
			
		||||
    pic_errorf(pic, "no slot named ~s found in ephemeron", key);
 | 
			
		||||
    pic_error(pic, "element not found for given key", 1, key);
 | 
			
		||||
  }
 | 
			
		||||
  kh_del(weak, h, it);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +74,7 @@ weak_call(pic_state *pic)
 | 
			
		|||
  n = pic_get_args(pic, "o|o", &key, &val);
 | 
			
		||||
 | 
			
		||||
  if (! pic_obj_p(pic, key)) {
 | 
			
		||||
    pic_errorf(pic, "attempted to set a non-object key '~s' in an ephemeron", key);
 | 
			
		||||
    pic_error(pic, "attempted to set a non-object key", 1, key);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  weak = pic_closure_ref(pic, 0);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue