about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--subx/011run.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/subx/011run.cc b/subx/011run.cc
index 5d2aab8a..3a57f055 100644
--- a/subx/011run.cc
+++ b/subx/011run.cc
@@ -206,6 +206,10 @@ void load(const program& p) {
       const line& l = seg.lines.at(j);
       for (int k = 0;  k < SIZE(l.words);  ++k) {
         const word& w = l.words.at(k);
+        if (SIZE(w.data) != 2) {
+          raise << "token '" << w.data << "' is not a hex byte\n" << end();
+          return;
+        }
         uint8_t val = hex_byte(w.data);
         if (trace_contains_errors()) return;
         write_mem_u8(addr, val);
@@ -234,6 +238,23 @@ uint8_t hex_byte(const string& s) {
   return static_cast<uint8_t>(result);
 }
 
+:(scenarios parse_and_load)
+:(scenario load_error)
+% Hide_errors = true;
+== 0x1
+05 cab
++error: token 'cab' is not a hex byte
+
+//: helper for tests
+:(code)
+void parse_and_load(const string& text_bytes) {
+  program p;
+  istringstream in(text_bytes);
+  parse(in, p);
+  if (trace_contains_errors()) return;  // if any stage raises errors, stop immediately
+  load(p);
+}
+
 //:: run
 
 :(before "End Initialize Op Names(name)")