 
 
 	'g': (x, y, dir, index, stack) ->
-		stack.push "programState.get(#{stack.popish()}, #{stack.popish()})"
+		stack.push "programState.get(#{stack.pop()}, #{stack.pop()})"
 		return
 
 


makeStack = (uid) ->
	stack = []
	pre = []
	read = []
	int = []
	post = []
	exit = false

	stackish = {}

	stackish.push = ->
		Array::push.apply stack, arguments
		return

	stackish.popish = ->
		if stack.length > 0
			stack.pop()
		else
			name = "p#{uid}_#{pre.length}"
			# use const once node supports it
			pre.push "var #{name} = programState.pop()"
			name

	stackish.peek = ->
		if stack.length
			stack[stack.length - 1]
		else
			name = "p#{uid}_#{pre.length}"
			# use const once node supports it
			pre.push "var #{name} = programState.peek()"
			name

	makeNext = (methodName) ->
		->
			name = "r#{uid}_#{read.length}"
			# use const once node supports it
			read.push "var #{name} = programState.#{methodName}()"
			name

	stackish.next = makeNext 'next'
	stackish.nextChar = makeNext 'nextChar'

	stackish.out = (entry) ->
		post.push entry
		return

	stackish.dump = ->
		int.push """
			#{pre.join '\n'}
			#{read.join '\n'}
			programState.push(#{stack.join ', '})
			#{post.join '\n'}
		"""

		stack = []
		pre = []
		read = []
		post = []

		return

	stackish.int = (entry) ->
		int.push entry
		return

	stackish.stringify = ->
		"""
			#{int.join '\n'}
			#{if exit then 'programState.exit()' else ''}
		"""


	stackish.exit = ->
		exit = true

	stackish


StackingCompiler.assemble = (path) ->


	'p': (x, y, dir, index, stack, from, to) ->
		stack.dump()
		stack.pushChunk """
			programState.put(
				#{stack.pop()},
				#{stack.pop()},
				#{stack.pop()},
				#{x}, #{y}, '#{dir}', #{index},
				'#{from}', '#{to}'
			)
