-
Notifications
You must be signed in to change notification settings - Fork 6
/
jit.c
796 lines (645 loc) · 18.3 KB
/
jit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
#include <stddef.h>
#include "struct.h"
#if !USE_JIT
#include "hash.h"
int jit(func_val* fv, hash_table* d) {
return FALSE;
}
#else
#include <lightning.h>
#include "gc.h"
#include "eval.h"
#include "continue.h"
#include "lookup.h"
#include "fail.h"
#define jit_movi_p(dest, addr) jit_movi(dest, (jit_word_t)(addr))
#define jit_pushargi_p(addr) jit_pushargi((jit_word_t)(addr))
static int inited = 0;
typedef struct context {
hash_table* d;
symbol* arg_name;
int stack_pos;
env *env;
int env_start;
int specialize;
tagged* inline_arg;
struct context *inline_from;
} context;
static jit_state_t *_jit;
static void jit_expr(tagged* expr, context *ctx);
static void jit_variable(int pos, context *ctx);
static void jit_cont_expr(tagged* expr, int cont_type, context *ctx);
static jitted_proc jit_continue_by_interp(tagged* body);
static void jit_cont_make(tagged* expr, context *ctx, int cont_type, int jit_cont_type);
static void do_jit_next();
static void continue_or_return();
static void jit_check_type(int need_type, int reg, char *complain);
static void jit_set_stack(int stack_pos, int reg);
static void jit_get_stack(int reg, int stack_pos);
static void jit_prep_possible_gc(int stack_pos, int tmp_reg);
static void jit_movi_maybe_gc(int reg, tagged* v);
static void jit_maybe_specialize(int stack_pos, context *ctx);
static func_val *realloc_lam(func_val *fv);
static tagged* extract_known(int pos, context *ctx);
static int no_calls(tagged* expr, context *ctx);
static int want_to_jit(lambda_expr* lam);
static int definitely_number(tagged* expr);
static int definitely_function(tagged* expr);
static int can_inline(bin_op_expr* bn, context *ctx, int without_introducing_calls, func_val **_fv);
#define STACK_SIZE 64
static tagged* stack[STACK_SIZE];
static int stack_gc_depth = 0;
#define MAX_CODE_ROOTS 128
static tagged* code_roots[MAX_CODE_ROOTS];
static int code_roots_count = 0;
#define FRAME_SIZE 64
void push_jit_roots(void (*paint_gray)(void *))
{
int i;
for (i = 0; i < code_roots_count; i++)
paint_gray(&code_roots[i]);
for (i = 0; i < stack_gc_depth; i++)
paint_gray(&stack[i]);
}
#if !FIXNUM_ENCODING
# error "JIT requires fixnum encoding"
#endif
static void init_context(context *ctx, hash_table* d, symbol* arg_name, env* e)
{
ctx->d = d;
ctx->arg_name = arg_name;
ctx->stack_pos = 0;
ctx->env = e;
ctx->env_start = 1;
ctx->specialize = 0;
ctx->inline_arg = NULL;
ctx->inline_from = NULL;
}
int jit(func_val *fv, hash_table* d)
{
jit_state_t *old_jit;
jit_node_t *after_prolog;
lambda_expr *lam = fv->lam;
context ctx;
init_context(&ctx, d, lam->arg_name, fv->e);
if ((fv->specialize_counter == 1) && want_to_jit(lam)) {
fv->specialize_counter = 0;
if (fv->e) {
fv = realloc_lam(fv);
lam = fv->lam;
ctx.env = fv->e;
ctx.arg_name = lam->arg_name;
ctx.specialize = 1;
}
}
if (lam->code)
return TRUE; /* already JIT-compiled */
if (lam->tail_code)
return FALSE; /* tail code continues via interp */
if (!want_to_jit(lam)) {
lam->tail_code = jit_continue_by_interp(lam->body);
return FALSE;
}
if (!inited) {
inited = 1;
init_jit(NULL);
}
old_jit = _jit;
_jit = jit_new_state();
jit_prolog();
jit_frame(FRAME_SIZE);
after_prolog = jit_indirect();
jit_expr(lam->body, &ctx);
continue_or_return();
lam->code = jit_emit();
lam->tail_code = jit_address(after_prolog);
jit_clear_state();
_jit = old_jit;
return TRUE;
}
jitted_proc jit_cont(tagged* expr, context *ctx, int cont_type, int jit_cont_type, jitted_proc *_tail_code)
{
jitted_proc code;
jit_state_t *old_jit;
jit_node_t *after_prolog;
old_jit = _jit;
_jit = jit_new_state();
jit_prolog();
jit_frame(FRAME_SIZE);
after_prolog = jit_indirect();
jit_ldi(JIT_R2, &todos);
jit_ldxi(JIT_R1, JIT_R2, offsetof(jitted, rest));
jit_sti(&todos, JIT_R1);
switch (jit_cont_type) {
case right_jitted_type:
jit_ldxi(JIT_R1, JIT_R2, offsetof(right_jitted, env));
jit_sti(&e, JIT_R1);
break;
case finish_jitted_type:
jit_ldxi(JIT_R1, JIT_R2, offsetof(finish_jitted, val));
break;
}
jit_ldi(JIT_R0, &val);
jit_cont_expr(expr, cont_type, ctx);
continue_or_return();
code = jit_emit();
*_tail_code = jit_address(after_prolog);
jit_clear_state();
_jit = old_jit;
return code;
}
void continue_or_return()
{
/* Stay in the JITted world if the continuation is one of ours */
jit_node_t *test, *this_one;
jit_ldi(JIT_R2, &todos);
jit_ldxi_i(JIT_R1, JIT_R2, offsetof(cont, type));
test = jit_bnei(JIT_R1, right_jitted_type);
this_one = jit_label();
do_jit_next();
jit_patch(test);
test = jit_beqi(JIT_R1, finish_jitted_type);
jit_patch_at(test, this_one);
jit_prep_possible_gc(0, JIT_R2);
jit_retr(JIT_R0);
}
jitted_proc jit_continue_by_interp(tagged* body)
{
jit_state_t *old_jit;
jitted_proc code;
jit_node_t *after_prolog;
if (!inited) {
inited = 1;
init_jit(NULL);
}
old_jit = _jit;
_jit = jit_new_state();
jit_prolog();
jit_frame(FRAME_SIZE);
after_prolog = jit_indirect();
jit_movi_maybe_gc(JIT_R0, body);
jit_ldi(JIT_R1, &todos);
jit_prepare();
jit_pushargr(JIT_R0);
jit_pushargr(JIT_R1);
jit_finishi(make_interp);
jit_retval(JIT_R0);
jit_sti(&todos, JIT_R0);
jit_prep_possible_gc(0, JIT_R2);
jit_movi_p(JIT_R0, make_num(0));
jit_retr(JIT_R0);
(void)jit_emit();
code = jit_address(after_prolog);
jit_clear_state();
_jit = old_jit;
return code;
}
static void jit_expr_push(tagged* expr, context *ctx)
{
ctx->stack_pos++;
jit_expr(expr, ctx);
--ctx->stack_pos;
}
static void jit_expr(tagged* expr, context *ctx)
{
switch (TAGGED_TYPE(expr)) {
case num_type:
case func_type:
jit_movi_maybe_gc(JIT_R0, expr);
break;
case sym_type:
{
int pos;
if (same_symbol((symbol*)expr, ctx->arg_name))
jit_variable(0, ctx);
else {
pos = env_lookup_pos((symbol *)expr, ctx->env);
if (pos != -1)
jit_variable(pos+1, ctx);
else
jit_movi_maybe_gc(JIT_R0, lookup(ctx->d, (symbol *)expr));
}
}
break;
case debruijn_type:
{
int pos = ((debruijn_expr*)expr)->pos;
jit_variable(pos, ctx);
}
break;
case plus_type:
case minus_type:
case times_type:
{
bin_op_expr* bn = (bin_op_expr*)expr;
if (no_calls(bn->left, ctx) && no_calls(bn->right, ctx)) {
jit_expr(bn->left, ctx);
jit_set_stack(ctx->stack_pos, JIT_R0);
jit_expr_push(bn->right, ctx);
jit_get_stack(JIT_R1, ctx->stack_pos);
jit_cont_expr(expr, finish_bin_type, ctx);
} else {
jit_cont_make(expr, ctx, right_of_bin_type, right_jitted_type);
jit_expr(bn->left, ctx);
do_jit_next();
}
}
break;
case if0_type:
{
if0_expr* if0 = (if0_expr*)expr;
if (no_calls(if0->tst, ctx)) {
jit_expr(if0->tst, ctx);
jit_cont_expr(expr, finish_if0_type, ctx);
} else {
jit_cont_make(expr, ctx, finish_if0_type, right_jitted_type);
jit_expr(if0->tst, ctx);
do_jit_next();
}
}
break;
case lambda_type:
{
lambda_expr *lam = (lambda_expr *)expr;
jit_ldi(JIT_R0, &e);
jit_prep_possible_gc(ctx->stack_pos, JIT_R2);
jit_prepare();
jit_pushargi_p(lam);
jit_pushargr(JIT_R0);
jit_finishi(make_func);
jit_retval(JIT_R0);
}
break;
case app_type:
{
bin_op_expr* bn = (bin_op_expr*)expr;
func_val *fv;
if (can_inline(bn, ctx, FALSE, &fv)) {
/* inline a call */
context in_ctx;
init_context(&in_ctx, ctx->d, fv->lam->arg_name, fv->e);
in_ctx.inline_arg = bn->right;
in_ctx.inline_from = ctx;
jit_expr(fv->lam->body, &in_ctx);
} else {
if (no_calls(bn->left, ctx) && no_calls(bn->right, ctx)) {
jit_expr(bn->left, ctx);
jit_set_stack(ctx->stack_pos, JIT_R0);
jit_expr_push(bn->right, ctx);
jit_get_stack(JIT_R1, ctx->stack_pos);
jit_cont_expr(expr, finish_app_type, ctx);
} else {
jit_cont_make(expr, ctx, right_of_app_type, right_jitted_type);
jit_expr(bn->left, ctx);
do_jit_next();
}
}
}
break;
default:
fail("unrecognized expression in JIT compile");
}
}
static void jit_variable(int pos, context *ctx)
{
tagged* val;
val = extract_known(pos, ctx);
if (val) {
if (TAGGED_TYPE(val) == debruijn_type) {
/* due to inlining */
jit_variable(pos + ((debruijn_expr*)val)->pos + 1, ctx);
} else if (TAGGED_TYPE(val) == sym_type) {
/* due to inlining */
} else
jit_expr(val, ctx);
} else if ((pos == 0) && ctx->inline_arg) {
jit_expr(ctx->inline_arg, ctx->inline_from);
} else {
jit_ldi(JIT_R2, &e);
while (pos--)
jit_ldxi(JIT_R2, JIT_R2, offsetof(env, rest));
jit_ldxi(JIT_R0, JIT_R2, offsetof(env, val));
}
}
static void jit_cont_expr(tagged* expr, int cont_type, context *ctx)
{
switch (cont_type) {
case right_of_bin_type:
{
bin_op_expr* bn = (bin_op_expr*)expr;
if (no_calls(bn->right, ctx)) {
jit_set_stack(ctx->stack_pos, JIT_R0);
jit_expr_push(bn->right, ctx);
jit_get_stack(JIT_R1, ctx->stack_pos);
jit_cont_expr(expr, finish_bin_type, ctx);
} else {
jit_cont_make(expr, ctx, finish_bin_type, finish_jitted_type);
jit_expr(bn->right, ctx);
do_jit_next();
}
}
break;
case finish_bin_type:
{
bin_op_expr* bn = (bin_op_expr*)expr;
/* JIT_R1 has left arg, JIT_R0 has right arg */
if (!definitely_number(bn->left))
jit_check_type(num_type, JIT_R1, "not a number");
if (!definitely_number(bn->right))
jit_check_type(num_type, JIT_R0, "not a number");
jit_rshi(JIT_R1, JIT_R1, 1);
jit_rshi(JIT_R0, JIT_R0, 1);
switch (TAGGED_TYPE(expr)) {
case plus_type:
jit_addr(JIT_R0, JIT_R1, JIT_R0);
break;
case minus_type:
jit_subr(JIT_R0, JIT_R1, JIT_R0);
break;
case times_type:
jit_mulr(JIT_R0, JIT_R1, JIT_R0);
break;
default:
fail("unknown arithmetic");
}
jit_lshi(JIT_R0, JIT_R0, 1);
jit_ori(JIT_R0, JIT_R0, 0x1);
}
break;
case finish_if0_type:
{
if0_expr* if0 = (if0_expr*)expr;
jit_node_t *branch, *done;
if (!definitely_number(if0->tst))
jit_check_type(num_type, JIT_R0, "not a number");
jit_rshi(JIT_R0, JIT_R0, 1);
branch = jit_bnei(JIT_R0, 0);
jit_expr(if0->thn, ctx);
done = jit_jmpi();
jit_patch(branch);
jit_expr(if0->els, ctx);
jit_patch(done);
}
break;
case right_of_app_type:
{
bin_op_expr* bn = (bin_op_expr*)expr;
if (no_calls(bn->right, ctx)) {
jit_set_stack(ctx->stack_pos, JIT_R0);
jit_expr_push(bn->right, ctx);
jit_get_stack(JIT_R1, ctx->stack_pos);
jit_cont_expr(expr, finish_app_type, ctx);
} else {
jit_cont_make(expr, ctx, finish_app_type, finish_jitted_type);
jit_expr(bn->right, ctx);
do_jit_next();
}
}
break;
case finish_app_type:
{
bin_op_expr* bn = (bin_op_expr*)expr;
jit_node_t *branch;
/* JIT_R1 has function, JIT_R0 has argument */
if (!definitely_function(bn->left))
jit_check_type(func_type, JIT_R1, "not a function");
/* Save function & arg on stack in case of GC */
jit_set_stack(ctx->stack_pos, JIT_R1);
jit_set_stack(ctx->stack_pos+1, JIT_R0);
jit_prep_possible_gc(ctx->stack_pos + 2, JIT_R2);
jit_maybe_specialize(ctx->stack_pos, ctx);
jit_ldxi(JIT_R2, JIT_R1, offsetof(func_val, lam));
jit_ldxi(JIT_R0, JIT_R2, offsetof(lambda_expr, tail_code));
branch = jit_bnei(JIT_R0, (jit_word_t)NULL);
{
/* Not yet JIT-compiled, so compile it now */
jit_movi_p(JIT_R0, ctx->d);
jit_prepare();
jit_pushargr(JIT_R1);
jit_pushargr(JIT_R0);
jit_finishi(jit);
}
jit_patch(branch);
/* Extend the environment */
jit_get_stack(JIT_R1, ctx->stack_pos);
jit_get_stack(JIT_R0, ctx->stack_pos+1);
jit_ldxi(JIT_R2, JIT_R1, offsetof(func_val, e));
jit_ldxi(JIT_R1, JIT_R1, offsetof(func_val, lam));
jit_ldxi(JIT_R1, JIT_R1, offsetof(lambda_expr, arg_name));
jit_prepare();
jit_pushargr(JIT_R1); /* argument name */
jit_pushargr(JIT_R0); /* argument value */
jit_pushargr(JIT_R2); /* env */
jit_finishi(make_env);
jit_retval(JIT_R0);
jit_sti(&e, JIT_R0);
/* Jump to the called function's body */
jit_get_stack(JIT_R1, ctx->stack_pos);
jit_ldxi(JIT_R0, JIT_R1, offsetof(func_val, lam));
jit_ldxi(JIT_R0, JIT_R0, offsetof(lambda_expr, tail_code));
jit_jmpr(JIT_R0);
}
break;
default:
fail("unrecognized continuation type in JIT compile");
}
}
static void jit_cont_make(tagged* expr, context *ctx, int cont_type, int jit_cont_type)
{
jitted_proc cont_code, cont_tail_code;
cont_code = jit_cont(expr, ctx, cont_type, jit_cont_type, &cont_tail_code);
jit_prep_possible_gc(0, JIT_R2);
jit_ldi(JIT_R2, &todos);
jit_prepare();
jit_movi_p(JIT_R1, cont_code);
jit_pushargr(JIT_R1); /* code pointer */
jit_movi_p(JIT_R1, cont_tail_code);
jit_pushargr(JIT_R1);
jit_pushargr(JIT_R2); /* continuation */
switch (jit_cont_type) {
case right_jitted_type:
jit_ldi(JIT_R0, &e);
jit_pushargr(JIT_R0); /* environment */
jit_finishi(make_right_jitted);
break;
case finish_jitted_type:
jit_pushargr(JIT_R0); /* value to save */
jit_finishi(make_finish_jitted);
break;
}
jit_retval(JIT_R0);
jit_sti(&todos, JIT_R0);
}
static void jit_check_type(int need_type, int reg, char *complain)
{
jit_node_t *ok, *not_ok;
if (need_type == num_type)
ok = jit_bmsi(reg, 0x1);
else {
not_ok = jit_bmsi(reg, 0x1);
jit_ldxi_i(JIT_R2, reg, offsetof(tagged, type));
ok = jit_beqi(JIT_R2, need_type);
jit_patch(not_ok);
}
jit_prepare();
jit_pushargi_p(complain);
jit_finishi(fail);
jit_patch(ok);
}
static void do_jit_next()
{
/* We know that the current continuation has type finish_jitted[_with_val] */
jit_sti(&val, JIT_R0);
jit_ldi(JIT_R2, &todos);
jit_ldxi(JIT_R2, JIT_R2, offsetof(jitted, tail_code));
jit_jmpr(JIT_R2);
}
static void jit_set_stack(int stack_pos, int reg)
{
if (stack_pos >= STACK_SIZE)
fail("stack too small for JIT-generated code");
jit_sti(&stack[stack_pos], reg);
}
static void jit_get_stack(int reg, int stack_pos)
{
jit_ldi(reg, &stack[stack_pos]);
}
static void jit_prep_possible_gc(int stack_pos, int tmp_reg)
{
jit_movi(tmp_reg, stack_pos);
jit_sti_i(&stack_gc_depth, tmp_reg);
}
static void jit_movi_maybe_gc(int reg, tagged* v)
{
if (gc_is_collectable(v)) {
if (code_roots_count >= MAX_CODE_ROOTS)
fail("too many GCable values in JIT-generated code");
code_roots[code_roots_count] = v;
jit_ldi(reg, &code_roots[code_roots_count]);
code_roots_count++;
} else
jit_movi_p(reg, v);
}
static void jit_maybe_specialize(int stack_pos, context *ctx)
{
/* JIT_R1 holds a function, and the function is also
on the local stack at position 0 */
jit_node_t *branch, *branch2;
/* Check specialization counter */
jit_ldxi_i(JIT_R2, JIT_R1, offsetof(func_val, specialize_counter));
branch = jit_beqi(JIT_R2, 0);
jit_subi(JIT_R2, JIT_R2, 1);
jit_stxi_i(offsetof(func_val, specialize_counter), JIT_R1, JIT_R2);
/* If specialize_counter goes to 1, then specialize */
branch2 = jit_bnei(JIT_R2, 1);
jit_movi_p(JIT_R0, ctx->d);
jit_prepare();
jit_pushargr(JIT_R1);
jit_pushargr(JIT_R0);
jit_finishi(jit);
/* Reload function into JIT_R1 */
jit_get_stack(JIT_R1, stack_pos);
jit_patch(branch);
jit_patch(branch2);
}
static func_val *realloc_lam(func_val *fv)
{
lambda_expr* lam = fv->lam;
if (gc_is_collectable(fv)) {
code_roots[code_roots_count++] = (tagged*)fv;
lam = (lambda_expr*)make_lambda(lam->arg_name,
lam->body);
fv = (func_val*)code_roots[--code_roots_count];
} else {
disable_gc();
lam = (lambda_expr*)make_lambda(lam->arg_name,
lam->body);
enable_gc();
}
fv->lam = lam;
return fv;
}
static tagged* extract_known(int pos, context *ctx)
{
if (ctx->specialize && (pos >= ctx->env_start)) {
/* specializing; use known value */
env *env = ctx->env;
pos -= ctx->env_start;
while (pos--)
env = env->rest;
return env->val;
} else
return NULL;
}
static int no_calls(tagged* expr, context *ctx)
{
switch (TAGGED_TYPE(expr)) {
case app_type:
return ctx && can_inline((bin_op_expr*)expr, ctx, TRUE, NULL);
case plus_type:
case minus_type:
case times_type:
{
bin_op_expr* bn = (bin_op_expr*)expr;
return no_calls(bn->left, ctx) && no_calls(bn->right, ctx);
}
case if0_type:
{
if0_expr* if0 = (if0_expr*)expr;
return (no_calls(if0->tst, ctx)
&& no_calls(if0->thn, ctx)
&& no_calls(if0->els, ctx));
}
}
return TRUE;
}
static int want_to_jit(lambda_expr* lam)
{
return TRUE;
}
static int definitely_number(tagged* expr)
{
switch (TAGGED_TYPE(expr)) {
case num_type:
case plus_type:
case minus_type:
case times_type:
return TRUE;
}
return FALSE;
}
static int definitely_function(tagged* expr)
{
switch (TAGGED_TYPE(expr)) {
case lambda_type:
case func_type:
return TRUE;
}
return FALSE;
}
static int can_inline(bin_op_expr* bn, context *ctx, int without_introducing_calls, func_val **_fv)
{
if (TAGGED_TYPE(bn->left) == debruijn_type) {
tagged* val = extract_known(((debruijn_expr*)bn->left)->pos, ctx);
if (val && TAGGED_TYPE(val) == func_type) {
/* Simpe enough argument? */
switch (TAGGED_TYPE(bn->right)) {
case num_type:
case func_type:
case debruijn_type:
case sym_type:
{
func_val* fv = (func_val*)val;
if (_fv)
*_fv = fv;
if (without_introducing_calls)
return no_calls(fv->lam->body, NULL);
return TRUE;
}
break;
}
}
}
return FALSE;
}
#endif /* USE_JIT */