-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlang.txt
297 lines (219 loc) · 6.4 KB
/
lang.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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
## TODO:
can we allow commas between arguments in xlist/mlist to make it more like conventional programming langauges?
make literal frame in the compiler not use object momory. ask VM to take the byte codes and create literal frame using object memory
-> hcl->code.lit.arr must be composed of plain data. not using object memory
-> it must ask VM(locally via a function call, remotely via some communication) to create objects in the object memory
static class -> collect class info(variables information) in the compiler
dyna-class -> compiler doesn't know about classes in advance
for static cleases, super.var-name can be allowed.
for dyna-clases, the super prefix is now allowed for varibles. it's allowed for method calls only.
double-check symbol and dsymbol resolution in set, set-r, defun, defclass to decide how to make it more logical and reasonable
assignment syntax
(k := 20) -> (set k 20)
k := 20 -> (set k 20)
[a, b] := (multi-retvar-fun 10 20) -> (set-r a b (multi-retvar-fun 10 20))
implement module -> ::, ., or what notation?
implement namespace -> ::, ., or what notation?
review the . notation used for C-module loading... may have to change it
dynamic byte array is supported but we need yet to support byte-string(byte-array) constant
b"..." or B"..." for an byte string constant notation
u"..." or U"..." for an explicit unicode string constant notation?
-> change u to c???
#[ ] normal array?
#b[ ] byte array??
#c[ ] charcter array??
#w[ ] word array??
#hw[ ] half-word array??
#u8[ ]
#u16[ ]
#u32[ ]
#u64[ ]
#i8[ ]
#i16[ ]
#i32[ ]
#i64[ ]
allow b'X' or 'X' in byte array in #b[] notation?
signal handling
full oop
make basic branded types to an object if possible.
for example (#[10 20]:at 1)
isn't : for method call confliting with key value spearator in a dictionary?
default return value for some class methods.
:: method -> return what??
:* method -> return the new instance
normal method -> return the last evaluated value?
## dictionary list (DIC)
#{ 1 2 3 4 }
#{ 1: 2, 3: 4}
#{} -> empty dictionary
#{ 1 } -> error, no value. dictionary requires even number of items.
## array list
[ 1 2 3 4]
[ 1, 2, 3, 4 ]
[] -> empty array
## byte array list
#[ 1 2 3 4 ]
#[ 1, 2, 3, 4 ]
each item must be in the byte range.
if a given value is not a number in the allowed range, an exception error is raised.
(try
(set a 20)
#[ 1 2 3 (+ a 300)] ; this throws an catchable exception.
catch(e)
(printf "EXCEPTION - %O\n" e)
)
## non-executable list (QLIST)
#(1 2 3 4)
#(1 2 3 4 . 5)
#() -> same as null
comma not allowed to seperate items.
## varaible declaration list (VLIST)
| a b c |
## class declaration with methods.
(defclass X
| x y | ; instance variables
:: | bob jim | ; class variables
; instance variables and class variables must not collide with those of parent classes.
; they must not collide with method names of parent classes
(set bob "Bob") ; can access class variables. disallowed to access instance variables
(defun setX (a)
(set x a)
)
; instance method. a method name must not collide with instance variable names and class variable names.
; the name can be the same as method names of parent classes.
(defun K (a b)
(self:Y a)
(return (+ a b x y))
)
(defun Y (a)
(printf "Y=>%d [%s]\n" a bob)
)
(defun :: KK (a b)
(printf "K=>%s\n" bob) ; a class method can access class variables but not instance variables
(return (+ a b))
)
(set jim (lambda (a b) (+ a b))) ; an anonymous function created
)
(set r (object-new X))
(r:Y 10)
(printf ">>%d\n" (X:KK 77 99))
## method invocation
send the message aaa to the receiver
(self:aaa)
send the message aaa to the receiver but let it resolve the method in the superclass side.
(super:aaa)
send the message dump to the object pointed to by x with arguments 1, 2, 3.
(x:dump 1 2 3)
## method types
- class method
- class instantiation method
(defclass P
| x y |
(defun :* new ()
(set x 1)
(set y 1)
(return self)
)
(defun get-x() x)
(defun get-y() y)
)
(defclass X :: P
| x y |
(defun :* new (a b)
(super:new)
x = a
y = b
(return self)
)
(defun get-xx() x)
(defun get-yy() y)
)
(set t (X:new 10 20)) ;t is an instance of X
(printf "%d %d %d %d\n" (t:get-x) (t:get-y) (t:get-xx) (t:get-yy)) ; must print 1 1 10 20
(t:new 100 300) ;the x, y in the X part get reset to 100 and 300. doesn't create a new instance
(printf "%d %d %d %d\n" (t:get-x) (t:get-y) (t:get-xx) (t:get-yy)) ; must print 1 1 100 300
- instance method
## dynamic dispatching by method name
(defclass X
(defun t1 (x) (printf "t1 = %d\n" (+ x x x)))
(defun t2 (x) (printf "t2 = %d\n" (* x x x)))
)
(defun get-name-1() "t1")
(defun get-name-2() "t2")
(set x (object-new X))
(x:(get-name-1) 100) ; must be same as (x:t1 100)
(x:(get-name-2) 100) ; must be same as (x:t2 100)
## Something to look into..
normal function call
(f arg1 arg2 arg3)
(rcv f arg1 arg2)
## dynamic method invocation???
(X:(f) arg1 arg2)
as long as f returns a symbol, it can also invoke a method??
(defun getX() X) ; ->it must return an object
((getX)->show "hello")
X.Y
push X
push_symbol Y
lookup
(X.Y)
push X
push_symbol Y
lookup
call 0
X.Y.Z
push X
push_symbol Y
lookup
push_symbol Z
lookup
--- if this is within a method, it must become push_instvar
self.x
push self
push symbol x
lookup
fun f(a, b)
{
}
fun f(a, b) -> (c, d)
{
}
class X
{
var x, y, z
var! printer;
printer := Printer.new();
fun! new(a, b)
{
return super.new().init(a, b);
}
fun init(a, b)
{
}
fun show(a, b)
{
Printer.dump(a, b);
}
}
x := X.new(10, 20);
x.show (40, 50);
---------------
variadic arguments -> supported
multiple return variables -> supported
(defun ff(a b :: x y z)
(set x (+ a b))
(set y (+ x x))
(set z (+ 999 x))
)
(set-r v1 v2 v3 (ff 10 20))
(printf "%d %d %d\n" v1 v2 v3)
variadic multiple return variables -> not supported as of now
(defun ff(a b :: x y z ...) <--- can i support something like this???
(set x (+ a b))
(set y (+ x x))
(set z (+ 999 x))
)
(set-r v1 v2 v3 (ff 10 20))
(printf "%d %d %d\n" v1 v2 v3)
since va-get is used to get a variadic argument, can i create vr-put
to set a variadic return variable?