Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
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
36case 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);
47 free_value(lenv);
49 break;
50}
Value out
Definition apop.c:38
@ OP_SUBSTR
Definition bytecode.h:103
Value str
Definition regex_match.c:41
Value bi_substr(const Value *str, int start, int len)
Extract a substring from a string Value.
Definition string.c:77
Tagged union representing a Fun value.
Definition value.h:68
int64_t i
Definition value.h:71
ValueType type
Definition value.h:69
Value startv
Definition substr.c:38
free_value(str)
push_value(vm, out)
@ VAL_STRING
Definition value.h:53
@ VAL_INT
Definition value.h:51
#define fprintf
Definition vm.c:200
#define exit(code)
Definition vm.c:230