-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParagraph.clp
More file actions
281 lines (247 loc) · 11.9 KB
/
Paragraph.clp
File metadata and controls
281 lines (247 loc) · 11.9 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
; syn
; Copyright (c) 2013-2017, Joshua Scoggins and Contributors
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
; the encyclopedia scheme is a 72 bit byte encoding / 69 bit word addressing scheme
; It defines several levels of delination from the sentence up through the book. While
; higher memory concepts are possible (for instance 56 more bits to get to 128-bits wide
; which could be called a set). There is no way I will ever see this in my lifetime nor
; I think ever as that is a lot of ram!!!
; See doc/iris64/Memory Layout.txt
(defglobal MAIN
?*encyclopedia-sentence-max-address* = (hex->int 0x3FF)
?*encyclopedia-sentence-size* = (+ ?*encyclopedia-sentence-max-address*
1)
?*encyclopedia-sentence-mask* = ?*encyclopedia-sentence-max-address*)
(deffunction MAIN::address->sentence-address
"extract the lowest 10 bits"
(?address)
(decode-bits ?address
?*encyclopedia-sentence-mask*
0))
; conceptually, the sentence is the smallest unit of measurement, unfortunately it is way too
; fine grain of control for CLIPS, having directly addressable 2kb worth of memory is too fine
; and adds about 750 megabytes of overhead for one section!
; First lets see if we do nine-bits instead of eight bits!
(defclass MAIN::encyclopedia-sentence
"A set of 1024 words which is the smallest unit, this would be known as a block in
other architectures! This translates to 8k per sentence"
(is-a memory-block)
(slot capacity
(source composite)
(access read-only)
(storage shared)
(create-accessor read)
(default ?*encyclopedia-sentence-size*))
(message-handler map-write primary)
(message-handler read primary)
(message-handler write primary))
(defmessage-handler encyclopedia-sentence map-write primary
(?address $?values)
(override-next-handler (address->sentence-address ?address)
?values))
(defmessage-handler encyclopedia-sentence read primary
(?address)
(override-next-handler (address->sentence-address ?address)))
(defmessage-handler encyclopedia-sentence write primary
(?address ?value)
(override-next-handler (address->sentence-address ?address)
?value))
(defclass MAIN::encyclopedia-container
"The higher level containers for the encyclopedia concept which do not
directly interface with native memory blocks"
(is-a device)
(role concrete)
(pattern-match reactive)
(multislot children
(type INSTANCE)
(visibility public)
(storage local)
(default ?NONE))
(message-handler map-write primary)
(message-handler select-child primary)
(message-handler compute-child-address primary)
(message-handler read primary)
(message-handler write primary))
(defmessage-handler encyclopedia-container map-write primary
(?address $?values)
(bind ?child
(send ?self
select-child
?address))
; TODO: add support for spanning multiple sections
(if ?child then
(send ?child
map-write
?address
?values)))
(defmessage-handler encyclopedia-container read primary
(?address)
(bind ?child
(send ?self
select-child
?address))
(if ?child then
(send ?child
read
?address)))
(defmessage-handler encyclopedia-container write primary
(?address ?value)
(bind ?child
(send ?self
select-child
?address))
(if ?child then
(send ?child
write
?address
?value)))
(defmessage-handler encyclopedia-container select-child primary
(?address)
; perform the address one-index conversion here
(bind ?conv
(+ (send ?self
compute-child-address
?address)
1))
(if (<= ?conv
(length$ (dynamic-get children))) then
(nth$ ?conv
(dynamic-get children))))
; A paragraph has 16 sentences in it for a total of 64k per paragraph
(defglobal MAIN
?*encyclopedia-paragraph-max-address* = (hex->int 0x7)
?*encyclopedia-paragraph-size* = (+ ?*encyclopedia-paragraph-max-address*
1)
?*encyclopedia-shift-amount* = 10
?*encyclopedia-paragraph-mask* = (left-shift ?*encyclopedia-paragraph-max-address*
?*encyclopedia-shift-amount*))
(deffunction MAIN::address->paragraph-address
(?address)
(decode-bits ?address
?*encyclopedia-paragraph-mask*
?*encyclopedia-shift-amount*))
(defclass MAIN::encyclopedia-paragraph
"A paragraph is 3 bits worth of sentences which make up 64k of space"
(is-a encyclopedia-container)
(multislot children
(source composite)
(allowed-classes encyclopedia-sentence)
(cardinality 1
8)
(default ?NONE))
(message-handler compute-child-address primary))
(defmessage-handler encyclopedia-paragraph compute-child-address primary
(?address)
(address->paragraph-address ?address))
(defglobal MAIN
?*encyclopedia-page-max-address* = (hex->int 0xFF)
?*encyclopedia-page-size* = (+ ?*encyclopedia-page-max-address*
1)
?*encyclopedia-page-shift-count* = 13
?*encyclopedia-page-mask* = (left-shift ?*encyclopedia-page-max-address*
?*encyclopedia-page-shift-count*))
(deffunction MAIN::address->page-address
(?address)
(decode-bits ?address
?*encyclopedia-page-mask*
?*encyclopedia-page-shift-count*))
(defclass MAIN::encyclopedia-page
"A page consists of 256 pages which is 16 megabytes"
(is-a encyclopedia-container)
(multislot children
(source composite)
(allowed-classes encyclopedia-paragraph)
(cardinality 1 256)
(default ?NONE))
(message-handler compute-child-address primary))
(defmessage-handler encyclopedia-page compute-child-address primary
(?address)
(address->page-address ?address))
(defglobal MAIN
?*encyclopedia-section-max-address* = (hex->int 0xFF)
?*encyclopedia-section-size* = (+ ?*encyclopedia-section-max-address*
1)
?*encyclopedia-section-shift-count* = 21
?*encyclopedia-section-mask* = (left-shift ?*encyclopedia-section-max-address*
?*encyclopedia-section-shift-count*))
(deffunction MAIN::address->section-address
(?address)
(decode-bits ?address
?*encyclopedia-section-mask*
?*encyclopedia-section-shift-count*))
(defclass MAIN::encyclopedia-section
"A section consists of 256 pages which is 4 gigabytes!"
(is-a encyclopedia-container)
(multislot children
(source composite)
(cardinality 1 256)
(allowed-classes encyclopedia-page)
(default ?NONE))
(message-handler compute-child-address primary))
(defmessage-handler encyclopedia-section compute-child-address primary
(?address)
(address->section-address ?address))
(defglobal MAIN
?*encyclopedia-chapter-max-address* = (hex->int 0xFFFFF)
?*encyclopedia-chapter-size* = (+ ?*encyclopedia-chapter-max-address*
1)
?*encyclopedia-chapter-mask* = (hex->int 0x1ffffe0000000))
(deffunction MAIN::address->chapter-address
(?address)
(decode-bits ?address
?*encyclopedia-chapter-mask*
29))
(defclass MAIN::encyclopedia-chapter
"An encyclopedia chapter consists of 2^20 sections which is 4 petabytes!!!!
To put this in perspective, one chapter has the same storage capacity as the
theoretical 52-bit maximum on x86_64 machines!!!!"
(is-a encyclopedia-container)
(multislot children
(source composite)
(cardinality 1 1048576)
(allowed-classes encyclopedia-section)
(default ?NONE))
(message-handler compute-child-address primary))
(defmessage-handler MAIN::encyclopedia-chapter compute-child-address primary
(?address)
(address->chapter-address ?address))
; The highest level of the current addressing scheme is the book, there are 256 possible
; books in the current addressing scheme and that totals 4096 exabytes!!! I do not see the point
; of actually implementing support for this as I'll never see it! I may eat my words but holy fuck,
; that is a lot of memory. I'll have to get creative anyway with the current clips implementation anyway
; to get values beyond 64-bit signed. For my emulation purposes, even having a full chapter is nuts!!!
(defclass MAIN::iris64-encyclopedia
"A child of the encyclopedia-chapter, it is the mmu interface that an iris64 cpu would use, it is
hard masked to at most 4 full sections or 16 gigabytes!"
(is-a encyclopedia-chapter)
(multislot children
(source composite)
(cardinality 1 4))
(message-handler compute-child-address primary))
(defmessage-handler MAIN::iris64-encyclopedia compute-child-address primary
(?address)
; TODO: add support for handling the IO section and its magic :D
; mask down to 4 sections
(decode-bits ?address
(hex->int 0x60000000)
29))