Skip to content

Commit 4a4a944

Browse files
removed limo_cons. conses are now inside the limo_data. speedup
1 parent deeef65 commit 4a4a944

File tree

17 files changed

+181
-202
lines changed

17 files changed

+181
-202
lines changed

builtins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ BUILTIN(builtin_setcar)
256256
limo_data *cons = eval(FIRST_ARG, env);
257257
limo_data *value = eval(SECOND_ARG, env);
258258

259-
if (cons->type != limo_TYPE_CONS || cons->d_cons == NULL)
259+
if (cons->type != limo_TYPE_CONS)
260260
limo_error("ERROR: (setcar CONS value)");
261261

262262
CAR(cons) = value;
@@ -270,7 +270,7 @@ BUILTIN(builtin_setcdr)
270270
limo_data *cons = eval(FIRST_ARG, env);
271271
limo_data *value = eval(SECOND_ARG, env);
272272

273-
if (cons->type != limo_TYPE_CONS || cons->d_cons == NULL)
273+
if (cons->type != limo_TYPE_CONS)
274274
limo_error("ERROR: (setcdr CONS value)");
275275

276276
CDR(cons) = value;

dict.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ inline int limo_equals(limo_data *a, limo_data *b)
2828
return !strncmp(a->d_string, b->d_string, a->hash);
2929

3030
case limo_TYPE_CONS:
31-
return a->d_cons == b->d_cons;
31+
return CAR(a) == CAR(b) && CDR(a) == CDR(b);
3232

3333
case limo_TYPE_GMPQ:
3434
return !mpq_cmp(LIMO_MPQ(a), LIMO_MPQ(b));
35+
36+
case limo_TYPE_NIL:
37+
return b->type == limo_TYPE_NIL;
3538
}
3639

3740
return 0;
@@ -101,7 +104,7 @@ limo_dict *make_dict_size(int minused)
101104
return d;
102105
}
103106

104-
void dict_resize(limo_data *dict)
107+
inline void dict_resize(limo_data *dict)
105108
{
106109
limo_data new = *dict;
107110
limo_dict *olddict = dict->d_dict;
@@ -117,7 +120,7 @@ void dict_resize(limo_data *dict)
117120
dict->d_dict = newdict;
118121
}
119122

