-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc.scm
66 lines (46 loc) · 1.9 KB
/
cc.scm
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
;;; Copyright 2013-2017 by Christian Jaeger <[email protected]>
;;; This file is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License (GPL) as published
;;; by the Free Software Foundation, either version 2 of the License, or
;;; (at your option) any later version.
(require easy
)
(export (macro CC))
;; *simple* expression to C compiler
;; - no need for ctx, since, just any variable that isn't known to be fixed is a variable? (but, what about shadowing?)
;; - what about types? infer from ops in e ?
;; - hm and breaks basic block for rangechange? well for..< broke it anyway right?.
;; example:
;; (CC (integer (fl* (fl- (Mr.ref@ m i0 i1) lo) rangechange)))
;; yielding something like:
;; (##c-code "___SCMOBJ m=___ARG1; ___SCMOBJ i0=___ARG2; ....
;; ___RESULT= ___FIX(___CAST(long, ((___F64VECTORREF(___VECTORREF(___VECTORREF(m,___FIX(3)),i0),i1) - lo) * rangechange)))
;; " m i0 i1 lo rangechange)
;; hm
;; > (expansion (Mr.ref@ m i0 i1))
;; ((lambda (m i0 i1) (Vr.ref@ (##vector-ref (##vector-ref m 3) i0) i1)) m i0 i1)
;; > Vr.ref@
;; #<procedure #2 ##f64vector-ref>
;; -> (##f64vector-ref (##vector-ref (##vector-ref m 3) i0) i1)
;;or keep intermediate variables ok?
;; (define-struct. ccop
;; )
;; (define cc-opmap
;; )
;; (define (cc e ctx)
;; )
(define cc-map
(list->table
'(("(integer (fl* (fl- (Mr.ref@ m i0 i1) lo) rangechange))"
.
(##c-code "
___SCMOBJ m=___ARG1;
___SCMOBJ i0=___ARG2;
___SCMOBJ i1=___ARG3;
___SCMOBJ lo=___ARG4;
___SCMOBJ rangechange= ___ARG5;
___RESULT= ___FIX(___CAST(long, ((___F64VECTORREF(___VECTORREF(___VECTORREF(m,___FIX(3)),i0),i1) - ___FLONUM_VAL(lo)) * ___FLONUM_VAL(rangechange))));
" m i0 i1 lo rangechange)))))
(define-macro* (CC e)
(or (table-ref cc-map (object->string (cj-desourcify e)) #f)
(raise-source-error e "missing manual compilation for expression")))