#!/bin/sh

source $testsuitedir/lib_test.sh

cat > PROGRAMME << EOP
	:new INT*6, STR
	3 -> &0
	4 -> &1
	"invalid" -> &6
	:call @&6 &0
	:shutdown
:label function
	@:current + 1 -> (:current+2)
	@(:current+1) * @(:current+2) -> (:current+2)
	:return
:label other_function
	@:current - 1 -> (:current+2)
	@(:current+1) * @(:current+2) -> (:current+2)
	:return
EOP

cat > MEMOIRE_INITIALE << EOM
# Memory:
# Aliases:
# Free addresses:
# Free blocks:
# End of memory
EOM

cat > MEMOIRE_REF << EOM
# Memory:
# Aliases:
# Free addresses:
# Free blocks:
# End of memory
EOM

cat > STDOUT_REF << EOS
EOS

cat > STDERR_REF << EOS
+---------------------------------------------------------------------------------------------+
| File PROGRAMME.setlggasm, line 5 > Runtime error (ILL): Inexistant label invalid to jump to |
+---------------------------------------------------------------------------------------------+
EOS

cat > CODE_RETOUR_REF << EOC
129
EOC

test_basique

cat > PROGRAMME << EOP
	:new INT*6, INT
	3 -> &0
	4 -> &1
	17 -> &6
	:call @&6 &0
	:shutdown
:label function
	@:current + 1 -> (:current+2)
	@(:current+1) * @(:current+2) -> (:current+2)
	:return
:label other_function
	@:current - 1 -> (:current+2)
	@(:current+1) * @(:current+2) -> (:current+2)
	:return
EOP

cat > MEMOIRE_INITIALE << EOM
# Memory:
# Aliases:
# Free addresses:
# Free blocks:
# End of memory
EOM

cat > MEMOIRE_REF << EOM
# Memory:
# Aliases:
# Free addresses:
# Free blocks:
# End of memory
EOM

cat > STDOUT_REF << EOS
EOS

cat > STDERR_REF << EOS
+---------------------------------------------------------------------------------------------------------------------------+
| File PROGRAMME.setlggasm, line 5 > Runtime error (SEGV): Read to address &6 incorrect as value type is INT instead of STR |
+---------------------------------------------------------------------------------------------------------------------------+
EOS

cat > CODE_RETOUR_REF << EOC
129
EOC

test_basique
