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
substr.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
35
36
case
OP_SUBSTR
: {
37
Value
lenv = pop_value(vm);
38
Value
startv
= pop_value(vm);
39
Value
str
= pop_value(vm);
40
if
(
str
.type !=
VAL_STRING
||
startv
.type !=
VAL_INT
|| lenv.
type
!=
VAL_INT
) {
41
fprintf
(stderr,
"Runtime type error: SUBSTR expects (string, int, int)\n"
);
42
exit
(1);
43
}
44
Value
out
=
bi_substr
(&
str
, (
int
)
startv
.i, (
int
)lenv.
i
);
45
free_value
(
str
);
46
free_value
(
startv
);
47
free_value
(lenv);
48
push_value
(vm,
out
);
49
break
;
50
}
out
Value out
Definition
apop.c:38
OP_SUBSTR
@ OP_SUBSTR
Definition
bytecode.h:103
str
Value str
Definition
regex_match.c:41
bi_substr
Value bi_substr(const Value *str, int start, int len)
Extract a substring from a string Value.
Definition
string.c:77
Value
Tagged union representing a Fun value.
Definition
value.h:68
Value::i
int64_t i
Definition
value.h:71
Value::type
ValueType type
Definition
value.h:69
startv
Value startv
Definition
substr.c:38
free_value
free_value(str)
push_value
push_value(vm, out)
VAL_STRING
@ VAL_STRING
Definition
value.h:53
VAL_INT
@ VAL_INT
Definition
value.h:51
fprintf
#define fprintf
Definition
vm.c:200
exit
#define exit(code)
Definition
vm.c:230
Generated on
for Fun by
1.16.1