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 (byte-cell-next-id) x
5 (new-empty-set) (new-empty-set)))
8 (new-def-variable '() id '() type value '())))
11 (define (predefine-fun id type param-defs adr)
13 (cond ((eq? type 'byte) ;; TODO have the other types, or make this generic (this is not actually used anyway)
14 (new-value (list (make-byte-cell (byte-cell-next-id)
21 (error "unknown return type"))))
24 ;; parameters don't need names here
25 ;; TODO support other types
26 (predefine-var 'foo (car x) (list (cdr x))))
29 (new-def-procedure '() id '() type value params))
31 (asm-make-label id adr)))
32 (multi-link-parent! params ast)
33 (def-procedure-entry-set! ast entry)
36 (define predefined-routines '())
38 ;; as predefine-fun, but represented as bbs, not as preloaded machine code
39 ;; the body of the procedure (as a cfg) will be generated during the generation
41 (define (predefine-routine id type param-defs)
43 (map (lambda (type) ; parameters are passed like this: (type type ...)
44 ;; parameters don't need names here
45 (new-def-variable '() 'foo '() type (alloc-value type) '()))
47 (set! predefined-routines (cons id predefined-routines))
48 (new-def-procedure '() id '() type (alloc-value type) params)))
52 (predefine-var 'X 'byte '(5))
53 (predefine-var 'Y 'byte '(6))
54 (predefine-var 'Z 'byte '(7))
56 (predefine-fun 'FLASH_execute_erase 'void '() #x1EE)
57 (predefine-fun 'FLASH_execute_write 'void '() #x1F0)
58 (predefine-fun 'led_set 'void (list (cons 'byte WREG)) #x1F2)
59 (predefine-fun 'irda_tx_wake_up 'void '() #x1F4)
60 (predefine-fun 'irda_tx_raw 'void (list (cons 'byte WREG)) #x1F6)
61 (predefine-fun 'irda_rx_raw 'byte '() #x1F8)
62 (predefine-fun 'sleep_mode 'void '() #x1FA)
63 (predefine-fun 'exec_client 'void '() #x1FC)
66 (predefine-var 'SIXPIC_FSR0 'int16 (list FSR0L FSR0H))
67 (predefine-var 'SIXPIC_FSR1 'int16 (list FSR1L FSR1H))
68 (predefine-var 'SIXPIC_FSR2 'int16 (list FSR2L FSR2H))
70 (predefine-routine 'mul8_8 'int8 '(int8 int8))
71 (predefine-routine 'mul16_8 'int16 '(int16 int8)) ;; TODO since multiplication arguments are not padded, these asymetric operations are used, they are more efficient, but padding would mean fewer necessary routines
72 (predefine-routine 'mul16_16 'int16 '(int16 int16))
73 (predefine-routine 'mul32_16 'int32 '(int32 int16))
75 (predefine-routine 'shl8 'int8 '(int8 int8))
76 (predefine-routine 'shl16 'int16 '(int16 int8))
77 (predefine-routine 'shl32 'int32 '(int32 int8))
78 (predefine-routine 'shr8 'int8 '(int8 int8))
79 (predefine-routine 'shr16 'int16 '(int16 int8))
80 (predefine-routine 'shr32 'int32 '(int32 int8))
83 (define (cte-extend cte bindings)
84 (append bindings cte))
86 (define (cte-lookup cte id)
88 (error "undefined identifier" id))
89 ((eq? (def-id (car cte)) id)
92 (cte-lookup (cdr cte) id))))