Skip to content

Commit f6aecf2

Browse files
gh-113: Add operator ISFUNC.
1 parent 9604fed commit f6aecf2

5 files changed

Lines changed: 32 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(ANY: value)` = MUST return `TRUE` if the runtime type of `value` is respectively `BOOL`, `INT`, `FLT`, `STR`, `TNS`, or `MAP`, and `FALSE` otherwise.
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.
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
@@ -6545,6 +6545,11 @@ static Value builtin_ismap(Interpreter* interp, Value* args, int argc, Expr** ar
65456545
return value_bool(args[0].type == VAL_MAP);
65466546
}
65476547

6548+
static Value builtin_isfunc(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
6549+
(void)arg_nodes; (void)env; (void)interp; (void)line; (void)col;
6550+
return value_bool(args[0].type == VAL_FUNC);
6551+
}
6552+
65486553
static Value builtin_type(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
65496554
(void)arg_nodes; (void)env; (void)interp; (void)line; (void)col;
65506555
return value_str(value_type_name(args[0]));
@@ -9073,6 +9078,7 @@ static BuiltinFunction builtins_table[] = {
90739078
{"ISSTR", 1, 1, builtin_isstr},
90749079
{"ISTNS", 1, 1, builtin_istns},
90759080
{"ISMAP", 1, 1, builtin_ismap},
9081+
{"ISFUNC", 1, 1, builtin_isfunc},
90769082
{"TYPE", 1, 1, builtin_type},
90779083
{"SIGNATURE", 1, 1, builtin_signature},
90789084

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

tests/cases/passing/isfunc.pre

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

0 commit comments

Comments
 (0)