Skip to content

Commit

Permalink
Several minor adaptations and text updates.`
Browse files Browse the repository at this point in the history
  • Loading branch information
BartJongejan committed Jul 25, 2024
1 parent 4d67a2b commit 38325ce
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 49 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
25 July 2024
UFP export function accepts more formats: "%f" or F, %a or H, N, Q and %e or R.

25 January 2024
toML function: Removed the space before the slash in empty tags (void elements).
nestML function: If a </html> tag is present, make sure there also is a <html> tag
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,12 @@ matching. In short, it is all that regular Bracmat isn't.
* bracmatJS.html _(deleted, executable uploaded to latest release)_

Bracmat compiled to WebAssembly and Javascript using emscripten, embedded
in a single HTML-page. Nice for toy scripts, slow.

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

* edit-potuC.html.bra

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

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

* pre.js

Expand Down
9 changes: 5 additions & 4 deletions WebAssembly/edit-potuC.html.bra
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ outline: ridge;
<a href=\"http://rosettacode.org/wiki/Category:Bracmat\">rosettacode.org</a>.
<br />
For this demo version the C source code in which Bracmat is
written, is translated to JavaScript, so the demo runs within
the confines of your browser, with all the limitations that follow,
such as the inability to read and write files.
written, is translated to WebAssembly (or JavaScript, if the emcc
option <strong>-sWASM=0</strong> was present), so the demo runs within the confines
of your browser, with all the limitations that follow, such as the
inability to read and write files.
<br />
Full, ten times faster versions of Bracmat compiled and
Full, more than ten times faster versions of Bracmat compiled and
linked for Windows, macOS and Linux, together with the C source
code, can be found on
<a href=\"https://github.com/BartJongejan/Bracmat\">GitHub</a>.<br>
Expand Down
7 changes: 6 additions & 1 deletion WebAssembly/emscriptenHowToHTML.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.9
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
# Without WebAssembly:
#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"
# With WebAssembly
# 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.
# 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
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
bracmat "get'\"edit-potuC.html.bra\""
53 changes: 38 additions & 15 deletions doc/help
Original file line number Diff line number Diff line change
Expand Up @@ -2244,34 +2244,57 @@ native Bracmat expressions. The |_export_| method can export one variable at a
time. Only variables in the main source code can be exported, variables in user
defined functions cannot be exported. The variables that are declared as the
parameters of the UFP object can also be exported.
{?} ( new$(UFP,(=(s.a) (s.b).!a+!b:?b&2*!b:?c)):?calc
& (calc..go)$(10,11):?Y
& out$(Y !Y)
& (calc..export)$(N,b):?b
& out$(b !b)
& (calc..export)$(N,c):?c
& out$(c !c)
)

Y 4.2000000000000000E+01
b 21
c 42
{?} ( new
$ ( UFP
, (
= (s.a) (s.b)
. divide$(!a,!b):?c
& acos$-1:?pi
)
)
: ?calc
& out$(output (calc..go)$(22,7))
& out$(\"b \" (calc..export)$(N,b))
& out$(\"%f\" (calc..export)$(F,c))
& out$(\"%a\" (calc..export)$(H,c))
& out$(\"N \" (calc..export)$(N,c))
& out$(\"Q \" (calc..export)$(Q,c))
& out$(\"%e\" (calc..export)$(R,c))
& out$(pi (calc..export)$(R,pi))
& out$(pi (calc..export)$(\"%a\",pi))
& out$(pi (calc..export)$(Q,pi))
)

output 3.1415926535897931E+00
b 7
%f 3.142857
%a 0x1.9249249249249p+1
N 3
Q 884635641090633/281474976710656
%e 3.142857e+00
pi 3.141593e+00
pi 0x1.921fb54442d18p+1
pi 884279719003555/281474976710656

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

F or \"%f\"
A signed value that has the form <[-]dddd.dddddd> is expected. The number of
digits before the decimal point depends on the magnitude of the number.
There are six digits after the decimal point.
H or \"%a\"
A hexadecimal notation. This notation preserves all bits of a |_double_|.
N
An integer is expected. Only digits are allowed, the first digit not being
a |_0_|. The digits can be preceded by a |_-_| to indicate that the number
is negative.
R
R or \"%e\"
A floating point expression is expected: a signed value that has the form
<[-]d.dddddde[+|-]dd[d]>, where <d> is one decimal digit, <dddddd> is six
decimal digits, and <dd[d]> is two or three decimal digits.
Q
A rational number is expected. Similar to |_N_|, but a single slash |_/_|
is allowed between to digits, the digit following the |_/_| not being a |_0_|.
\"%a\"
A hexadecimal notation. This notation preserves all bits of a |_double_|.
"
)
& ( prostutxt1
Expand Down
20 changes: 10 additions & 10 deletions src/calculation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2199,21 +2199,21 @@ static Boolean print(struct typedObjectnode* This, ppsk arg)
return printmem(mem);
}

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

static enum formt getFormat(char* psobj)
{
if(!strcmp(psobj, "R"))
return floating;
else if(!strcmp(psobj, "%a"))
if(!strcmp(psobj, "%e") || !strcmp(psobj, "R"))
return scientific;
else if(!strcmp(psobj, "%a") || !strcmp(psobj, "H"))
return hexadecimal;
else if(!strcmp(psobj, "F"))
return fixed;
else if(!strcmp(psobj, "%f") || !strcmp(psobj, "F"))
return floatingPoint;
else if(!strcmp(psobj, "N"))
return integer;
else if(!strcmp(psobj, "Q"))
return fraction;
return floating;
return scientific;
}

static psk createOperatorNode(int operator)
Expand Down Expand Up @@ -2433,22 +2433,22 @@ static Boolean eksport(struct typedObjectnode* This, ppsk arg)
{
psk lhs = Arg->LEFT;
psk rhs = Arg->RIGHT;
enum formt format = floating;
enum formt format = scientific;
if(!is_op(lhs))
{
format = getFormat(&lhs->u.sobj);
}
switch(format)
{
case floating:
case scientific:
xprtfnc = FloatNode;
spec = "%e";
break;
case hexadecimal:
xprtfnc = FloatNode;
spec = "%a";
break;
case fixed:
case floatingPoint:
xprtfnc = FloatNode;
spec = "%f";
break;
Expand Down
3 changes: 1 addition & 2 deletions src/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ static jstate value(int arg)
case '"':
popj(); action = push(string); startString(); return json;
case '[':
popj
(); action = push(valueOrCloseSquareBracket); startArray(); return json;
popj(); action = push(valueOrCloseSquareBracket); startArray(); return json;
case '{':
popj(); action = push(startNamestringOrCloseBrace); startObject(); firstValue(); return json;
case 't':
Expand Down
6 changes: 3 additions & 3 deletions src/potu.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
email: [email protected]
*/

#define DATUM "7 Januari 2024"
#define VERSION "6.21.0"
#define BUILD "299"
#define DATUM "25 July 2024"
#define VERSION "6.22.0"
#define BUILD "300"
/*
COMPILATION
-----------
Expand Down
31 changes: 20 additions & 11 deletions valid.bra
Original file line number Diff line number Diff line change
Expand Up @@ -6188,8 +6188,13 @@ string line 2\"
& "prepare for reading all bytes"
& (fil$(,STR)|Out$847)
& "read all bytes"
& (fil$(,TEL):255|Out$847b)
& (fil$(,SET,0)|Out$848)
& ( fil$:(@(?:? [255).)
& (fil$(,TEL):0|Out$848b)
& ( fil$
: (@(?:? [255).)
: ?TEXT
& out$(str$(TEXT[ !TEXT "]"))
| Out$849
)
& "prepare for reading all as DEC"
Expand Down Expand Up @@ -6227,7 +6232,7 @@ string line 2\"
)
& @( toML$(nestML$!xml)
: ?a
"<tr><td bgcolor=\"&cellback;\" rowspan=\"2\" colspan=\"1\" />"
"<tr><td bgcolor=\"&cellback;\" rowspan=\"2\" colspan=\"1\"/>"
?b
)
& (!y:!b|Out$848bA)
Expand Down Expand Up @@ -6792,7 +6797,7 @@ string line 2\"
, HT ML
)
)
: "<html><head><meta content=\"text/html; charset=UTF-8\" /></head><body>≩︀</body></html>"
: "<html><head><meta content=\"text/html; charset=UTF-8\"/></head><body>≩︀</body></html>"
| Out$931
)
( toML
Expand Down Expand Up @@ -6892,7 +6897,7 @@ string line 2\"
)
)
)
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\" /></:text>"
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\"/></:text>"
| Out$944
)
( toML
Expand All @@ -6904,7 +6909,7 @@ string line 2\"
)
)
)
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\" /></:text>"
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\"/></:text>"
| Out$945
)
( toML
Expand All @@ -6916,7 +6921,7 @@ string line 2\"
)
)
)
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\" /></:text>"
: "<:text lix=\"45.61\" :ovix=\"70.39\" _nk=\"1.09\" i:d=\"aa01a\"><_sentence i-d=\"e248e955-e24865ce\" _geo.context=\"|\"/></:text>"
| Out$946
)
( map
Expand Down Expand Up @@ -7326,21 +7331,25 @@ string line 2\"
: ("0x1.0000000000000p+8"|"0x1p+8")
& (myCalc..go)$"0.015625"
: "1.5625000000000000E-02"
& (myCalc..export)$("%a",myParm)
& (myCalc..export)$(H,myParm)
: ("0x1.0000000000000p-6"|0x1p-6)
& (myCalc..go)$0xCAP-007
: "1.5781250000000000E+00"
& (myCalc..export)$("%a",myParm)
: ("0x1.9400000000000p+0"|"0x1.94p+0")
& (myCalc..go)$"0.857421875"
: "8.5742187500000000E-01"
& (myCalc..export)$("%a",myParm)
& (myCalc..export)$(H,myParm)
: ("0x1.b700000000000p-1"|"0x1.b7p-1")
& (myCalc..export)$(Q,myParm)
: 439/512
& (myCalc..go)$9007199254740991
& (myCalc..export)$(R,myParm)
: "9.007199e+15"
& (myCalc..export)$("%e",myParm)
: "9.007199e+15"
& (myCalc..export)$("%f",myParm)
: "9007199254740991.000000"
& (myCalc..export)$(N,myParm)
: 9007199254740991
& (myCalc..go)$0x1p-1074
Expand All @@ -7352,15 +7361,15 @@ string line 2\"
& (myCalc..export)$("%a",myParm)
: "0x1.921fb4d12d84ap+1"
& (myCalc..go)$5:"5.0000000000000000E+00"
& (myCalc..export)$("%a",myParm)
& (myCalc..export)$(H,myParm)
: ("0x1.4000000000000p+2"|"0x1.4p+2")
& (myCalc..go)$"0x1.999999999999ap-4"
: "1.0000000000000001E-01"
& (myCalc..export)$("%a",myParm)
: "0x1.999999999999ap-4"
& (myCalc..go)$"0x3.3333333333334p-5"
: "1.0000000000000001E-01"
& (myCalc..export)$("%a",myParm)
& (myCalc..export)$(H,myParm)
: "0x1.999999999999ap-4"
& (myCalc..go)$"0xcc.ccccccccccdp-11"
: "1.0000000000000001E-01"
Expand All @@ -7370,7 +7379,7 @@ string line 2\"
: "1.0000000000000001E-01"
& flt$(x2d$1999999999999a*2^-56,80)
: "1.00000000000000005551115123125782702118158340454101562500000000000000000000000000E-1"
& (myCalc..export)$("%a",myParm)
& (myCalc..export)$(H,myParm)
: "0x1.999999999999ap-4"
| Out$"Something amiss with very simple UFP object."
)
Expand Down

0 comments on commit 38325ce

Please sign in to comment.