Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
disconnect.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 disconnect.c
12 * @brief Implements the OP_PCSC_DISCONNECT opcode (conditional build).
13 *
14 * Disconnects a previously connected smart-card handle and frees the
15 * corresponding registry slot. When PCSC support is disabled at build time,
16 * this opcode returns 0 after consuming its argument.
17 *
18 * OP_PCSC_DISCONNECT: (handle_id:int) -> int
19 *
20 * - Pops: handle_id.
21 * - Pushes: 1 on success; 0 on error (invalid id/not found) or when disabled.
22 * - Notes: Uses SCardDisconnect(..., SCARD_LEAVE_CARD).
23 */
24
25/**
26
27 */
28
29/* PCSC disconnect */
31#ifdef FUN_WITH_PCSC
32 Value vh = pop_value(vm);
33 int hid = (int)vh.i;
36 if (!ce) {
37 push_value(vm, make_int(0));
38 break;
39 }
40 SCardDisconnect(ce->h, SCARD_LEAVE_CARD);
41 ce->in_use = 0;
42 ce->h = 0;
43 ce->proto = 0;
45#else
46 Value vh = pop_value(vm);
48 push_value(vm, make_int(0));
49#endif
50 break;
51}
@ OP_PCSC_DISCONNECT
Definition bytecode.h:188
pcsc_card_entry * ce
Definition connect.c:51
free_value(vh)
SCardDisconnect(ce->h, SCARD_LEAVE_CARD)
int hid
Definition disconnect.c:33
push_value(vm, make_int(1))
Value vh
Definition get_bool.c:38
static pcsc_card_entry * pcsc_get_card(int id)
Lookup a card slot by id.
Definition pcsc.c:102
Tagged union representing a Fun value.
Definition value.h:68
Definition pcsc.c:40
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