Skip to content

Commit 63c9f04

Browse files
gh-196: Make permanent freezing ops use STR.
Closes #196.
1 parent da387fd commit 63c9f04

7 files changed

Lines changed: 23 additions & 21 deletions

File tree

docs/SPECIFICATION.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,9 @@
709709

710710
- `STR SIGNATURE(SYMBOL name)` = MUST return a textual signature for `name`. If `name` denotes a user-defined function, the result MUST use the canonical function-signature form of this specification. For any other visible binding, the result MUST be `TYPE name`.
711711

712-
-- `BOOL FREEZE(STR name)`, `BOOL THAW(STR name)`, and `BOOL PERMAFREEZE(SYMBOL name)` = MUST modify the mutability state of the binding designated by `name`. `FREEZE` MUST prevent reassignment and deletion until thawed. `PERMAFREEZE` MUST permanently prevent reassignment, deletion, and later thawing. `THAW` MUST clear a non-permanent freeze, MUST raise a runtime error when applied to a permanently frozen binding, and MUST otherwise succeed as a no-op when applied to a binding that is not currently frozen. `FREEZE`, `THAW`, and `PERMAFREEZE` MUST each return `FALSE` on success and MUST raise a runtime error if `name` is undefined.
712+
- `BOOL FREEZE(STR name)`, `BOOL THAW(STR name)`, and `BOOL PERMAFREEZE(STR name)` = MUST modify the mutability state of the binding designated by `name`. `FREEZE` MUST prevent reassignment and deletion until thawed. `PERMAFREEZE` MUST permanently prevent reassignment, deletion, and later thawing. `THAW` MUST clear a non-permanent freeze, MUST raise a runtime error when applied to a permanently frozen binding, and MUST otherwise succeed as a no-op when applied to a binding that is not currently frozen. `FREEZE`, `THAW`, and `PERMAFREEZE` MUST each return `FALSE` on success and MUST raise a runtime error if `name` is undefined.
713713

714-
-- `BOOL FROZEN(STR name)` and `BOOL PERMAFROZEN(SYMBOL name)` = MUST report the freeze state of `name`. `FROZEN` MUST return `TRUE` for any frozen or permanently frozen binding and `FALSE` otherwise. `PERMAFROZEN` MUST return `TRUE` only for permanently frozen bindings and `FALSE` otherwise. If `name` is undefined, both operators MUST return `FALSE`.
714+
- `BOOL FROZEN(STR name)` and `BOOL PERMAFROZEN(STR name)` = MUST report the freeze state of `name`. `FROZEN` MUST return `TRUE` for any frozen or permanently frozen binding and `FALSE` otherwise. `PERMAFROZEN` MUST return `TRUE` only for permanently frozen bindings and `FALSE` otherwise. If `name` is undefined, both operators MUST return `FALSE`.
715715

716716
---
717717

