Fun
0.41.5
The programming language that makes You have fun
Main Page
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
src
vm
strings
find.c
Go to the documentation of this file.
1
/*
2
* This file is part of the Fun programming language.
3
* https://fun-lang.xyz/
4
*
5
* Copyright 2025 Johannes Findeisen <you@hanez.org>
6
* Licensed under the terms of the Apache-2.0 license.
7
* https://opensource.org/license/apache-2-0
8
*/
9
34
35
case
OP_FIND
: {
36
Value
needle = pop_value(vm);
37
Value
hay
= pop_value(vm);
38
if
(
hay
.type !=
VAL_STRING
|| needle.
type
!=
VAL_STRING
) {
39
fprintf
(stderr,
"Runtime type error: FIND expects (string, string)\n"
);
40
exit
(1);
41
}
42
int
idx
=
bi_find
(&
hay
, &needle);
43
free_value
(
hay
);
44
free_value
(needle);
45
push_value
(vm,
make_int
(
idx
));
46
break
;
47
}
OP_FIND
@ OP_FIND
Definition
bytecode.h:104
push_value
push_value(vm, make_int(idx))
free_value
free_value(hay)
hay
Value hay
Definition
find.c:37
idx
int idx
Definition
index_of.c:38
bi_find
int bi_find(const Value *hay, const Value *needle)
Find the first occurrence of a needle inside a haystack string.
Definition
string.c:96
Value
Tagged union representing a Fun value.
Definition
value.h:68
Value::type
ValueType type
Definition
value.h:69
make_int
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition
value.c:51
VAL_STRING
@ VAL_STRING
Definition
value.h:53
fprintf
#define fprintf
Definition
vm.c:200
exit
#define exit(code)
Definition
vm.c:230
Generated on
for Fun by
1.16.1