120-
void dict_check_resize(limo_data *dict)
123+
inline void dict_check_resize(limo_data *dict)
121124
{
122125
if (3 * (dict->d_dict->used) > 2*dict->d_dict->size)
123126
dict_resize(dict);
@@ -127,8 +130,8 @@ void dict_put_cons_ex(limo_data *dict, limo_data *cons, int flags)
127130
{
128131
limo_dict_item *ld_place;
129132

130-
if (dict->type != limo_TYPE_DICT)
131-
limo_error("dict_put(): didn't get a dict.");
133+
/* if (dict->type != limo_TYPE_DICT) */
134+
/* limo_error("dict_put(): didn't get a dict."); */
132135

133136
ld_place = dict_get_place(dict, CAR(cons));
134137
if (ld_place->cons == NULL) {

eval.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ limo_data *eval(limo_data *form, limo_data *env) // tail recursion :D
159159
limo_data *stacktrace_cons;
160160

161161
limo_data thunk;
162-
limo_cons thunk_cons;
163162
thunk.type = limo_TYPE_THUNK;
164-
thunk.d_cons = &thunk_cons;
165163

166164
if (limo_register) { // TODO: here is a check of "things". could be used to signal Ctrl-c
167165
if (limo_register & LR_SIGINT) {
@@ -177,25 +175,20 @@ limo_data *eval(limo_data *form, limo_data *env) // tail recursion :D
177175

178176
stacktrace_cons = make_cons(form, tmp_stacktrace);
179177
pk_stacktrace_set(stacktrace_cons);
180-
for (;;) {
181-
form=real_eval(form, env, &thunk);
182-
assert(form);
183-
assert(form->type != limo_TYPE_CONST);
184-
185-
if (form->type == limo_TYPE_THUNK) {
186-
limo_data *next_form;
187-
// printf("THUNK:"); writer(form); printf("\n");
188-
next_form= CDR(form);
189-
env = CAR(form);
190-
form = next_form;
191-
CAR(stacktrace_cons) = form;
192-
}
193-
else {
194-
pk_stacktrace_set(tmp_stacktrace);
195-
return form;
196-
}
197-
}
198178

179+
form=real_eval(form, env, &thunk);
180+
while (form->type == limo_TYPE_THUNK) {
181+
limo_data *next_form;
182+
// printf("THUNK:"); writer(form); printf("\n");
183+
next_form= CDR(form);
184+
env = CAR(form);
185+
form = next_form;
186+
CAR(stacktrace_cons) = form;
187+
188+
form = real_eval(form, env, &thunk);
189+
}
190+
pk_stacktrace_set(tmp_stacktrace);
191+
return form;
199192
}
200193

201194
limo_data *real_eval(limo_data *ld, limo_data *env, limo_data *thunk_place)

examples/autosnake.limo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
(defun shuffle (l)
3030
(when l
3131
(setq r (random (list-length l)))
32-
(cons (nth r l) (shuffle (remove-nth l r)))))
32+
(dcons (nth r l) (shuffle (remove-nth l r)))))
3333

3434
(defun random-choice (l)
3535
(nth (random (list-length l)) l))

examples/autosnake2.limo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
(:else
220220
(cons (car bs) (remove-as as (cdr bs))))))
221221
(freezeq remove-as)
222-
(let* ((ssnake (qsort tuple-lt snake))
222+
(let* ((ssnake (sort tuple-lt snake))
223223
(pot-apple-fields (remove-as ssnake *all-fields*)))
224224
(if pot-apple-fields
225225
(random-choice pot-apple-fields)
@@ -280,7 +280,7 @@
280280
(cons (wn-get (car headpos) (+ (cdr headpos) 1))
281281
(cons (car headpos)
282282
(+ (cdr headpos) 1)))))))
283-
(moves-most-ahead (qsort (lambda (m n) (> (norm-to-tail (car m) tailwn)
283+
(moves-most-ahead (sort (lambda (m n) (> (norm-to-tail (car m) tailwn)
284284
(norm-to-tail (car n) tailwn)))
285285
moves)))
286286
(if (or *circlestrat*

examples/mandelbrot.limo

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
(setq *surface* ([_sdl . sdl-setvideomode] 640 480 24 [_sdl . sdl_hwsurface]))
1212

13-
(freezeq +)
14-
(freezeq -)
15-
(freezeq /)
16-
(freezeq *)
17-
1813
(defun bit (n v)
1914
(mod (floor (/ v n)) 2))
2015

@@ -26,20 +21,6 @@
2621
(* 255 (bit 4 n))))
2722
(range 0 17 1))))
2823

29-
(defun sqrt (x)
30-
(block fun
31-
(let ((lo 0)
32-
(hi x)
33-
(mid (/ x 2)))
34-
(for-each i (drange 0 10 1)
35-
(setq sqr (* mid mid))
36-
(cond ((= sqr x) (return-from fun mid))
37-
((< sqr x) (setf lo mid))
38-
(:t (setf hi mid)))
39-
(setf mid (/ (+ hi lo) 2)))
40-
mid)))
41-
(freezeq sqrt)
42-
4324
(defun csqr (c)
4425
(cons (- (* (car c) (car c))
4526
(* (cdr c) (cdr c)))
@@ -51,10 +32,6 @@
5132
(+ (cdr a) (cdr b))))
5233
(freezeq cadd)
5334

54-
(defun cabs (c)
55-
(sqrt (+ (* (car c) (car c)) (* (cdr c) (cdr c)))))
56-
(freezeq cabs)
57-
5835
(defun mandelbrot (x y)
5936
(block fun
6037
(progn

examples/tetris.limo

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(mod-load "ncurses")
1+
(import "ncurses.limo")
22

33
(defun min (a b)
44
(if (< a b) a b))
@@ -75,35 +75,35 @@
7575
(() :t :t)
7676
(() :t ())))))
7777

