From: Simon Forman Date: Fri, 23 Sep 2022 03:43:25 +0000 (-0700) Subject: At this point... X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=8cb04fc72d3fd3eb14d0841174c11e070c0aa7ee;p=joypy%2FThun.git At this point... ...I'm just relearning C semantics. (And they are garbage, as is widely known.) I don't think there's much point to this (at the moment) because I don't want to relearn C (at the moment) and Nim is available (at the moment.) Really, I'm trying to do away with the entire relationship of C et. al. to the underlying machine. (For instance, Nim gives you a much nicer relationship, without the vast distance that, say, Python imposes.) I should really look at other compiled languages, like Ocaml or Julia. --- diff --git a/implementations/C/joy b/implementations/C/joy index 22c6cf3..6697c3f 100755 Binary files a/implementations/C/joy and b/implementations/C/joy differ diff --git a/implementations/C/joy.c b/implementations/C/joy.c index 8e75d87..7037d66 100644 --- a/implementations/C/joy.c +++ b/implementations/C/joy.c @@ -1,31 +1,57 @@ #include #include -// 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; +enum JoyTypeType { + joySymbol, + joyTrue, + joyFalse, + joyInt, + joyList }; -#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 +typedef struct list_node* JoyList; -sexpr cons(sexpr a, sexpr b) { - sexpr tmp = {GC_MALLOC(sizeof(struct cons))}; - car(tmp) = a; cdr(tmp) = b; - return (tmp); -}; +typedef struct JoyType { + enum JoyTypeType kind; + union { + int b; // bool + mpz_t i; + JoyList el; + }; +} name ; + +typedef struct list_node { + struct JoyType head; + struct list_node* tail; +} *JoyList; + + +// 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);*/ +/*};*/ void* reallocate_function (void *ptr, size_t old_size, size_t new_size) { return GC_realloc(ptr, new_size); @@ -40,12 +66,12 @@ void my_callback(GC_PTR void_obj, GC_PTR void_environment) { mpz_clear(*obj); } -sexpr new_int(void) { - sexpr tmp = {GC_MALLOC(sizeof(struct cons))}; - mpz_init(tmp.i); - GC_register_finalizer(tmp.i, my_callback, NULL, NULL, NULL); - 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);*/ +/*}*/ int main(void) @@ -60,10 +86,10 @@ int main(void) mpz_init_set_str (pi, "25d0c79fe247f31777d922627a74624", 16); gmp_printf ("%Zd = %Zx\n", pi, pi); GC_register_finalizer(pi, my_callback, NULL, NULL, NULL); - - sexpr i = new_int(); - mpz_add(i.i, pi, pi); - gmp_printf ("%Zd\n", i.i); + + /*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))));