From b09055f299b7b8af70f4bce14a8dc0a61d084964 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Wed, 1 Feb 2023 20:28:24 -0800 Subject: [PATCH] Print ints. --- implementations/C/joy.c | 17 +++++--------- implementations/C/notes | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 implementations/C/notes diff --git a/implementations/C/joy.c b/implementations/C/joy.c index bd1f748..8cbcd2f 100644 --- a/implementations/C/joy.c +++ b/implementations/C/joy.c @@ -86,7 +86,7 @@ make_symbol_node(char *text, size_t size) node->head.kind = joySymbol; node->head.value.symbol = (char *)GC_malloc(size + 1); strncat(node->head.value.symbol, text, size); - printf("%s\n", node->head.value.symbol); + /*printf("%s\n", node->head.value.symbol);*/ return node; } @@ -166,6 +166,9 @@ void print_node(struct JoyType j) { switch (j.kind) { + case joyInt: + gmp_printf("%Zd", j.value.i); + break; case joySymbol: printf("%s", j.value.symbol); break; @@ -194,6 +197,7 @@ main(void) { mpz_t pi; struct list_node* el; + char *text = (char *)TEXT; mp_set_memory_functions( &GC_malloc, @@ -204,17 +208,8 @@ main(void) /*mpz_init_set_str(pi, "25d0c79fe247f31777d922627a74624", 16);*/ GC_register_finalizer(pi, my_callback, NULL, NULL, NULL); - gmp_printf("%Zd = %Zx\n", pi, pi); - mpz_mul(pi, pi, pi); - gmp_printf("%Zd = %Zx\n", pi, pi); - el = push_integer_from_str("3141592653589793238462643383279502884", 0); - el = text_to_expression("char *te xt"); + el->tail = text_to_expression(text); print_list(el); - /*sexpr i = new_int();*/ - /*mpz_add(i.i, pi, pi);*/ - /*gmp_printf ("%Zd\n", i.i);*/ return 0; - - /*return to_i(car(cons(from_i(0),from_i(1))));*/ } diff --git a/implementations/C/notes b/implementations/C/notes new file mode 100644 index 0000000..6b8520c --- /dev/null +++ b/implementations/C/notes @@ -0,0 +1,49 @@ + +// Example S-exprs +// https://www.hboehm.info/gc/04tutorial.pdf +/**/ +/*typedef union se*/ +/*{*/ +/* struct cons * cp;*/ +/* mpz_t i;*/ +/*} sexpr;*/ +/**/ +/*struct cons*/ +/*{*/ +/* union se head;*/ +/* union se tail;*/ +/*};*/ +/**/ +/*#define car(s) (s).cp->head*/ +/*#define cdr(s) (s).cp->tail*/ +/*#define from_i(z) ({sexpr tmp; tmp.i=z; tmp;})*/ +/*#define to_i(s) (s).i*/ +/**/ +/*sexpr cons(sexpr a, sexpr b) {*/ +/* sexpr tmp = {GC_MALLOC(sizeof(struct cons))};*/ +/* car(tmp) = a; cdr(tmp) = b;*/ +/* return (tmp);*/ +/*};*/ + + + +/*sexpr new_int(void) {*/ +/* sexpr node = {GC_MALLOC(sizeof(struct cons))};*/ +/* mpz_init(node.i);*/ +/* GC_register_finalizer(node.i, my_callback, NULL, NULL, NULL);*/ +/* return (node);*/ +/*}*/ + + +typedef struct list_node* JoyList; + + + + /*sexpr i = new_int();*/ + /*mpz_add(i.i, pi, pi);*/ + /*gmp_printf ("%Zd\n", i.i);*/ + /*return to_i(car(cons(from_i(0),from_i(1))));*/ + + /*gmp_printf("%Zd = %Zx\n", pi, pi);*/ + /*mpz_mul(pi, pi, pi);*/ + /*gmp_printf("%Zd = %Zx\n", pi, pi);*/