Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
env.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
21
22case OP_ENV: {
23 Value key = pop_value(vm);
24 if (key.type != VAL_STRING) {
25 fprintf(stderr, "Runtime type error: ENV expects string name\n");
26 free_value(key);
27 exit(1);
28 }
29 const char *name = key.s ? key.s : "";
30 const char *val = getenv(name);
31 /* Return empty string if not set (consistent with read_file fallback style) */
34 break;
35}
@ OP_ENV
Definition bytecode.h:140
free_value(key)
push_value(vm, make_string(val ? val :""))
const char * name
Definition env.c:29
Value val
Definition load_local.c:36
Tagged union representing a Fun value.
Definition value.h:68
ValueType type
Definition value.h:69
char * s
Definition value.h:73
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
Definition value.c:95
@ VAL_STRING
Definition value.h:53
#define fprintf
Definition vm.c:200
#define exit(code)
Definition vm.c:230