module test_mini_cecil_with_env.

import mini_cecil_abstract_syntax env algebra mini_cecil_with_env.

type test	int -> value -> o. % tests that sould succeed
type failtest	int -> value -> o. % tests that should fail (\Prolog says no)

test 1 V :-
	(evalExpr (intLiteral 3) H V).

test 2 V :-
	(evalExpr true H V).

test 3 V :-
	(evalExpr false H V).

test 4 V :-
	(evalExpr (msgExpr "theVoid" nil) H V).

test 5 V :-
	(evalExpr (msgExpr "and" (true::false::nil)) H V).

test 6 V :-
	(evalExpr
	 (msgExpr "add" ((msgExpr "1" nil)::(intLiteral 4)::nil)) H V).

test 7 V :-
	(evalExpr (varExpr "x") (bind "x" (inValue (inInteger 541))) V).

% an environment to use for tests...

type an_env	(environ string bindable) -> o.
an_env (overlay (bind "i" (inValue (inInteger 541)))
	(overlay (bind "n" (inValue (inInteger 227)))
	(overlay (bind "b" (inValue (inTruthValue tt)))
	(overlay (bind "inc"
		  (inProcedureClosure
			(makeProcClosure
				empty_environ
				("y"::nil)
				(body
				  (seqStmt nil)
				  (return (msgExpr "add"
					    ((varExpr "y")::
					     (intLiteral 1)::nil)))))))

	empty_environ)))).

test 8 V :-
	an_env H,
	(evalExpr (msgExpr "add"
				((msgExpr "1" nil)::
				 (msgExpr "mult" ((varExpr "i")::
						  (varExpr "n")::nil))::
				 nil))
		    H V).

test 9 V :-
	an_env H,
	(evalExpr (procCallExpr "inc" ((varExpr "i")::nil)) H V).

failtest 1 V :-  % should fail
	(evalExpr (varExpr "x") empty_environ V).
