Skip to content

Commit 38325ce

Browse files
committed
Several minor adaptations and text updates.`
1 parent 4d67a2b commit 38325ce

9 files changed

+94
-49
lines changed

Changelog

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
25 July 2024
2+
UFP export function accepts more formats: "%f" or F, %a or H, N, Q and %e or R.
3+
14
25 January 2024
25
toML function: Removed the space before the slash in empty tags (void elements).
36
nestML function: If a </html> tag is present, make sure there also is a <html> tag

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,12 @@ matching. In short, it is all that regular Bracmat isn't.
259259
* bracmatJS.html _(deleted, executable uploaded to latest release)_
260260

261261
Bracmat compiled to WebAssembly and Javascript using emscripten, embedded
262-
in a single HTML-page. Nice for toy scripts, slow.
263-
262+
in a single HTML-page. Nice for toy scripts.
263+
You can choose between pure JavaScript and JavaScript+WebAssembly.
264+
The latter produces smaller and faster, compiled code, but you probably
265+
will not be able to run bracmatJS.html straight from the filesystem in your
266+
browser. Instead run it in a (local) webserver. See emscriptenHowToHTML.sh
267+
for more details.
264268

265269
* edit-potuC.html.bra
266270

@@ -272,8 +276,9 @@ matching. In short, it is all that regular Bracmat isn't.
272276

273277
Linux batch file that runs emscripten and does some postprocessing,
274278
creating a Javascript version of Bracmat, bracmatJS.html.
275-
Requirement: emscripten 1.38.0
279+
Requirement: emscripten 1.39.0
276280
emcc and bracmat must be in PATH to run this script.
281+
Add the -sWASM=0 option to produce pure JavaScript code.
277282

278283
* pre.js
279284

WebAssembly/edit-potuC.html.bra

+5-4
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@ outline: ridge;
142142
<a href=\"http://rosettacode.org/wiki/Category:Bracmat\">rosettacode.org</a>.
143143
<br />
144144
For this demo version the C source code in which Bracmat is
145-
written, is translated to JavaScript, so the demo runs within
146-
the confines of your browser, with all the limitations that follow,
147-
such as the inability to read and write files.
145+
written, is translated to WebAssembly (or JavaScript, if the emcc
146+
option <strong>-sWASM=0</strong> was present), so the demo runs within the confines
147+
of your browser, with all the limitations that follow, such as the
148+
inability to read and write files.
148149
<br />
149-
Full, ten times faster versions of Bracmat compiled and
150+
Full, more than ten times faster versions of Bracmat compiled and
150151
linked for Windows, macOS and Linux, together with the C source
151152
code, can be found on
152153
<a href=\"https://github.com/BartJongejan/Bracmat\">GitHub</a>.<br>

WebAssembly/emscriptenHowToHTML.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.9
2-
emcc ../src/*.c --pre-js pre.js -s EXPORTED_RUNTIME_METHODS='["cwrap", "allocateUTF8", "intArrayFromString"]' -s "EXPORTED_FUNCTIONS=['_main','_oneShot','_malloc']" -s "MODULARIZE=0" -s "WASM=0" -O0 -o potuC.html
2+
# Without WebAssembly:
3+
#emcc ../src/*.c --pre-js pre.js -s EXPORTED_RUNTIME_METHODS='["cwrap", "allocateUTF8", "intArrayFromString"]' -s "EXPORTED_FUNCTIONS=['_main','_oneShot','_malloc']" -s "MODULARIZE=0" -O0 -o potuC.html -s "WASM=0"
4+
# With WebAssembly
5+
# Note that you probably need to run from a web server. You can do `python -m http.server' and then load http://localhost:8000/bracmatJS.html in your browser.
6+
# See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing
7+
emcc ../src/*.c --pre-js pre.js -s EXPORTED_RUNTIME_METHODS='["cwrap", "allocateUTF8", "intArrayFromString"]' -s "EXPORTED_FUNCTIONS=['_main','_oneShot','_malloc']" -s "MODULARIZE=0" -O0 -o potuC.html
38
bracmat "get'\"edit-potuC.html.bra\""

doc/help

+38-15
Original file line numberDiff line numberDiff line change
@@ -2244,34 +2244,57 @@ native Bracmat expressions. The |_export_| method can export one variable at a
22442244
time. Only variables in the main source code can be exported, variables in user
22452245
defined functions cannot be exported. The variables that are declared as the
22462246
parameters of the UFP object can also be exported.
2247-
{?} ( new$(UFP,(=(s.a) (s.b).!a+!b:?b&2*!b:?c)):?calc
2248-
& (calc..go)$(10,11):?Y
2249-
& out$(Y !Y)
2250-
& (calc..export)$(N,b):?b
2251-
& out$(b !b)
2252-
& (calc..export)$(N,c):?c
2253-
& out$(c !c)
2254-
)
2255-
2256-
Y 4.2000000000000000E+01
2257-
b 21
2258-
c 42
2247+
{?} ( new
2248+
$ ( UFP
2249+
, (
2250+
= (s.a) (s.b)
2251+
. divide$(!a,!b):?c
2252+
& acos$-1:?pi
2253+
)
2254+
)
2255+
: ?calc
2256+
& out$(output (calc..go)$(22,7))
2257+
& out$(\"b \" (calc..export)$(N,b))
2258+
& out$(\"%f\" (calc..export)$(F,c))
2259+
& out$(\"%a\" (calc..export)$(H,c))
2260+
& out$(\"N \" (calc..export)$(N,c))
2261+
& out$(\"Q \" (calc..export)$(Q,c))
2262+
& out$(\"%e\" (calc..export)$(R,c))
2263+
& out$(pi (calc..export)$(R,pi))
2264+
& out$(pi (calc..export)$(\"%a\",pi))
2265+
& out$(pi (calc..export)$(Q,pi))
2266+
)
2267+
2268+
output 3.1415926535897931E+00
2269+
b 7
2270+
%f 3.142857
2271+
%a 0x1.9249249249249p+1
2272+
N 3
2273+
Q 884635641090633/281474976710656
2274+
%e 3.142857e+00
2275+
pi 3.141593e+00
2276+
pi 0x1.921fb54442d18p+1
2277+
pi 884279719003555/281474976710656
22592278

22602279
The first argument to the |_export_| method tells wich notation is expected in the output:
22612280

2281+
F or \"%f\"
2282+
A signed value that has the form <[-]dddd.dddddd> is expected. The number of
2283+
digits before the decimal point depends on the magnitude of the number.
2284+
There are six digits after the decimal point.
2285+
H or \"%a\"
2286+
A hexadecimal notation. This notation preserves all bits of a |_double_|.
22622287
N
22632288
An integer is expected. Only digits are allowed, the first digit not being
22642289
a |_0_|. The digits can be preceded by a |_-_| to indicate that the number
22652290
is negative.
2266-
R
2291+
R or \"%e\"
22672292
A floating point expression is expected: a signed value that has the form
22682293
<[-]d.dddddde[+|-]dd[d]>, where <d> is one decimal digit, <dddddd> is six
22692294
decimal digits, and <dd[d]> is two or three decimal digits.
22702295
Q
22712296
A rational number is expected. Similar to |_N_|, but a single slash |_/_|
22722297
is allowed between to digits, the digit following the |_/_| not being a |_0_|.
2273-
\"%a\"
2274-
A hexadecimal notation. This notation preserves all bits of a |_double_|.
22752298
"
22762299
)
22772300
& ( prostutxt1

src/calculation.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -2199,21 +2199,21 @@ static Boolean print(struct typedObjectnode* This, ppsk arg)
21992199
return printmem(mem);
22002200
}
22012201

2202-
enum formt { floating /* %e */, hexadecimal /* %a */, fixed /* %f */, integer, fraction };
2202+
enum formt { scientific /* %e */, hexadecimal /* %a */, floatingPoint /* %f */, integer, fraction };
22032203

22042204
static enum formt getFormat(char* psobj)
22052205
{
2206-
if(!strcmp(psobj, "R"))
2207-
return floating;
2208-
else if(!strcmp(psobj, "%a"))
2206+
if(!strcmp(psobj, "%e") || !strcmp(psobj, "R"))
2207+
return scientific;
2208+
else if(!strcmp(psobj, "%a") || !strcmp(psobj, "H"))
22092209
return hexadecimal;
2210-
else if(!strcmp(psobj, "F"))
2211-
return fixed;
2210+
else if(!strcmp(psobj, "%f") || !strcmp(psobj, "F"))
2211+
return floatingPoint;
22122212
else if(!strcmp(psobj, "N"))
22132213
return integer;
22142214
else if(!strcmp(psobj, "Q"))
22152215
return fraction;
2216-
return floating;
2216+
return scientific;
22172217
}
22182218

22192219
static psk createOperatorNode(int operator)
@@ -2433,22 +2433,22 @@ static Boolean eksport(struct typedObjectnode* This, ppsk arg)
24332433
{
24342434
psk lhs = Arg->LEFT;
24352435
psk rhs = Arg->RIGHT;
2436-
enum formt format = floating;
2436+
enum formt format = scientific;
24372437
if(!is_op(lhs))
24382438
{
24392439
format = getFormat(&lhs->u.sobj);
24402440
}
24412441
switch(format)
24422442
{
2443-
case floating:
2443+
case scientific:
24442444
xprtfnc = FloatNode;
24452445
spec = "%e";
24462446
break;
24472447
case hexadecimal:
24482448
xprtfnc = FloatNode;
24492449
spec = "%a";
24502450
break;
2451-
case fixed:
2451+
case floatingPoint:
24522452
xprtfnc = FloatNode;
24532453
spec = "%f";
24542454
break;

src/json.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,7 @@ static jstate value(int arg)
545545
case '"':
546546
popj(); action = push(string); startString(); return json;
547547
case '[':
548-
popj
549-
(); action = push(valueOrCloseSquareBracket); startArray(); return json;
548+
popj(); action = push(valueOrCloseSquareBracket); startArray(); return json;
550549
case '{':
551550
popj(); action = push(startNamestringOrCloseBrace); startObject(); firstValue(); return json;
552551
case 't':

src/potu.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
email: bartj@hum.ku.dk
2121
*/
2222

23-
#define DATUM "7 Januari 2024"
24-
#define VERSION "6.21.0"
25-
#define BUILD "299"
23+
#define DATUM "25 July 2024"
24+
#define VERSION "6.22.0"
25+
#define BUILD "300"
2626
/*
2727
COMPILATION
2828
-----------

valid.bra

+20-11
Original file line numberDiff line numberDiff line change
@@ -6188,8 +6188,13 @@ string line 2\"
61886188
& "prepare for reading all bytes"
61896189
& (fil$(,STR)|Out$847)
61906190
& "read all bytes"
6191+
& (fil$(,TEL):255|Out$847b)
61916192
& (fil$(,SET,0)|Out$848)
6192-
& ( fil$:(@(?:? [255).)
6193+
& (fil$(,TEL):0|Out$848b)
6194+
& ( fil$
6195+
: (@(?:? [255).)
6196+
: ?TEXT
6197+
& out$(str$(TEXT[ !TEXT "]"))
61936198
| Out$849
61946199
)
61956200
& "prepare for reading all as DEC"
@@ -6227,7 +6232,7 @@ string line 2\"
62276232
)
62286233
& @( toML$(nestML$!xml)
62296234
: ?a
6230-
"<tr><td bgcolor=\"&cellback;\" rowspan=\"2\" colspan=\"1\" />"
6235+
"<tr><td bgcolor=\"&cellback;\" rowspan=\"2\" colspan=\"1\"/>"
62316236
?b
62326237
)
62336238
& (!y:!b|Out$848bA)
@@ -6792,7 +6797,7 @@ string line 2\"
67926797
, HT ML
67936798
)
67946799
)
6795-
: "<html><head><meta content=\"text/html; charset=UTF-8\" /></head><body>≩︀</body></html>"
6800+
: "<html><head><meta content=\"text/html; charset=UTF-8\"/></head><body>≩︀</body></html>"
67966801
| Out$931
67976802
)
67986803
( toML
@@ -6892,7 +6897,7 @@ string line 2\"
68926897
)
68936898
)
68946899
)
6895-
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\" /></:text>"
6900+
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\"/></:text>"
68966901
| Out$944
68976902
)
68986903
( toML
@@ -6904,7 +6909,7 @@ string line 2\"
69046909
)
69056910
)
69066911
)
6907-
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\" /></:text>"
6912+
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\"/></:text>"
69086913
| Out$945
69096914
)
69106915
( toML
@@ -6916,7 +6921,7 @@ string line 2\"
69166921
)
69176922
)
69186923
)
6919-
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\" /></:text>"
6924+
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\"/></:text>"
69206925
| Out$946
69216926
)
69226927
( map
@@ -7326,21 +7331,25 @@ string line 2\"
73267331
: ("0x1.0000000000000p+8"|"0x1p+8")
73277332
& (myCalc..go)$"0.015625"
73287333
: "1.5625000000000000E-02"
7329-
& (myCalc..export)$("%a",myParm)
7334+
& (myCalc..export)$(H,myParm)
73307335
: ("0x1.0000000000000p-6"|0x1p-6)
73317336
& (myCalc..go)$0xCAP-007
73327337
: "1.5781250000000000E+00"
73337338
& (myCalc..export)$("%a",myParm)
73347339
: ("0x1.9400000000000p+0"|"0x1.94p+0")
73357340
& (myCalc..go)$"0.857421875"
73367341
: "8.5742187500000000E-01"
7337-
& (myCalc..export)$("%a",myParm)
7342+
& (myCalc..export)$(H,myParm)
73387343
: ("0x1.b700000000000p-1"|"0x1.b7p-1")
73397344
& (myCalc..export)$(Q,myParm)
73407345
: 439/512
73417346
& (myCalc..go)$9007199254740991
73427347
& (myCalc..export)$(R,myParm)
73437348
: "9.007199e+15"
7349+
& (myCalc..export)$("%e",myParm)
7350+
: "9.007199e+15"
7351+
& (myCalc..export)$("%f",myParm)
7352+
: "9007199254740991.000000"
73447353
& (myCalc..export)$(N,myParm)
73457354
: 9007199254740991
73467355
& (myCalc..go)$0x1p-1074
@@ -7352,15 +7361,15 @@ string line 2\"
73527361
& (myCalc..export)$("%a",myParm)
73537362
: "0x1.921fb4d12d84ap+1"
73547363
& (myCalc..go)$5:"5.0000000000000000E+00"
7355-
& (myCalc..export)$("%a",myParm)
7364+
& (myCalc..export)$(H,myParm)
73567365
: ("0x1.4000000000000p+2"|"0x1.4p+2")
73577366
& (myCalc..go)$"0x1.999999999999ap-4"
73587367
: "1.0000000000000001E-01"
73597368
& (myCalc..export)$("%a",myParm)
73607369
: "0x1.999999999999ap-4"
73617370
& (myCalc..go)$"0x3.3333333333334p-5"
73627371
: "1.0000000000000001E-01"
7363-
& (myCalc..export)$("%a",myParm)
7372+
& (myCalc..export)$(H,myParm)
73647373
: "0x1.999999999999ap-4"
73657374
& (myCalc..go)$"0xcc.ccccccccccdp-11"
73667375
: "1.0000000000000001E-01"
@@ -7370,7 +7379,7 @@ string line 2\"
73707379
: "1.0000000000000001E-01"
73717380
& flt$(x2d$1999999999999a*2^-56,80)
73727381
: "1.00000000000000005551115123125782702118158340454101562500000000000000000000000000E-1"
7373-
& (myCalc..export)$("%a",myParm)
7382+
& (myCalc..export)$(H,myParm)
73747383
: "0x1.999999999999ap-4"
73757384
| Out$"Something amiss with very simple UFP object."
73767385
)

0 commit comments

Comments
 (0)