78-
(defclass screen ()
79-
(defmethod init (self scr)
80-
(setmember [self . _scr] scr))
81-
(defmethod keypad (self onoff)
82-
([_ncurses . keypad] [self . _scr] onoff))
83-
(defmethod move (self y x)
84-
([_ncurses . wmove] [self . _scr] y x))
85-
(defmethod addch (self c)
86-
([_ncurses . waddch] [self . _scr] c))
87-
(defmethod refresh (self)
88-
([_ncurses . wrefresh] [self . _scr]))
89-
(defmethod getch (self)
90-
([_ncurses . wgetch] [self . _scr]))
91-
(defmethod erase (self)
92-
([_ncurses . werase] [self . _scr]))
93-
(defmethod print-with-attr (self str attr)
94-
(for-each c (string-to-list str)
95-
[self addch (+ (ord c) attr)]))
96-
(defmethod nodelay (self bf)
97-
([_ncurses . nodelay] [self . _scr] bf))
98-
(defmethod halfdelay (self tenths)
99-
([_ncurses . halfdelay] tenths)))
78+
;; (defclass screen ()
79+
;; (defmethod init (self scr)
80+
;; (setmember [self . _scr] scr))
81+
;; (defmethod keypad (self onoff)
82+
;; ([_ncurses . keypad] [self . _scr] onoff))
83+
;; (defmethod move (self y x)
84+
;; ([_ncurses . wmove] [self . _scr] y x))
85+
;; (defmethod addch (self c)
86+
;; ([_ncurses . waddch] [self . _scr] c))
87+
;; (defmethod refresh (self)
88+
;; ([_ncurses . wrefresh] [self . _scr]))
89+
;; (defmethod getch (self)
90+
;; ([_ncurses . wgetch] [self . _scr]))
91+
;; (defmethod erase (self)
92+
;; ([_ncurses . werase] [self . _scr]))
93+
;; (defmethod print-with-attr (self str attr)
94+
;; (for-each c (string-to-list str)
95+
;; [self addch (+ (ord c) attr)]))
96+
;; (defmethod nodelay (self bf)
97+
;; ([_ncurses . nodelay] [self . _scr] bf))
98+
;; (defmethod halfdelay (self tenths)
99+
;; ([_ncurses . halfdelay] tenths)))
100100

101-
(defun ncurses-init ()
102-
([_ncurses . initscr])
103-
([_ncurses . cbreak])
104-
([_ncurses . noecho])
105-
([_ncurses . keypad] ([_ncurses . stdscr]) :t)
106-
([_ncurses . stdscr]))
101+
;; (defun ncurses-init ()
102+
;; ([_ncurses . initscr])
103+
;; ([_ncurses . cbreak])
104+
;; ([_ncurses . noecho])
105+
;; ([_ncurses . keypad] ([_ncurses . stdscr]) :t)
106+
;; ([_ncurses . stdscr]))
107107

108108
(defun enumerate (l)
109109
(defun enumerate-helper (s l)

helpers.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
inline int (is_nil)(limo_data *ld)
55
{
6-
if (!ld)
7-
limo_error("null pointer (is_nil)");
8-
return ld->type == limo_TYPE_CONS && !ld->d_cons;
6+
return ld->type == limo_TYPE_NIL;
97
}
108

119
int list_length(limo_data *l)
@@ -28,7 +26,7 @@ char *limo_strdup(char *in)
2826
limo_data *thunk_safe_cdr(limo_data *x)
2927
{
3028
limo_data *cdr;
31-
cdr = (x)->d_cons->cdr;
29+
cdr = CDR(x);
3230
while (cdr->type == limo_TYPE_THUNK)
3331
cdr = eval(CDR(cdr), CAR(cdr));
3432

libs/fd/fd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ BUILTIN(builtin_fd_poll)
118118
for (i=0; i<pollfdlist_length; ++i,CDR(ld_cursor)=make_cons(nil, nil), ld_cursor=CDR(ld_cursor))
119119
CAR(ld_res) = make_number_from_long_long(pfds[i].revents);
120120

121-
ld_cursor->d_cons=NULL;
121+
ld_cursor->type=limo_TYPE_NIL;
122122
return ld_res;
123123
}
124124

limo-code/random.limo

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,25 @@
66
(mod (+ (* 255 (random-byte 256))
77
(random-byte 256))
88
n))
9+
10+
(defun shuffle (l) ; merge
11+
(defun seconds (l) ; every second item
12+
(when l
13+
(dcons (car l)
14+
(when (cdr l) (seconds (cddr l))))))
15+
16+
(defun merge (l m)
17+
(cond ((and l m)
18+
(if (= 0 (random-byte 2))
19+
(dcons (car l) (merge (cdr l) m))
20+
(dcons (car m) (merge l (cdr m)))))
21+
(l l)
22+
(m m)
23+
(:else nil)))
24+
(undyn
25+
(when l
26+
(let ((left (undyn (seconds l)))
27+
(right (undyn (seconds (cdr l)))))
28+
(if (not (and left right))
29+
(or left right)
30+
(merge (shuffle left) (shuffle right)))))))

0 commit comments

Comments
 (0)