Skip to content

Commit 7c86461

Browse files
gh-115: Add operator REFUTE.
1 parent 229c1c5 commit 7c86461

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

docs/SPECIFICATION.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@
841841
842842
- `BOOL: ASSERT(ANY: value)` = MUST raise a runtime error if `value` is falsey according to the language's truthiness rules. On success, it MUST return `TRUE`.
843843
844+
- `BOOL: REFUTE(~BOOL: cond)` = MUST raise a runtime error if `cond` is truthy according to the language's truthiness rules. On success, it MUST return `TRUE`.
845+
844846
- `THROW()` or `THROW(INT|STR: a1, ..., INT|STR: aN)` = MUST raise a runtime error. When one or more arguments are supplied, the error message MUST be formed by concatenating those arguments using the same rendering rules as `PRINT`, but without a trailing newline. When no arguments are supplied, the error message MUST be `"Exception thrown"`.
845847
846848
- `BOOL: MAIN()` = MUST return `TRUE` when the call site is in the primary program source and `FALSE` when the call site is executing from imported module code. The result MUST depend on the source location of the call expression rather than on the dynamic caller stack.

src/builtins.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6448,6 +6448,16 @@ static Value builtin_assert(Interpreter* interp, Value* args, int argc, Expr** a
64486448
return value_bool(true);
64496449
}
64506450

6451+
// REFUTE(~BOOL: cond):BOOL
6452+
static Value builtin_refute(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
6453+
(void)arg_nodes; (void)env;
6454+
6455+
if (value_truthiness(args[0])) {
6456+
RUNTIME_ERROR(interp, "Refutation failed", line, col);
6457+
}
6458+
return value_bool(true);
6459+
}
6460+
64516461
static Value builtin_throw(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
64526462
(void)arg_nodes; (void)env;
64536463

@@ -9102,6 +9112,7 @@ static BuiltinFunction builtins_table[] = {
91029112

91039113
// Control
91049114
{"ASSERT", 1, 1, builtin_assert},
9115+
{"REFUTE", 1, 1, builtin_refute},
91059116
{"THROW", 0, -1, builtin_throw},
91069117

91079118
// Variables
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REFUTE(TRUE)

tests/cases/passing/refute.pre

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REFUTE(FALSE)
2+
REFUTE(0d0)
3+
REFUTE(0d0.0)
4+
REFUTE("")

0 commit comments

Comments
 (0)