I'm still not entirely sure I believe that it works

Published November 13, 2012
Advertisement
The following Epoch program now compiles and executes:

//
// GENERICLIST.EPOCH
//
// Simple implementation of a singly linked list holding arbitrary data
//


type listnode : list | nothing

structure list :
T value,
listnode next


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


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

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


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

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

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

checkvalue : nothing, T 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, 666)
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, 666)

passtest()
}


This is the first implementation of a generic data type container in Epoch.


Suffice it to say it took a monumental effort to pull that off, and I am thoroughly exhausted. The fact that it's 4 AM has nothing to do with that.


Lots of cleanup needed now... there's a host of ugly hacks and leftover cruft floating around the code, and it'll take some time to improve things to the point where I'm happy with the implementation of templates in the language.


The flip side, though, is that I built a working implementation of templates in what amounts to a couple of weekends of work and a spare evening, so I'm pretty darn happy with that.
2 likes 1 comments

Comments

Jason Z
Congrats, and goodnight :)
November 13, 2012 01:41 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement