diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-11-26 20:44:52 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-11-26 20:44:52 -0800 |
commit | 6515192306e1c37cea8ec1dddee3556fba44a5d6 (patch) | |
tree | add4ac3b5f529610952e75c4f98d870809f5d95b /038new_text.cc | |
parent | eb2b6cd21e06b3a421ede3f7a6ae78b932dcab19 (diff) | |
download | mu-6515192306e1c37cea8ec1dddee3556fba44a5d6.tar.gz |
3694
Fix CI, broken by commit 3691.
Diffstat (limited to '038new_text.cc')
-rw-r--r-- | 038new_text.cc | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/038new_text.cc b/038new_text.cc index 493c1b50..d65ac63d 100644 --- a/038new_text.cc +++ b/038new_text.cc @@ -152,7 +152,50 @@ string read_mu_text(int address) { return tmp.str(); } -//:: 'cheating' by using the host system +//:: some miscellaneous helpers now that we have text + +//: assert: perform sanity checks at runtime + +:(scenario assert) +% Hide_errors = true; // '%' lines insert arbitrary C code into tests before calling 'run' with the lines below. Must be immediately after :(scenario) line. +def main [ + assert 0, [this is an assert in Mu] +] ++error: this is an assert in Mu + +:(before "End Primitive Recipe Declarations") +ASSERT, +:(before "End Primitive Recipe Numbers") +put(Recipe_ordinal, "assert", ASSERT); +:(before "End Primitive Recipe Checks") +case ASSERT: { + if (SIZE(inst.ingredients) != 2) { + raise << maybe(get(Recipe, r).name) << "'assert' takes exactly two ingredients rather than '" << inst.original_string << "'\n" << end(); + break; + } + if (!is_mu_scalar(inst.ingredients.at(0))) { + raise << maybe(get(Recipe, r).name) << "'assert' requires a boolean for its first ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + break; + } + if (!is_literal_text(inst.ingredients.at(1)) && !is_mu_text(inst.ingredients.at(1))) { + raise << maybe(get(Recipe, r).name) << "'assert' requires a text as its second ingredient, but got '" << inst.ingredients.at(1).original_string << "'\n" << end(); + break; + } + break; +} +:(before "End Primitive Recipe Implementations") +case ASSERT: { + if (!ingredients.at(0).at(0)) { + if (is_literal_text(current_instruction().ingredients.at(1))) + raise << current_instruction().ingredients.at(1).name << '\n' << end(); + else + raise << read_mu_text(ingredients.at(1).at(0)) << '\n' << end(); + } + break; +} + + +//: 'cheating' by using the host system :(before "End Primitive Recipe Declarations") _READ, |