forked from toddjasonblackmon/wren
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathe_notes.txt
158 lines (114 loc) · 4.04 KB
/
e_notes.txt
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
Bugs:
X disasm.wren and boot.wren assumes little endian; maybe we need peek2 (refx)
X boot.wren could use * (i.e., fetch_byte) in place of peek in a couple places
Try to eliminate (or rename) get_xt (it adds c0 and isn't really necessary)
Look at uses of c0; see Sandboxing below
Convert "cp" to "cx" and "dp" to "dx"?
X Rename FETCH_BYTE PEEK POKE to REFB REFV SETV and add REFX SETX SETB
X where B is Byte X is indeX and V is Value
X all take wIndex offsets into the_store.
X PEEKB *
X PEEKX refx
X PEEKV refv
X POKEB setb
X POKEX setx
X POKEV setv
Sandboxing:
X Consider converting from addresses to offsets everywhere inside the_store
X -- the exception would be CCALL addresses
X -- pay attention to PUSH_STRING which pushes an address now
X Convert wValue to int32_t
X -- requires gen_pointer and write_wP to make wren_bind_c_function work
X -- requires fetch_wP to make CCALL work
X Check all peek and poke operations to be within the_store;
What other operations would need a bounds check?
Replace assert() with something that longjmps to reset wren
Extending:
disasm.wren could try to find names for GLOBAL_FETCH and GLOBAL_STORE
(BTW, consider renaming to SETG and REFG for compatibility with REF/SET prims?)
Consider encoding string length after PUSH_STRING to avoid strlen()
To add function locals (e.g., "let xxx : yyy in ...") we'd need an additional field
for the number of locals; it would be used along with arity to allocate and drop
stack cells on function call and tail call. The locals would live after the
arguments on the stack.
Now that we've moved the arity to the first byte of the function body in code space,
the locals counts can go in that same byte.
Provide array syntax; bounds checking would work for all of
the_store if the first word of the store was the store size. I.e., 0[index] = ...
The Forth CREATE word makes a new dict word that simply returns its code pointer.
We could do the same for ARRAY, and store the size in the first couple bytes.
Otherwise we need a prim to return a value (and index) size to compute offsets.
Do we also need an align prim to optimize access time?
Readline support, e.g., https://github.com/Helius/microrl/network
(but microrl wants to prompt after every newline; need to be smarter)
===========================================================================
2018-10-09
Cut:
# Assumes wValues are 4 bytes (not true on LP64); assumes little endian
#fun byte_mask n = not (sla 0xff (n*8))
#fun byte_or orig byte new = orig & (byte_mask byte) | (sla (new & 0xff) (byte*8))
#fun aligned addr = addr & (not 0x03)
#fun offset addr = addr & 0x03
#
#fun cpoke addr x =
# poke (aligned addr) (byte_or (peek (aligned addr)) (offset addr) x)
# This isn't reliable. Probably need to hard wire this anyways
## Dangerous stuff here, don't play unless you understand!
#fun execute xt =
# poke (find 'exec_helper') 0x09090909 ;
# poke (find 'exec_helper'-1) (0x08 + sla (xt-c0) 16)
#
## Don't ever, ever call this!
#fun exec_helper = cr;cr
## End dangerous stuff
# Use execute on xt's of no argument functions.
# Example:
# fun test = puts 'Hello World';cr
# You can run test by executing it's xt.
# execute (find 'test')
2018-10-07
cat boot.wren disasm.wren dasm_test.wren | ./wren
2018-10-07
after dictionary and header changes...
wren e$ cat boot.wren disasm.wren | ./wren
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Library Loaded
2863 bytes (69%) remaining.
0
> > > > > > > > >
Disassembler Loaded
1474 bytes (35%) remaining.
0
>
wren e$
before dictionary and header changes...
wren e$ cat boot.wren disasm.wren | ./wren
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Library Loaded
2847 bytes (69%) remaining.
0
> > > > > > > > >
Disassembler Loaded
1372 bytes (33%) remaining.
0
>
wren e$
wren e$ ./benchmark
> > 9227465
>
real 0m0.449s
user 0m0.445s
sys 0m0.002s
wren e$ ./benchmark
> > 9227465
>
real 0m0.449s
user 0m0.445s
sys 0m0.002s
wren e$ ./benchmark
> > 9227465
>
real 0m0.452s
user 0m0.447s
sys 0m0.002s
wren e$