OSDN Git Service

Working on README, put defs in joy.py
[joypy/Thun.git] / implementations / C / notes
1
2
3     >>> 23 * 12345.6789
4     283950.61470000003
5
6     joy? 23 123456789 *
7     2839506147
8
9     joy? 10000 /
10     283950
11
12 eh?
13
14 See that "0000003" at the end of the float?
15 Floating point numbers /suck/, we only use them because
16 computers were small and slow.  Now that they are large
17 (sixty-four bits per word!?  Holy shit!) and fast, so
18 floating point is no longer necessary.
19
20 (However, in practice, we will still be using it, because
21 it's been turd-polished to such a high sheen.  GPUs are
22 monsters!  But most of us have no use for supercomputers
23 outside of playing fancy games.)
24
25 ---------------------------------------
26
27
28
29
30 With a little bit of complexity we could improve efficiency (e.g. using
31 VList instead of singly-linked list.)  But I want to tackle efficiency by
32 compilation, and write the compiler(s) in Prolog.  I think that avoids
33 complexity compared to intricating the guts of the interpreter by hand,
34 and moves the unavoidable complexity into formal statements of logic that
35 can be evaluated by machine (aka Prolog.)
36
37 ---------------------------------------
38
39 So how do we want to handle definitions?  Read a defs.txt file at
40 compile time?  Build defs.c from defs.txt?
41
42 void
43 defname(JoyListPtr stack, JoyListPtr expression)
44 {
45         def_node = some C initializer?
46         def_node = text_to_expression("dup mul");
47         push_quote(def_node, expression);
48 }
49
50 ...?
51
52 I think the easiest thing to do at the mo' would be to hardcode the defs
53 as an array of strings and then read them and convert at start time?
54
55
56
57
58
59
60
61
62
63
64
65
66         /*mpz_t pi;*/
67         /*char *text = (char *)TEXT;*/
68         /*mpz_init_set_str(pi, "3141592653589793238462643383279502884", 10);*/
69         /*mpz_init_set_str(pi, "25d0c79fe247f31777d922627a74624", 16);*/
70         /*GC_register_finalizer(pi, my_callback, NULL, NULL, NULL);*/
71
72         /*el = push_integer_from_str("3141592653589793238462643383279502884", 0);*/
73         /*el->tail = text_to_expression(text);*/
74         /*el = text_to_expression(text);*/
75         /*print_list(el);*/
76         /*printf("\n");*/
77
78   concat
79 cons
80 dip
81 dup
82 first
83 loop
84 pop
85 rest
86 stack
87 swaack
88 swap
89
90
91 pop_any(), pop_int(), and add
92
93 With cmp (provided by the GMP lib) we can implement the rest of
94 the comparison functions as definitions:
95
96      G       E       L
97  eq [false] [true] [false] cmp
98  gt [true] [false] [false] cmp
99  lt [false] [false] [true] cmp
100 neq [true] [false] [true] cmp
101  le [false] [true] [true] cmp
102  ge [true] [true] [false] cmp
103  
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 ---------------------------------- 
127 Argh!  That was brutal.
128
129 I hate staring at the thing that SHOULD work and it just fucking doesn't work.
130
131 Why?  Because some fuck-wit somewhere decided to fuck up how things have always been done.
132
133 https://stackoverflow.com/questions/12734161/how-to-use-boehm-garbage-collector-in-ubuntu-12-04
134
135 > To answer my own question: actually, the Boehm GC library still works the same way as it used to in 12.04.  The problem is that GCC doesn't! GCC has started to default to --as-needed, and it drops -lgc completely if it is at the beginning of the line. This is a very major change!!
136
137 > Solution is to move -lgc to the end:
138
139 > gcc test.c -lgc
140
141 > Or add:
142
143 > gcc -Wl,--as-needed -lgc test.c
144
145
146
147 Goddamnit!