src/builtins.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8568,11 +8568,12 @@ static Value builtin_thaw(Interpreter *interp, Value *args, int argc, Expr **arg
85688568

85698569
static Value builtin_permafreeze(Interpreter *interp, Value *args, int argc, Expr **arg_nodes, Env *env, int line,
85708570
int col) {
8571-
(void)args;
8572-
if (argc != 1 || arg_nodes[0]->type != EXPR_IDENT) {
8573-
RUNTIME_ERROR(interp, "PERMAFREEZE expects an identifier", line, col);
8571+
(void)arg_nodes;
8572+
if (argc != 1) {
8573+
RUNTIME_ERROR(interp, "PERMAFREEZE expects 1 argument", line, col);
85748574
}
8575-
const char *name = arg_nodes[0]->as.ident;
8575+
EXPECT_STR(args[0], "PERMAFREEZE", interp, line, col);
8576+
const char *name = args[0].as.s ? args[0].as.s : "";
85768577
int r = env_permafreeze(env, name);
85778578
if (r != 0) {
85788579
char buf[128];
@@ -8663,11 +8664,12 @@ static Value builtin_frozen(Interpreter *interp, Value *args, int argc, Expr **a
86638664

86648665
static Value builtin_permafrozen(Interpreter *interp, Value *args, int argc, Expr **arg_nodes, Env *env, int line,
86658666
int col) {
8666-
(void)args;
8667-
if (argc != 1 || arg_nodes[0]->type != EXPR_IDENT) {
8668-
RUNTIME_ERROR(interp, "PERMAFROZEN expects an identifier", line, col);
8667+
(void)arg_nodes;
8668+
if (argc != 1) {
8669+
RUNTIME_ERROR(interp, "PERMAFROZEN expects 1 argument", line, col);
86698670
}
8670-
const char *name = arg_nodes[0]->as.ident;
8671+
EXPECT_STR(args[0], "PERMAFROZEN", interp, line, col);
8672+
const char *name = args[0].as.s ? args[0].as.s : "";
86718673
int p = env_permafrozen(env, name);
86728674
return value_bool(p != 0);
86738675
}

tests/cases/passing/del-frozen.pre

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ REFUTE(DEL("frozen_symbol"))
1515
REFUTE(EXIST("frozen_symbol"))
1616

1717
BOOL permafrozen_symbol = TRUE
18-
REFUTE(PERMAFREEZE(permafrozen_symbol))
18+
REFUTE(PERMAFREEZE("permafrozen_symbol"))
1919

2020
BOOL permafrozen_delete_failed = FALSE
2121
TRY{

tests/cases/passing/freeze.pre

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ BOOL frozen_value = TRUE
22

33
REFUTE(FREEZE("frozen_value"))
44
ASSERT(FROZEN("frozen_value"))
5-
REFUTE(PERMAFROZEN(frozen_value))
5+
REFUTE(PERMAFROZEN("frozen_value"))
66

77
BOOL freeze_undefined_failed = FALSE
88
TRY{

tests/cases/passing/frozen.pre

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ ASSERT(FROZEN("normal_value"))
66
REFUTE(THAW("normal_value"))
77
REFUTE(FROZEN("normal_value"))
88

9-
REFUTE(PERMAFREEZE(normal_value))
9+
REFUTE(PERMAFREEZE("normal_value"))
1010
ASSERT(FROZEN("normal_value"))
11-
ASSERT(PERMAFROZEN(normal_value))
11+
ASSERT(PERMAFROZEN("normal_value"))

tests/cases/passing/permafreeze.pre

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
BOOL locked_value = TRUE
22

3-
REFUTE(PERMAFREEZE(locked_value))
3+
REFUTE(PERMAFREEZE("locked_value"))
44
ASSERT(FROZEN("locked_value"))
5-
ASSERT(PERMAFROZEN(locked_value))
5+
ASSERT(PERMAFROZEN("locked_value"))
66

77
BOOL permafreeze_undefined_failed = FALSE
88
TRY{
9-
PERMAFREEZE(not_declared)
9+
PERMAFREEZE("not_declared")
1010
} CATCH {
1111
permafreeze_undefined_failed = TRUE
1212
}
@@ -37,4 +37,4 @@ TRY{
3737
thaw_failed = TRUE
3838
}
3939
ASSERT(thaw_failed)
40-
ASSERT(PERMAFROZEN(locked_value))
40+
ASSERT(PERMAFROZEN("locked_value"))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BOOL normal_value = TRUE
2-
REFUTE(PERMAFROZEN(normal_value))
2+
REFUTE(PERMAFROZEN("normal_value"))
33

4-
REFUTE(PERMAFREEZE(normal_value))
5-
ASSERT(PERMAFROZEN(normal_value))
4+
REFUTE(PERMAFREEZE("normal_value"))
5+
ASSERT(PERMAFROZEN("normal_value"))
66
ASSERT(FROZEN("normal_value"))

0 commit comments

Comments
 (0)