Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
release.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
10/**
11 * @file release.c
12 * @brief Implements the OP_PCSC_RELEASE opcode (conditional build).
13 *
14 * Releases a previously established PC/SC context and frees its registry slot.
15 * When PCSC support is disabled at build time, this opcode returns 0 after
16 * consuming its argument.
17 *
18 * OP_PCSC_RELEASE: (ctx_id:int) -> int
19 *
20 * - Pops: ctx_id.
21 * - Pushes: 1 on success; 0 on error (invalid id/not found) or when disabled.
22 */
23
24/* PCSC release */
26#ifdef FUN_WITH_PCSC
27 Value vid = pop_value(vm);
28 int id = (int)vid.i;
31 if (!e) {
32 push_value(vm, make_int(0));
33 break;
34 }
36 e->in_use = 0;
37 e->ctx = 0;
39#else
40 Value vid = pop_value(vm);
41 free_value(vid);
42 push_value(vm, make_int(0));
43#endif
44 break;
45}
@ OP_PCSC_RELEASE
Definition bytecode.h:185
pcsc_ctx_entry * e
Definition connect.c:38
static pcsc_ctx_entry * pcsc_get_ctx(int id)
Lookup a context slot by id.
Definition pcsc.c:88
SCardReleaseContext(e->ctx)
free_value(vid)
push_value(vm, make_int(1))
Tagged union representing a Fun value.
Definition value.h:68
int64_t i
Definition value.h:71
Definition pcsc.c:35
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition vm.c:580