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.1.0"
27#define BORON_VERSION 0x020100
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
63
64typedef struct
65{
66 UCellId id;
67 UIndex avail; // End cell is pos + avail.
68 const UCell* pos;
69}
71
72#define boron_evalPos(a1) ((UCellCFuncEval*) a1)->pos
73#define boron_evalAvail(a1) ((UCellCFuncEval*) a1)->avail
74
75
77{
81};
82
83
85{
86 UR_PORT_SIMPLE, // buf->ptr.v is UPortDevice*.
87 UR_PORT_EXT, // buf->ptr.v is UPortDevice**.
88};
89
90
91enum PortOpenOptions
92{
93 UR_PORT_READ = 0x01,
94 UR_PORT_WRITE = 0x02,
95 UR_PORT_NEW = 0x04,
96 UR_PORT_NOWAIT = 0x08
97};
98
99
100enum PortSeek
101{
102 UR_PORT_HEAD,
103 UR_PORT_TAIL,
104 UR_PORT_SKIP
105};
106
107
108#ifdef _WIN32
109#define UR_PORT_HANDLE 0x7fffffff
110#endif
111
112typedef struct UPortDevice UPortDevice;
113
115{
116 int (*open) ( UThread*, const UPortDevice*, const UCell* from, int opt,
117 UCell* res );
118 void (*close)( UBuffer* );
119 int (*read) ( UThread*, UBuffer*, UCell*, int len );
120 int (*write)( UThread*, UBuffer*, const UCell* );
121 int (*seek) ( UThread*, UBuffer*, UCell*, int where );
122#ifdef _WIN32
123 int (*waitFD)( UBuffer*, void** );
124#else
125 int (*waitFD)( UBuffer* );
126#endif
128};
129
130
131#ifdef __cplusplus
132extern "C" {
133#endif
134
137void boron_freeEnv( UThread* );
138UStatus boron_defineCFunc( UThread*, UIndex ctxN, const BoronCFunc* funcs,
139 const char* spec, int slen );
140void boron_overrideCFunc( UThread*, const char* name, BoronCFunc func );
141void boron_addPortDevice( UThread*, const UPortDevice*, UAtom name );
142UBuffer* boron_makePort( UThread*, const UPortDevice*, void* ext, UCell* res );
143void boron_setAccessFunc( UThread*, int (*func)( UThread*, const char* ) );
144UStatus boron_requestAccess( UThread*, const char* msg, ... );
145void boron_bindDefault( UThread*, UIndex blkN );
146UStatus boron_load( UThread*, const char* file, UCell* res );
147int boron_runFibre( UThread* );
148UStatus boron_evalBlock( UThread*, UIndex blkN, UCell* res );
149UCell* boron_evalUtf8( UThread*, const char* script, int len );
150UIndex boron_evalRecurse(UThread*, UCell* res);
151void boron_evalSetTop(UThread*, UIndex top);
152int boron_reframeDoBlock(UThread*, UIndex blkN, UCell* res, int flags);
153void boron_reset( UThread* );
154UStatus boron_throwWord( UThread*, UAtom atom, UIndex stackPos );
155int boron_catchWord( UThread*, UAtom atom );
156char* boron_cstr( UThread*, const UCell* strC, UBuffer* bin );
157char* boron_cpath( UThread*, const UCell* strC, UBuffer* bin );
158UBuffer* boron_tempBinary( const UThread* );
159UStatus boron_badArg( UThread*, UIndex atom, int argN );
160void boron_randomSeed( UThread*, uint32_t );
161uint32_t boron_random( UThread* );
162
163#ifdef __cplusplus
164}
165#endif
166
167
168#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:962
UCell * boron_evalUtf8(UThread *, const char *script, int len)
Run script and put result in the last stack cell.
Definition: eval.c:2033
void boron_addPortDevice(UThread *, const UPortDevice *, UAtom name)
Register port device.
Definition: boron_types.c:313
void boron_bindDefault(UThread *, UIndex blkN)
Bind block in thread dataStore to default contexts.
Definition: eval.c:1995
UStatus boron_badArg(UThread *, UIndex atom, int argN)
Throw a standardized error for an unexpected function argument.
Definition: eval.c:694
UIndex boron_evalRecurse(UThread *, UCell *res)
Begin a section where boron_evalBlock() can be recursively called.
Definition: eval.c:760
UserAccess
Definition: boron.h:77
void boron_evalSetTop(UThread *, UIndex top)
Reset evaluator operation stack position.
Definition: eval.c:780
PortForm
Definition: boron.h:85
@ UR_PORT_SIMPLE
Denotes that UBuffer::ptr is the UPortDevice pointer.
Definition: boron.h:86
@ UR_PORT_EXT
Denotes that UBuffer::ptr points to extension data and that the first member is the UPortDevice point...
Definition: boron.h:87
UBuffer * boron_makePort(UThread *, const UPortDevice *, void *ext, UCell *res)
Create port buffer.
Definition: boron_types.c:350
UStatus boron_throwWord(UThread *, UAtom atom, UIndex stackPos)
Throw named exception.
Definition: boron.c:300
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:320
UThread * boron_makeEnv(UEnvParameters *)
Make Boron environment and initial thread.
Definition: boron.c:721
UStatus boron_defineCFunc(UThread *, UIndex ctxN, const BoronCFunc *funcs, const char *spec, int slen)
Add C functions to context.
Definition: boron.c:388
void boron_randomSeed(UThread *, uint32_t)
Seed the thread RNG.
Definition: random.c:44
void boron_freeEnv(UThread *)
Destroy Boron environment.
Definition: boron.c:865
UStatus boron_load(UThread *, const char *file, UCell *res)
Load block! from file and give it default bindings.
Definition: boron.c:889
void boron_reset(UThread *)
Reset thread after exception.
Definition: boron.c:214
void boron_setAccessFunc(UThread *, int(*func)(UThread *, const char *))
Set the callback function that will request security access from the user.
Definition: boron.c:933
char * boron_cstr(UThread *, const UCell *strC, UBuffer *bin)
Make null terminated UTF-8 string in binary buffer.
Definition: boron.c:236
@ UR_ACCESS_ALWAYS
Grant access to the resource and allow all future requests.
Definition: boron.h:80
@ UR_ACCESS_DENY
Forbid access to the resource.
Definition: boron.h:78
@ UR_ACCESS_ALLOW
Grant access to the resource.
Definition: boron.h:79
UStatus boron_requestAccess(UThread *, const char *msg,...)
Request user permission to access a resource.
Definition: boron.c:948
UEnvParameters * boron_envParam(UEnvParameters *)
Initialize UEnvParameters structure to default Boron values.
Definition: boron.c:706
char * boron_cpath(UThread *, const UCell *strC, UBuffer *bin)
Make null terminated UTF-8 string in binary buffer.
Definition: boron.c:252
The UBuffer struct holds information about a resource, usually a chuck of memory.
Definition: urlan.h:266
Structure of CFUNC a1 argument when boron_defineCFunc() signature is ":eval".
Definition: boron.h:65
const UCell * pos
Block program counter.
Definition: boron.h:68
UIndex avail
Number of valid cells following pos.
Definition: boron.h:67
Basic type identification.
Definition: urlan.h:158
The UEnvParameters struct allows the user to override default buffer and structure sizes.
Definition: urlan.h:488
The UPortDevice struct holds methods for a class of input/ouput device.
Definition: boron.h:115
int defaultReadLen
Number of bytes to read if script does not specify a length.
Definition: boron.h:127
int(* open)(UThread *, const UPortDevice *, const UCell *from, int opt, UCell *res)
Create and open a new port.
Definition: boron.h:116
void(* close)(UBuffer *)
Close port.
Definition: boron.h:118
int(* write)(UThread *, UBuffer *, const UCell *)
Write data to port.
Definition: boron.h:120
int(* seek)(UThread *, UBuffer *, UCell *, int where)
Seek to position.
Definition: boron.h:121
int(* read)(UThread *, UBuffer *, UCell *, int len)
Read data from port.
Definition: boron.h:119
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:119
@ UR_BIND_USER
Start of user defined bindings.
Definition: urlan.h:96