1 (define (predefine-var id type addresses)
3 ;; adrs is the list of addresses this variable is stored at
4 (new-value (map (lambda (x) (make-byte-cell x '() '()))
7 (new-def-variable '() id '() type value '())))
10 (define (predefine-fun id type param-defs adr)
12 (cond ((eq? type 'byte) ;; TODO have the others, or make this generic (this is not actually used anyway)
13 (new-value (list (make-byte-cell WREG '() '()))))
17 (error "unknown return type"))))
20 ;; parameters don't need names here
21 ;; TODO this does not support parameters wider than 1 byte, but this function is not used for any useful function anyway
22 (predefine-var 'foo (car x) (list (cdr x))))
25 (new-def-procedure '() id '() type value params))
27 (asm-make-label id adr)))
28 (multi-link-parent! params ast)
29 (def-procedure-entry-set! ast entry)
32 (define predefined-routines '())
34 ;; as predefine-fun, but represented as bbs, not as preloaded machine code
35 ;; the body of the procedure (as a cfg) will be generated during the generation
37 (define (predefine-routine id type param-defs)
39 (map (lambda (type) ; parameters are passed like this: (type type ...)
40 ;; parameters don't need names here
41 (new-def-variable '() 'foo '() type (alloc-value type) '()))
43 (set! predefined-routines (cons id predefined-routines))
44 (new-def-procedure '() id '() type (alloc-value type) params)))
46 (define initial-cte ;; TODO clean this up
48 (predefine-var 'X 'byte '(5))
49 (predefine-var 'Y 'byte '(6))
50 (predefine-var 'Z 'byte '(7))
52 (predefine-fun 'FLASH_execute_erase 'void '() #x1EE)
53 (predefine-fun 'FLASH_execute_write 'void '() #x1F0)
54 (predefine-fun 'led_set 'void (list (cons 'byte WREG)) #x1F2)
55 (predefine-fun 'irda_tx_wake_up 'void '() #x1F4)
56 (predefine-fun 'irda_tx_raw 'void (list (cons 'byte WREG)) #x1F6)
57 (predefine-fun 'irda_rx_raw 'byte '() #x1F8)
58 (predefine-fun 'sleep_mode 'void '() #x1FA)
59 (predefine-fun 'exec_client 'void '() #x1FC)
62 ;; TODO fit the memory divide here too
63 (predefine-var 'SIXPIC_FSR0 'int16 (list FSR0L FSR0H))
64 (predefine-var 'SIXPIC_FSR1 'int16 (list FSR1L FSR1H))
65 (predefine-var 'SIXPIC_FSR2 'int16 (list FSR2L FSR2H))
68 (predefine-routine 'mul8_8 'int16 '(byte byte))
69 (predefine-routine 'mul16_8 'int24 '(int16 byte))
70 (predefine-routine 'mul16_16 'int32 '(int16 int16))
73 (define (cte-extend cte bindings)
74 (append bindings cte))
76 (define (cte-lookup cte id)
78 (error "undefined identifier" id))
79 ((eq? (def-id (car cte)) id)
82 (cte-lookup (cdr cte) id))))