about summary refs log tree commit diff stats
path: root/subx/011run.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-08-08 16:55:54 -0700
committerKartik Agaram <vc@akkartik.com>2018-08-08 16:55:54 -0700
commitf8bd7ed527c600a5c022b039966c508d3adb0bc2 (patch)
tree1591792f9c10e5b535db6524849e22c4cb8fe45c /subx/011run.cc
parent03e72be63b23fecace199e19953a0aa192f5002b (diff)
downloadmu-f8bd7ed527c600a5c022b039966c508d3adb0bc2.tar.gz
4494
Hacky test. I'm creating a helper to run tests just for this layer. But
I won't be able to do this when I want to selectively run just
transforms below some level.
Diffstat (limited to 'subx/011run.cc')
-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)")