Jump to content

  • Log In with Google      Sign In   
  • Create Account





Back in the saddle

Posted by ApochPiQ, 03 November 2012 · 699 views

Epoch
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:

//
// 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")
}


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:

structure testwrapper<type T> :
	T contents,
	string tag



entrypoint : 
{
	testwrapper<integer> intwrap = 42, "number"
	testwrapper<string> strwrap = "test", "text"

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

	print("Pass")
}



It'll be much harder to implement generic functions:

add<type T> : T a, T b -> T sum = a + b

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

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

	print("Pass")
}


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.




Cool.

December 2014 »

S M T W T F S
 123456
78910111213
14151617181920
21 22 2324252627
28293031   

Recent Entries

Recent Comments

PARTNERS