mirror of
https://github.com/samsonjs/lake.git
synced 2026-03-25 08:55:49 +00:00
add int_repr
This commit is contained in:
parent
4299c51021
commit
6ef5fcb299
3 changed files with 9 additions and 8 deletions
11
src/int.c
11
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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue