Skip to content

Commit 113faf4

Browse files
gh-114: Add operator ISTHR.
1 parent 191f33d commit 113faf4

5 files changed

Lines changed: 30 additions & 1 deletion

File tree

docs/SPECIFICATION.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@
705705

706706
- `BOOL: EXIST(SYMBOL: name)` = MUST return `TRUE` if `name` resolves to a visible readable binding in the current lexical environment chain and `FALSE` otherwise.
707707

708-
- `BOOL: ISBOOL/ISINT/ISFLT/ISSTR/ISTNS/ISMAP/ISFUNC(ANY: value)` = MUST return `TRUE` if the runtime type of `value` is respectively `BOOL`, `INT`, `FLT`, `STR`, `TNS`, `MAP`, or `FUNC`, and `FALSE` otherwise.
708+
- `BOOL: ISBOOL/ISINT/ISFLT/ISSTR/ISTNS/ISMAP/ISFUNC/ISTHR(ANY: value)` = MUST return `TRUE` if the runtime type of `value` is respectively `BOOL`, `INT`, `FLT`, `STR`, `TNS`, `MAP`, `FUNC`, or `THR`, and `FALSE` otherwise.
709709

710710
- `STR: TYPE(ANY: value)` = MUST return the runtime type name of `value` as a `STR`. For core language values, the result MUST be one of `BOOL`, `INT`, `FLT`, `STR`, `TNS`, `MAP`, `FUNC`, or `THR`. For null or otherwise unrecognized internal values, the result MUST be `NULL`. Extension-defined values MUST report their registered type names.
711711

src/builtins.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6550,6 +6550,11 @@ static Value builtin_isfunc(Interpreter* interp, Value* args, int argc, Expr** a
65506550
return value_bool(args[0].type == VAL_FUNC);
65516551
}
65526552

6553+
static Value builtin_isthr(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
6554+
(void)arg_nodes; (void)env; (void)interp; (void)line; (void)col;
6555+
return value_bool(args[0].type == VAL_THR);
6556+
}
6557+
65536558
static Value builtin_type(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
65546559
(void)arg_nodes; (void)env; (void)interp; (void)line; (void)col;
65556560
return value_str(value_type_name(args[0]));
@@ -9079,6 +9084,7 @@ static BuiltinFunction builtins_table[] = {
90799084
{"ISTNS", 1, 1, builtin_istns},
90809085
{"ISMAP", 1, 1, builtin_ismap},
90819086
{"ISFUNC", 1, 1, builtin_isfunc},
9087+
{"ISTHR", 1, 1, builtin_isthr},
90829088
{"TYPE", 1, 1, builtin_type},
90839089
{"SIGNATURE", 1, 1, builtin_signature},
90849090

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ISTHR(TRUE, FALSE)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ISTHR()

tests/cases/passing/isthr.pre

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
BOOL: sample_bool_true = TRUE
2+
INT: sample_int = -0d7
3+
FLT: sample_flt = 0d3.5
4+
STR: sample_str = "prefix"
5+
TNS: sample_tns = [0d1, 0d2]
6+
MAP: sample_map = <"n" = 0d1>
7+
8+
FUNC INT: sample_func(INT: value){
9+
RETURN(value)
10+
}
11+
12+
THR(sample_thr){}
13+
14+
REFUTE(ISTHR(sample_bool_true))
15+
REFUTE(ISTHR(sample_int))
16+
REFUTE(ISTHR(sample_flt))
17+
REFUTE(ISTHR(sample_str))
18+
REFUTE(ISTHR(sample_tns))
19+
REFUTE(ISTHR(sample_map))
20+
REFUTE(ISTHR(sample_func))
21+
ASSERT(ISTHR(sample_thr))

0 commit comments

Comments
 (0)