You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For now, this is for record-keeping and discussion. I don't want to implement too many examples just yet, because our arrays/variables are still in flux. For now, I'll just sketch them out.
My goal is to keep these examples minimal, but still interesting. Some of these examples might require us to implement more features. For example, I think we want the other arithmetic and comparison operations (which should be straightforward to implement). Other types (e.g. floats or strings) might be nice, but probably not necessary.
2D Point
Very simple example for testing function inlining, and maybe branch speculation. This is so simple it's boring, but that's why we have other examples.
Fields [x, y] - x and y are the coordinates
Functions init(x, y) - returns a reference to a new point, initialized to x and y getX(p), getY(p), setX(p, x), setY(p, y) - getters and setters equals(p1, p2) - compares two points, returns a boolean
Example program
User provides a list of points as inputs, check if any of those points equals some predefined point.
Vector
An array that automatically grows as needed. Again, we can test inlining and branch speculation, but we also get bounds check elimination and maybe code motion.
Note: We need multiplication and comparison for this.
Fields [size, length, arr] - size is the physical size of the allocated array, length is the portion that is being used, arr is a reference to an array of size size
Functions init() - returns a reference to a new vector of size 1 and length 0 set(v, i, x) - sets v[i] to x, after ensuring 0 <= i. Grows the internal array (by doubling its size) if necessary, and zeros everything between the old length and the new length. get(v, i) - returns v[i], after ensuring 0 <= i < length length(v) - returns the length of v iter(v, f) - iterates over all (used) elements, applying f to each element
List
A doubly-linked list. We can test inlining and branch speculation. On second thought, this example doesn't really give us anything new.
Fields [val, next, prev] - val is the integer stored in the cell, next and prev are references to the next and previous cells
TODO. Still thinking about this, will probably start with the example in #83.
This is where strings would be nice, to represent method names. We could work around this by using (unique) numbers to represent method names, but it would be pretty unreadable. An alternative might be to implement symbols, like in Racket or Ruby. Basically immutable strings that you can only compare for equality.
The text was updated successfully, but these errors were encountered:
For now, this is for record-keeping and discussion. I don't want to implement too many examples just yet, because our arrays/variables are still in flux. For now, I'll just sketch them out.
My goal is to keep these examples minimal, but still interesting. Some of these examples might require us to implement more features. For example, I think we want the other arithmetic and comparison operations (which should be straightforward to implement). Other types (e.g. floats or strings) might be nice, but probably not necessary.
2D Point
Very simple example for testing function inlining, and maybe branch speculation. This is so simple it's boring, but that's why we have other examples.
Fields
[x, y]
-x
andy
are the coordinatesFunctions
init(x, y)
- returns a reference to a new point, initialized tox
andy
getX(p)
,getY(p)
,setX(p, x)
,setY(p, y)
- getters and settersequals(p1, p2)
- compares two points, returns a booleanExample program
User provides a list of points as inputs, check if any of those points equals some predefined point.
Vector
An array that automatically grows as needed. Again, we can test inlining and branch speculation, but we also get bounds check elimination and maybe code motion.
Note: We need multiplication and comparison for this.
Fields
[size, length, arr]
-size
is the physical size of the allocated array,length
is the portion that is being used,arr
is a reference to an array of sizesize
Functions
init()
- returns a reference to a new vector of size 1 and length 0set(v, i, x)
- setsv[i]
tox
, after ensuring0 <= i
. Grows the internal array (by doubling its size) if necessary, and zeros everything between the old length and the new length.get(v, i)
- returnsv[i]
, after ensuring0 <= i < length
length(v)
- returns the length ofv
iter(v, f)
- iterates over all (used) elements, applyingf
to each elementList
A doubly-linked list. We can test inlining and branch speculation. On second thought, this example doesn't really give us anything new.
Fields
[val, next, prev]
-val
is the integer stored in the cell,next
andprev
are references to the next and previous cellsFunctions
cons(v, l)
,head(l)
,tail(l)
,append(l1, l2)
,fold(f, acc, l)
- self-explanatorylength(l)
,iter(f, l)
,map(f, l)
,filter(p, l)
- implemented withfold
Object System
TODO. Still thinking about this, will probably start with the example in #83.
This is where strings would be nice, to represent method names. We could work around this by using (unique) numbers to represent method names, but it would be pretty unreadable. An alternative might be to implement symbols, like in Racket or Ruby. Basically immutable strings that you can only compare for equality.
The text was updated successfully, but these errors were encountered: