-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompiled-program.scm
118 lines (98 loc) · 3.59 KB
/
compiled-program.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
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
(define-library (compiled-program)
(export make-empty-compiled-program
compiled-program-module-definitions
compiled-program-value-code
compiled-program-with-value-code
compiled-program-append-value-code
compiled-program-append-value-codes
compiled-program-add-definition
compiled-program-last-definition
compiled-program-lookup-definition
compiled-program-fold-definitions
compiled-program-flatmap-definitions
compiled-program-get-definitions
compiled-program-contains-definition
compiled-program-definition-index
compiled-program-definitions-count
compiled-program-with-definition-and-value-code
compiled-program-with-definitions-and-value-code)
(import (scheme base)
(lists)
(definitions-table))
(begin
(define (make-compiled-program module-definitions value-code)
(list module-definitions value-code))
(define (compiled-program-module-definitions cp)
(car cp))
(define (compiled-program-value-code cp)
(cadr cp))
(define (make-empty-compiled-program)
(make-compiled-program
(make-empty-definitions-table)
'()))
(define (compiled-program-with-value-code cp code)
(make-compiled-program
(compiled-program-module-definitions cp)
code))
(define (compiled-program-append-value-code cp code)
(make-compiled-program
(compiled-program-module-definitions cp)
(append (compiled-program-value-code cp)
code)))
(define (compiled-program-append-value-codes cp1 cp2)
(make-compiled-program
(compiled-program-module-definitions cp2)
(append (compiled-program-value-code cp1)
(compiled-program-value-code cp2))))
(define (compiled-program-add-definition cp definition)
(make-compiled-program
(add-definition
(compiled-program-module-definitions cp)
definition)
(compiled-program-value-code cp)))
(define (compiled-program-last-definition cp type)
(last-definition
(compiled-program-module-definitions cp)
type))
(define (compiled-program-lookup-definition cp predicate)
(lookup-definition
(compiled-program-module-definitions cp)
predicate))
(define (compiled-program-fold-definitions cp proc init)
(fold-definitions
(compiled-program-module-definitions cp)
proc
init))
(define (compiled-program-flatmap-definitions cp proc)
(flatmap-definitions
(compiled-program-module-definitions cp)
proc))
(define (compiled-program-get-definitions cp type)
(get-definitions
(compiled-program-module-definitions cp)
type))
(define (compiled-program-contains-definition cp definition)
(contains-definition
(compiled-program-module-definitions cp)
definition))
(define (compiled-program-definition-index cp definition)
(definition-index
(compiled-program-module-definitions cp)
definition))
(define (compiled-program-definitions-count cp type)
(definitions-count
(compiled-program-module-definitions cp)
type))
(define (compiled-program-with-definition-and-value-code cp definition code)
(make-compiled-program
(add-definition
(compiled-program-module-definitions cp)
definition)
code))
(define (compiled-program-with-definitions-and-value-code cp definitions code)
(fold
(lambda (definition cp)
(compiled-program-with-definition-and-value-code cp definition code))
cp
definitions))
))