Skip to content

Commit ff9edde

Browse files
committed
uxn exceptions work
1 parent ee70c08 commit ff9edde

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

examples/exceptions.cal

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
include "cores/select.cal"
22
include "std/io.cal"
33

4-
func __arm64_exception begin
5-
&_cal_exception Exception.msg + "Unhandled exception: %s" printf new_line
6-
1 exit
7-
end
8-
94
func exception_msg begin
105
&_cal_exception Exception.msg +
116
end
127

8+
func __uxn_exception begin
9+
exception_msg c"Unhandled exception: %s" printf new_line
10+
1 exit
11+
end
12+
1313
func error foo begin
1414
c"hi im an exception" throw
1515
end

source/backends/uxn.d

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class BackendUXN : CompilerBackend {
130130
override long MaxInt() => 0xFFFF;
131131

132132
override string DefaultHeader() => "
133+
|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
133134
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
134135
";
135136

@@ -216,6 +217,7 @@ class BackendUXN : CompilerBackend {
216217
}
217218

218219
override void Init() {
220+
WarnNoInfo("This backend is slightly broken. Don't use implement or printf");
219221
output ~= "|0 @vsp $2 @arraySrc $2 @arrayDest $2\n";
220222
output ~= "|100\n";
221223
output ~= "@on-reset\n";
@@ -264,6 +266,13 @@ class BackendUXN : CompilerBackend {
264266
}
265267
}
266268

269+
output ~= "@memcpy 01\n";
270+
output ~= "&length 0000\n";
271+
output ~= "&srcBank 0000\n";
272+
output ~= "&srcAddr 0000\n";
273+
output ~= "&dstBank 0000\n";
274+
output ~= "&dstAddr 0000\n";
275+
267276
// pad for the stack
268277
output ~= "|e0000\n";
269278
}
@@ -1104,15 +1113,14 @@ class BackendUXN : CompilerBackend {
11041113
output ~= format("#ffff ;global_%s STA2\n", Sanitise("_cal_exception"));
11051114

11061115
// copy exception message
1107-
// TODO: make this less bloat
1108-
foreach (i ; 0 .. 3) {
1109-
output ~= "DUP2 LDA2\n";
1110-
output ~= format(
1111-
";global_%s #%.2x ADD2 STA2\n", Sanitise("_cal_exception"), i + 2
1112-
);
1113-
output ~= "#0002 ADD2\n";
1114-
}
1115-
output ~= "POP2\n";
1116+
output ~= "#0006 ;memcpy/length STA2\n";
1117+
output ~= "#0000 ;memcpy/srcBank STA2\n";
1118+
output ~= ";memcpy/srcAddr STA2\n";
1119+
output ~= "#0000 ;memcpy/dstBank STA2\n";
1120+
output ~= format(
1121+
";global_%s INC2 INC2 ;memcpy/dstAddr STA2\n", Sanitise("_cal_exception")
1122+
);
1123+
output ~= ";memcpy .System/expansion DEO2\n";
11161124

11171125
CompileReturn(node);
11181126
}

0 commit comments

Comments
 (0)