Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
open.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 open.c
12 * @brief Implements the OP_SQLITE_OPEN opcode (conditional build).
13 *
14 * Opens a SQLite database and registers a handle when FUN_WITH_SQLITE is
15 * enabled. On failure or when SQLite support is disabled, pushes 0.
16 *
17 * OP_SQLITE_OPEN: (path:string) -> handle:int (>0) or 0 on error
18 */
19
21#ifdef FUN_WITH_SQLITE
22 Value vpath = pop_value(vm);
25 if (!path) {
26 push_value(vm, make_int(0));
27 break;
28 }
29 sqlite3 *db = NULL;
30 int rc = sqlite3_open(path, &db);
32 if (rc != SQLITE_OK || !db) {
33 if (db) sqlite3_close(db);
34 push_value(vm, make_int(0));
35 break;
36 }
38 if (!h) {
39 sqlite3_close(db);
40 push_value(vm, make_int(0));
41 break;
42 }
44#else
45 Value v = pop_value(vm);
47 push_value(vm, make_int(0));
48#endif
49 break;
50}
@ OP_SQLITE_OPEN
Definition bytecode.h:178
Value v
Definition cast.c:22
CURLcode rc
Definition download.c:71
CURL * h
Definition download.c:59
char * path
Definition download.c:43
double db
Definition fmax.c:27
free_value(vpath)
free(path)
push_value(vm, make_int(h->id))
static SqlHandle * sql_reg_add(sqlite3 *db)
Add a sqlite3 handle to the registry.
Definition sqlite.c:54
Node in a singly-linked list of registered SQLite handles.
Definition sqlite.c:29
Tagged union representing a Fun value.
Definition value.h:68
void vpath
Definition stubs.c:23
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
Definition value.c:641
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