~rabbits/uxn

ref: 8bf99e6d7620b8bf54fe8ae6031969ec39a0ccb6 uxn/etc/asma-test.sh -rwxr-xr-x 1.8 KiB
8bf99e6dneauoire Changed the screen.tal colors to fit the Varvara docs 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
set -e
cd "$(dirname "${0}")/.."
rm -rf asma-test
mkdir asma-test
cd asma-test

build_asma() {
    sed -ne '/^( devices )/,/^( vectors )/p' ../projects/software/asma.tal
    cat <<EOD
|0100 @reset
	;&source-file ;&dest-file ;asma-assemble-file JSR2
	;asma/error LDA2 #0000 NEQ2 JMP BRK
	#0000 DIV

	&source-file "in.tal 00
	&dest-file "out.rom 00

EOD
	sed -ne '/%asma-IF-ERROR/,$p' ../projects/software/asma.tal
}

expect_failure() {
    cat > 'in.tal'
    if ../bin/uxncli asma.rom > asma.log 2>/dev/null || ! grep -qF "${1}" asma.log; then
        echo "error: asma didn't report error ${1} in faulty code"
		tail asma.log
        exit 1
    fi
}

echo 'Assembling asma with uxnasm'
build_asma > asma.tal
../bin/uxnasm asma.tal asma.rom > uxnasm.log
find ../projects -type f -name '*.tal' -not -name 'blank.tal' | sort | while read F; do
	echo "Comparing assembly of ${F}"
	BN="$(basename "${F%.tal}")"

	if ! ../bin/uxnasm "${F}" "uxnasm-${BN}.rom" > uxnasm.log; then
		echo "error: uxnasm failed to assemble ${F}"
		tail uxnasm.log
		exit 1
	fi
	xxd "uxnasm-${BN}.rom" > "uxnasm-${BN}.hex"

	cp "${F}" 'in.tal'
	if ! ../bin/uxncli asma.rom > asma.log; then
		echo "error: asma failed to assemble ${F}, while uxnasm succeeded"
		tail asma.log
		exit 1
	fi
	xxd 'out.rom' > "asma-${BN}.hex"

	diff -u "uxnasm-${BN}.hex" "asma-${BN}.hex"
done
expect_failure 'Invalid hexadecimal: $defg' <<'EOD'
|1000 $defg
EOD
expect_failure 'Invalid hexadecimal: #defg' <<'EOD'
|1000 #defg
EOD
expect_failure 'Address not in zero page: .hello' <<'EOD'
|1000 @hello
	.hello
EOD
expect_failure 'Address outside range: ,hello' <<'EOD'
|1000 @hello
|2000 ,hello
EOD
expect_failure 'Label not found: hello' <<'EOD'
hello
EOD
expect_failure 'Macro already exists: %abc' <<'EOD'
%abc { def }
%abc { ghi }
EOD
expect_failure 'Memory overwrite: SUB' <<'EOD'
|2000 ADD
|1000 SUB
EOD

echo 'All OK'