1 (define (predefine-var id type adr)
3 (new-value (list (make-byte-cell adr '() '()))))
5 (new-def-variable '() id '() type value '())))
8 (define (predefine-fun id type param-defs adr)
10 (cond ((eq? type 'byte) ;; TODO have the others, or make this generic (this is not actually used anyway)
11 (new-value (list (make-byte-cell WREG '() '()))))
15 (error "unknown return type"))))
18 ;; parameters don't need names here
19 (predefine-var 'foo (car x) (cdr x)))
22 (new-def-procedure '() id '() type value params))
24 (asm-make-label id adr)))
25 (multi-link-parent! params ast)
26 (def-procedure-entry-set! ast entry)
29 (define predefined-routines '())
31 ;; as predefine-fun, but represented as bbs, not as preloaded machine code
32 ;; the body of the procedure (as a cfg) will be generated during the generation
34 (define (predefine-routine id type param-defs)
36 (map (lambda (type) ; parameters are passed like this: (type type ...)
37 ;; parameters don't need names here
38 (new-def-variable '() 'foo '() type (alloc-value type) '()))
40 (set! predefined-routines (cons id predefined-routines))
41 (new-def-procedure '() id '() type (alloc-value type) params)))
43 (define initial-cte ;; TODO clean this up
44 (list (predefine-var 'X 'byte 5)
45 (predefine-var 'Y 'byte 6)
46 (predefine-var 'Z 'byte 7)
47 (predefine-fun 'FLASH_execute_erase
51 (predefine-fun 'FLASH_execute_write
55 (predefine-fun 'led_set
57 (list (cons 'byte WREG))
59 (predefine-fun 'irda_tx_wake_up
63 (predefine-fun 'irda_tx_raw
65 (list (cons 'byte WREG))
67 (predefine-fun 'irda_rx_raw
71 (predefine-fun 'sleep_mode
75 (predefine-fun 'exec_client
80 ;; TODO maybe use some for the fsr variables ? and have the address be the fsr registers
83 (predefine-routine 'mul8_8 'int16 '(byte byte))
84 (predefine-routine 'mul16_8 'int24 '(int16 byte))
85 (predefine-routine 'mul16_16 'int32 '(int16 int16))
86 ;; TODO maybe use predefine fun and have jump to a function already in rom ? then have some kind of linking to see if it's used, and if so, put the code in
89 (define (cte-extend cte bindings)
90 (append bindings cte))
92 (define (cte-lookup cte id)
94 (error "undefined identifier" id))
95 ((eq? (def-id (car cte)) id)
98 (cte-lookup (cdr cte) id))))