Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
parse.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
34/* OP_XML_PARSE: pops text string; pushes doc handle (>0) or 0 */
36#ifdef FUN_WITH_XML2
37 static int xml_inited = 0;
38 if (!xml_inited) {
39 xmlInitParser();
40 xml_inited = 1;
41 }
42 Value vtext = pop_value(vm);
43 char *text = value_to_string_alloc(&vtext);
44 free_value(vtext);
45 if (!text) {
46 push_value(vm, make_int(0));
47 break;
48 }
49 xmlDocPtr doc = xmlReadMemory(text, (int)strlen(text), NULL, NULL, XML_PARSE_NONET);
50 free(text);
51 int h = 0;
52 if (doc) {
53 h = xml_doc_alloc(doc);
54 if (!h) {
55 xmlFreeDoc(doc);
56 }
57 }
58 push_value(vm, make_int(h));
59#else
60 Value drop = pop_value(vm);
61 free_value(drop);
63#endif
64 break;
65}
@ OP_XML_PARSE
Definition bytecode.h:214
push_value(vm, make_nil())
free_value(drop)
free(vals)
Tagged union representing a Fun value.
Definition value.h:68
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