🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Back in the saddle

Published November 04, 2012
Advertisement
So once again I've dug out and dusted off the code for Epoch. The last several days have been pretty productive; I finished off the implementation and testing of algebraic sum types, and now the following program compiles and passes all tests:

[source]//
// LISTOFINTEGERS.EPOCH
//
// Simple implementation of a singly linked list holding integers
//


type listnode : list | nothing

structure list :
integer value,
listnode next


prepend : list ref thelist, integer value
{
list newlist = value, thelist
thelist = newlist
}


append : list ref thelist, integer value
{
append_recurse(thelist, thelist.next, value)
}


append_recurse : list ref thelist, nothing, integer value
{
list newlist = value, nothing
thelist.next = newlist
}

append_recurse : list ref thelist, list ref tail, integer value
{
append_recurse(tail, tail.next, value)
}


next : list ref thelist -> listnode tail = thelist.next
next : nothing -> listnode tail = nothing

checkvalue : list ref thelist, integer expected
{
assert(thelist.value == expected)
}

checkvalue : nothing, integer expected
{
print("Unexpected end of list")
assert(false)
}


dumplist : list ref thelist
{
listnode nn = thelist.next
dumplist(nn)
}

dumplist : nothing
{
}


entrypoint :
{
list numbers = 1, nothing

append(numbers, 2)
append(numbers, 3)
prepend(numbers, 0)

dumplist(numbers)

assert(numbers.value == 0)

listnode node = next(numbers)
checkvalue(node, 1)

node = next(node)
checkvalue(node, 2)

node = next(node)
checkvalue(node, 3)

print("Pass")
}[/source]

I'm pretty happy with that, considering I've been gone for the last several months (jeez... was it really April that I made the last release!?). (For the record, I haven't been slacking off... I just shipped this little game nobody's ever heard of during that time.)

Next up, I'm tackling generic programming. The easy part will be generic structures:

[source]structure testwrapper :
T contents,
string tag



entrypoint :
{
testwrapper intwrap = 42, "number"
testwrapper strwrap = "test", "text"

assert(intwrap.contents == 42)
assert(strwrap.contents == "test")

print("Pass")
}[/source]


It'll be much harder to implement generic functions:

[source]add : T a, T b -> T sum = a + b

entrypoint :
{
integer foo = add(40, 2)
integer bar = add(3.0, 0.14)

assert(foo == 42)
assert(bar == 3.14)

print("Pass")
}[/source]

Hopefully I can knock out the quick foundation of generic structures over this weekend (it's pretty trivial) and then dig into generic code gen later on.


So that's what's up.
2 likes 1 comments

Comments

3Ddreamer
Cool.
November 05, 2012 02:41 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement