Skip to content

Commit 995ff61

Browse files
committed
Correction
In JSON, there is a big difference between false and null. We have introduced a new atom: false to solve this issue. false is different from null but is treated in the same way.
1 parent 6d6d584 commit 995ff61

10 files changed

Lines changed: 32 additions & 23 deletions

File tree

binaries/wasm/lispe.wasm

-181 Bytes
Binary file not shown.

docs/lispe.wasm

-181 Bytes
Binary file not shown.

include/delegation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class Delegation {
199199
Atome* _TERMINAL;
200200
Atome* _INTO_STACK;
201201
Atome* _TRUE;
202+
Atome* _FALSE;
202203
Atome* _NULL;
203204
Atome* _CUT;
204205
Atome* _EMPTYATOM;

include/elements.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void decrement_total();
5353

5454
typedef enum {
5555
//Default values
56-
v_null, v_emptylist, v_emptyatom, v_true, v_mainspace, v_cut, v_into,
56+
v_null, v_emptylist, v_emptyatom, v_false, v_true, v_mainspace, v_cut, v_into,
5757

5858
//Default types
5959
t_emptystring, t_operator, t_atom,
@@ -196,8 +196,7 @@ inline const unsigned long _arity(long sz) {
196196
return (sz > 15)?P_FULL:1<<sz;
197197
}
198198
//------------------------------------------------------------------------------------------
199-
//false_ is actually a bit misleading as it is an alias to null_
200-
#define false_ lisp->n_null
199+
#define false_ lisp->delegation->_FALSE
201200
#define true_ lisp->n_true
202201
#define null_ lisp->n_null
203202

@@ -1334,10 +1333,6 @@ class Atome : public Element {
13341333
return name;
13351334
}
13361335

1337-
bool isNULL() {
1338-
return (atome == v_null);
1339-
}
1340-
13411336
int16_t function_label(LispE* lisp) {
13421337
return atome;
13431338
}
@@ -1356,9 +1351,11 @@ class Atome : public Element {
13561351
wstring jsonString(LispE* lisp) {
13571352
switch (atome) {
13581353
case v_null:
1359-
return L"false";
1354+
return L"null";
13601355
case v_emptylist:
13611356
return L"[]";
1357+
case v_false:
1358+
return L"false";
13621359
case v_true:
13631360
return L"true";
13641361
default:
@@ -1403,8 +1400,12 @@ class Atome : public Element {
14031400
Element* equal(LispE* lisp, Element* e);
14041401
bool egal(Element* e);
14051402

1403+
bool isNULL() {
1404+
return (atome == v_null || atome == v_false);
1405+
}
1406+
14061407
bool Boolean() {
1407-
return atome;
1408+
return (atome != v_null && atome != v_false);
14081409
}
14091410

14101411
double asNumber() {

include/tools.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ class UTF8_Handler {
427427

428428
void split_container(wchar_t* src, long lensrc, vector<long>&);
429429
void split_container(u_uchar* src, long lensrc, vector<long>&);
430+
class Atome;
430431

431432
class LispEJsonCompiler {
432433
public:
@@ -444,6 +445,9 @@ class LispEJsonCompiler {
444445
long to;
445446
long l;
446447
u_uchar c;
448+
Element* _false;
449+
Element* _true;
450+
Element* _null;
447451

448452
Element* compile_to_json(string& s);
449453
Element* compile_to_json(u_ustring& s);

src/composing.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class Counter : public Element {
522522
}
523523

524524
Element* compose(LispE* lisp, Element* var, Element* e) {
525-
if (e == NULL || counter->more(lisp,e) == false_)
525+
if (e == NULL || counter->more(lisp,e)->isNULL())
526526
return this;
527527
return e;
528528
}

src/lispe.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void decrement_total() {
3131
total_objects--;
3232
}
3333

34-
static std::string version = "1.2026.7.12.20.8";
34+
static std::string version = "1.2026.7.17.15.31";
3535
string LispVersion() {
3636
return version;
3737
}
@@ -880,6 +880,7 @@ void Delegation::initialisation(LispE* lisp) {
880880

881881
code_to_string[v_null] = U"nil";
882882
code_to_string[v_true] = U"true";
883+
code_to_string[v_false] = U"false";
883884
code_to_string[v_cut] = U"cut_";
884885
code_to_string[v_into] = U"into";
885886

@@ -928,6 +929,7 @@ void Delegation::initialisation(LispE* lisp) {
928929
_TERMINAL = (Atome*)lisp->provideAtomOrInstruction(l_terminal);
929930
_INTO_STACK = (Atome*)lisp->provideAtomOrInstruction(v_into);
930931
_TRUE = (Atome*)lisp->provideAtomOrInstruction(v_true);
932+
_FALSE = (Atome*)lisp->provideAtomOrInstruction(v_false);
931933
_CUT = (Atome*)lisp->provideAtomOrInstruction(v_cut);
932934
_EMPTYATOM = (Atome*)lisp->provideAtomOrInstruction(v_emptyatom);
933935
_DEFPAT = (Atome*)lisp->provideAtomOrInstruction(l_defpat);
@@ -976,7 +978,7 @@ void Delegation::initialisation(LispE* lisp) {
976978
_NUMERICAL_BOOLEANS[0] = _ZERO;
977979
_NUMERICAL_BOOLEANS[1] = _ONE;
978980

979-
_BOOLEANS[0][0] = _NULL;
981+
_BOOLEANS[0][0] = _FALSE;
980982
_BOOLEANS[0][1] = _TRUE;
981983
_BOOLEANS[1][0] = _ZERO;
982984
_BOOLEANS[1][1] = _ONE;
@@ -989,6 +991,7 @@ void Delegation::initialisation(LispE* lisp) {
989991

990992
//We create our constant values
991993
lisp->recordingunique(_TRUE, v_true);
994+
lisp->recordingunique(_FALSE, v_false);
992995
lisp->recordingunique(_NULL, v_null);
993996
lisp->recordingunique(_CUT, v_cut);
994997
lisp->recordingunique(_ERROR, t_error);
@@ -1161,10 +1164,6 @@ void Delegation::initialisation(LispE* lisp) {
11611164
w = U("¨");
11621165
string_to_code[w] = l_maplist;
11631166

1164-
//But also 'false', which is a substitute to nil as well
1165-
w = U"false";
1166-
string_to_code[w] = v_null;
1167-
11681167
//But also 'fail_', which is a substitute to nil as well (see cut_)
11691168
w = U"fail_";
11701169
string_to_code[w] = v_null;
@@ -3848,3 +3847,4 @@ Element* List::evall_memory(LispE* lisp) {
38483847

38493848

38503849

3850+

src/systems.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ class Command : public Element {
11411141
if ((scible.st_mode & S_IFMT) == S_IFDIR)
11421142
recording(mp, U"directory", true_);
11431143
else
1144-
recording(mp, U"directory", false_);
1144+
recording(mp, U"directory", null_);
11451145
return mp;
11461146
}
11471147

src/tools.cxx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5662,6 +5662,9 @@ void replacemetas(u_ustring& sub) {
56625662
}
56635663

56645664
bool LispEJsonCompiler::compile(LispE* lisp, u_ustring& s, bool raw) {
5665+
_false = false_;
5666+
_true = true_;
5667+
_null = null_;
56655668
if (!raw)
56665669
return compile_to_json(s);
56675670

@@ -5741,13 +5744,13 @@ char LispEJsonCompiler::buildexpression(LispE* lisp, Element* container) {
57415744
src[to] = 0;
57425745
token = (u_uchar*)src+i-1;
57435746
if (token == U"false")
5744-
container->append(false_);
5747+
container->append(_false);
57455748
else {
57465749
if (token == U"true")
5747-
container->append(true_);
5750+
container->append(_true);
57485751
else {
57495752
if (token == U"null" || token == U"nil")
5750-
container->append(null_);
5753+
container->append(_null);
57515754
else
57525755
container->append(lisp, token);
57535756
}
@@ -5909,13 +5912,13 @@ char LispEJsonCompiler::build_to_json(Element* container) {
59095912
src[to] = 0;
59105913
token = (u_uchar*)src+i-1;
59115914
if (token == U"false")
5912-
container->append(new Integer(0));
5915+
container->append(_false);
59135916
else {
59145917
if (token == U"true")
5915-
container->append(new Integer(0));
5918+
container->append(_true);
59165919
else {
59175920
if (token == U"null" || token == U"nil")
5918-
container->append(new Atome(v_null, U"nil"));
5921+
container->append(_null);
59195922
else
59205923
container->append(new String(token));
59215924
}

wasm/lispe.wasm

-181 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)