From cf7afa1e54b7cc9d7a738c09f44faad5810ea379 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 30 Oct 2011 23:55:42 +0900 Subject: [PATCH] adding type printer accessor --- lib/chibi/ast.c | 6 ++++++ lib/chibi/ast.sld | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/chibi/ast.c b/lib/chibi/ast.c index 06fc0ca6..51e7c16d 100644 --- a/lib/chibi/ast.c +++ b/lib/chibi/ast.c @@ -175,6 +175,11 @@ static sexp sexp_type_slots_op (sexp ctx sexp_api_params(self, n), sexp t) { return sexp_type_slots(t); } +static sexp sexp_type_printer_op (sexp ctx sexp_api_params(self, n), sexp t) { + sexp_assert_type(ctx, sexp_typep, SEXP_TYPE, t); + return sexp_type_print(t) ? sexp_make_foreign(ctx, "print", 3, 0, (sexp_proc1)sexp_type_print(t), NULL) : SEXP_FALSE; +} + static sexp sexp_object_size (sexp ctx sexp_api_params(self, n), sexp x) { sexp t; if ((! sexp_pointerp(x)) || (sexp_pointer_tag(x) >= sexp_context_num_types(ctx))) @@ -408,6 +413,7 @@ sexp sexp_init_library (sexp ctx sexp_api_params(self, n), sexp env) { sexp_define_foreign(ctx, env, "type-name", 1, sexp_type_name_op); sexp_define_foreign(ctx, env, "type-cpl", 1, sexp_type_cpl_op); sexp_define_foreign(ctx, env, "type-slots", 1, sexp_type_slots_op); + sexp_define_foreign(ctx, env, "type-printer", 1, sexp_type_printer_op); sexp_define_foreign(ctx, env, "object-size", 1, sexp_object_size); sexp_define_foreign_opt(ctx, env, "integer->immediate", 2, sexp_integer_to_immediate, SEXP_FALSE); sexp_define_foreign(ctx, env, "gc", 0, sexp_gc_op); diff --git a/lib/chibi/ast.sld b/lib/chibi/ast.sld index ecb3aa4d..49da26dd 100644 --- a/lib/chibi/ast.sld +++ b/lib/chibi/ast.sld @@ -30,7 +30,7 @@ bytecode-name bytecode-literals bytecode-source pair-source pair-source-set! port-line port-line-set! - type-name type-cpl type-parent type-slots + type-name type-cpl type-parent type-slots type-printer object-size integer->immediate gc string-contains integer->error-string flatten-dot update-free-vars!)