Boron 2.1.0
boron.h
Go to the documentation of this file.
1#ifndef BORON_H
2#define BORON_H
3/*
4 Copyright 2009-2023 Karl Robillard
5
6 This file is part of the Boron programming language.
7
8 Boron is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 Boron is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with Boron. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22
23#include "urlan.h"
24
25
26#define BORON_VERSION_STR "2.96.0"
27#define BORON_VERSION 0x0209600
28
29
30enum BoronDataType
31{
32 UT_FUNC = UT_BI_COUNT,
33 UT_CFUNC,
34 UT_AFUNC,
35 UT_PORT,
36 UT_BORON_COUNT
37};
38
39
40enum BoronWordBindings
41{
42 BOR_BIND_FUNC = UR_BIND_USER,
43 BOR_BIND_OPTION,
44 BOR_BIND_OPTION_ARG
45};
46
47
48enum BoronFibreState
49{
50 BOR_FIBRE_DONE,
51 BOR_FIBRE_YIELD,
52 BOR_FIBRE_EXCEPTION
53};
54
55
56typedef UStatus (*BoronCFunc)(UThread*,UCell*,UCell*);
57#define CFUNC(name) static UStatus name( UThread* ut, UCell* a1, UCell* res )
58#define CFUNC_PUB(name) UStatus name( UThread* ut, UCell* a1, UCell* res )
59#define CFUNC_OPTIONS a1[-1].id.ext
60#define CFUNC_OPT_ARG(opt) (a1 + ((uint8_t*)a1)[-opt])
61#define CFUNC_REFRAMED 2
62#define CFUNC_YIELD 3
63
64
65typedef struct
66{
67 UCellId id;
68 UIndex avail; // End cell is pos + avail.
69 const UCell* pos;
70}
72
73#define boron_evalPos(a1) ((UCellCFuncEval*) a1)->pos
74#define boron_evalAvail(a1) ((UCellCFuncEval*) a1)->avail
75
76
83
84
86{
87 UR_PORT_SIMPLE, // buf->ptr.v is UPortDevice*.
88 UR_PORT_EXT, // buf->ptr.v is UPortDevice**.
89};
90
91
92enum PortOpenOptions
93{
94 UR_PORT_READ = 0x01,
95 UR_PORT_WRITE = 0x02,
96 UR_PORT_NEW = 0x04,
97 UR_PORT_NOWAIT = 0x08
98};
99
100
101enum PortSeek
102{
103 UR_PORT_HEAD,
104 UR_PORT_TAIL,
105 UR_PORT_SKIP
106};
107
108
109#ifdef _WIN32
110#define UR_PORT_HANDLE 0x7fffffff
111#endif
112
113typedef struct UPortDevice UPortDevice;
114
116{
117 int (*open) ( UThread*, const UPortDevice*, const UCell* from, int opt,
118 UCell* res );
119 void (*close)( UBuffer* );
120 int (*read) ( UThread*, UBuffer*, UCell*, int len );
121 int (*write)( UThread*, UBuffer*, const UCell* );
122 int (*seek) ( UThread*, UBuffer*, UCell*, int where );
123#ifdef _WIN32
124 int (*waitFD)( UBuffer*, void** );
125#else
126 int (*waitFD)( UBuffer* );
127#endif
129};
130
131
132#ifdef __cplusplus
133extern "C" {
134#endif
135
137void boron_setStackSize( UEnvParameters*, uint16_t argStack,
138 uint16_t evalStack );
140void boron_freeEnv( UThread* );
141UStatus boron_defineCFunc( UThread*, UIndex ctxN, const BoronCFunc* funcs,
142 const char* spec, int slen );
143void boron_overrideCFunc( UThread*, const char* name, BoronCFunc func );
144void boron_addPortDevice( UThread*, const UPortDevice*, UAtom name );
145UBuffer* boron_makePort( UThread*, const UPortDevice*, void* ext, UCell* res );
146void boron_setAccessFunc( UThread*, int (*func)( UThread*, const char* ) );
147UStatus boron_requestAccess( UThread*, const char* msg, ... );
148void boron_bindDefault( UThread*, UIndex blkN );
149UStatus boron_load( UThread*, const char* file, UCell* res );
150int boron_runFibre( UThread* );
151UStatus boron_evalBlock( UThread*, UIndex blkN, UCell* res );
152UCell* boron_evalUtf8( UThread*, const char* script, int len );
155int boron_reframeDoBlock(UThread*, UIndex blkN, UCell* res, int flags);
156void boron_reset( UThread* );
157UStatus boron_throwWord( UThread*, UAtom atom, UIndex stackPos );
158int boron_catchWord( UThread*, UAtom atom );
159char* boron_cstr( UThread*, const UCell* strC, UBuffer* bin );
160char* boron_cpath( UThread*, const UCell* strC, UBuffer* bin );
161UBuffer* boron_tempBinary( const UThread* );
162UStatus boron_badArg( UThread*, UIndex atom, int argN );
163void boron_randomSeed( UThread*, uint32_t );
164uint32_t boron_random( UThread* );
165int64_t boron_msec();
166
167#ifdef __cplusplus
168}
169#endif
170
171
172#endif /*EOF*/
int boron_reframeDoBlock(UThread *, UIndex blkN, UCell *res, int flags)
Reuse the current CFUNC call frame for a EOP_DO_BLOCK operation.
Definition eval.c:964
UCell * boron_evalUtf8(UThread *, const char *script, int len)
Run script and put result in the last stack cell.
Definition eval.c:2127
void boron_addPortDevice(UThread *, const UPortDevice *, UAtom name)
Register port device.
Definition boron_types.c:321
void boron_bindDefault(UThread *, UIndex blkN)
Bind block in thread dataStore to default contexts.
Definition eval.c:2042
UStatus boron_badArg(UThread *, UIndex atom, int argN)
Throw a standardized error for an unexpected function argument.
Definition eval.c:696
UIndex boron_evalRecurse(UThread *, UCell *res)
Begin a section where boron_evalBlock() can be recursively called.
Definition eval.c:762
UserAccess
Definition boron.h:78
void boron_evalSetTop(UThread *, UIndex top)
Reset evaluator operation stack position.
Definition eval.c:782
PortForm
Definition boron.h:86
@ UR_PORT_SIMPLE
Denotes that UBuffer::ptr is the UPortDevice pointer.
Definition boron.h:87
@ UR_PORT_EXT
Denotes that UBuffer::ptr points to extension data and that the first member is the UPortDevice point...
Definition boron.h:88
UBuffer * boron_makePort(UThread *, const UPortDevice *, void *ext, UCell *res)
Create port buffer.
Definition boron_types.c:358
UStatus boron_throwWord(UThread *, UAtom atom, UIndex stackPos)
Throw named exception.
Definition boron.c:308
uint32_t boron_random(UThread *)
Get the next number from the thread RNG.
Definition random.c:56
int boron_catchWord(UThread *, UAtom atom)
Check if named exception was thrown.
Definition boron.c:328
UThread * boron_makeEnv(UEnvParameters *)
Make Boron environment and initial thread.
Definition boron.c:748
UStatus boron_defineCFunc(UThread *, UIndex ctxN, const BoronCFunc *funcs, const char *spec, int slen)
Add C functions to context.
Definition boron.c:396
void boron_randomSeed(UThread *, uint32_t)
Seed the thread RNG.
Definition random.c:44
void boron_freeEnv(UThread *)
Destroy Boron environment.
Definition boron.c:894
UStatus boron_load(UThread *, const char *file, UCell *res)
Load block! from file and give it default bindings.
Definition boron.c:918
void boron_reset(UThread *)
Reset thread after exception.
Definition boron.c:222
void boron_setAccessFunc(UThread *, int(*func)(UThread *, const char *))
Set the callback function that will request security access from the user.
Definition boron.c:973
char * boron_cstr(UThread *, const UCell *strC, UBuffer *bin)
Make null terminated UTF-8 string in binary buffer.
Definition boron.c:244
@ UR_ACCESS_ALWAYS
Grant access to the resource and allow all future requests.
Definition boron.h:81
@ UR_ACCESS_DENY
Forbid access to the resource.
Definition boron.h:79
@ UR_ACCESS_ALLOW
Grant access to the resource.
Definition boron.h:80
UStatus boron_requestAccess(UThread *, const char *msg,...)
Request user permission to access a resource.
Definition boron.c:988
UEnvParameters * boron_envParam(UEnvParameters *)
Initialize UEnvParameters structure to default Boron values.
Definition boron.c:714
char * boron_cpath(UThread *, const UCell *strC, UBuffer *bin)
Make null terminated UTF-8 string in binary buffer.
Definition boron.c:260
The UBuffer struct holds information about a resource, usually a chunk of memory.
Definition urlan.h:266
Structure of CFUNC a1 argument when boron_defineCFunc() signature is ":eval".
Definition boron.h:66
const UCell * pos
Block program counter.
Definition boron.h:69
UIndex avail
Number of valid cells following pos.
Definition boron.h:68
Basic type identification.
Definition urlan.h:155
The UEnvParameters struct allows the user to override default buffer and structure sizes.
Definition urlan.h:497
The UPortDevice struct holds methods for a class of input/ouput device.
Definition boron.h:116
int(* seek)(UThread *, UBuffer *, UCell *, int where)
Seek to position.
Definition boron.h:122
int defaultReadLen
Number of bytes to read if script does not specify a length.
Definition boron.h:128
void(* close)(UBuffer *)
Close port.
Definition boron.h:119
int(* read)(UThread *, UBuffer *, UCell *, int len)
Read data from port.
Definition boron.h:120
int(* open)(UThread *, const UPortDevice *, const UCell *from, int opt, UCell *res)
Create and open a new port.
Definition boron.h:117
int(* write)(UThread *, UBuffer *, const UCell *)
Write data to port.
Definition boron.h:121
The UThread struct stores the data specific to a thread of execution.
Definition urlan.h:309
A cell holds a single value of a simple type or a reference (often to a UBuffer) for a complex type.
Definition urlan.h:248
The Urlan programmer interface.
UStatus
Definition urlan.h:116
@ UR_BIND_USER
Start of user defined bindings.
Definition urlan.h:93
int32_t UIndex
This is an index into an array.
Definition urlan.h:150