From 6ef5fcb2999bb2bf654b4df2191cb311d65c2cb4 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 24 Apr 2011 20:39:22 -0700 Subject: [PATCH] add int_repr --- src/int.c | 11 +++++++---- src/int.h | 1 + src/lake.c | 5 +---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/int.c b/src/int.c index 739fc48..51c5e50 100644 --- a/src/int.c +++ b/src/int.c @@ -22,9 +22,7 @@ static LakeInt *int_alloc(void) LakeInt *int_make(void) { - LakeInt *i = int_alloc(); - i->val = 0; - return i; + return int_from_c(0); } LakeInt *int_from_c(int n) @@ -34,9 +32,14 @@ LakeInt *int_from_c(int n) return i; } +char *int_repr(LakeInt *i) +{ + return g_strdup_printf("%d", i->val); +} + LakeStr *int_to_str(LakeInt *i) { - char *s = g_strdup_printf("%d", i->val); + char *s = int_repr(i); LakeStr *str = str_from_c(s); g_free(s); return str; diff --git a/src/int.h b/src/int.h index 547ed35..05ac4f5 100644 --- a/src/int.h +++ b/src/int.h @@ -15,5 +15,6 @@ LakeInt *int_make(void); LakeInt *int_from_c(int n); LakeStr *int_to_str(LakeInt *i); +char *int_repr(LakeInt *i); #endif \ No newline at end of file diff --git a/src/lake.c b/src/lake.c index 29ec540..c0ec6a6 100644 --- a/src/lake.c +++ b/src/lake.c @@ -25,7 +25,6 @@ char *lake_repr(LakeVal *expr) if (expr == NULL) return g_strdup("(null)"); char *s = NULL; - LakeStr *str; switch (expr->type) { @@ -38,9 +37,7 @@ char *lake_repr(LakeVal *expr) break; case TYPE_INT: - str = int_to_str(INT(expr)); - s = str_val(str); - str_free(str); + s = int_repr(INT(expr)); break; case TYPE_STR: