Skip to content

Commit d21714d

Browse files
committed
Made BASIC booleans print as true and false
1 parent 324388c commit d21714d

File tree

9 files changed

+697
-678
lines changed

9 files changed

+697
-678
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Version 6.6.0
33
- Implemented proper boolean type for C
44
- Fixed -- operator for floats
55
- Made the BASIC boolean type a distinct type
6+
- Made BASIC booleans print as "true" and "false"
67

78
Version 6.5.4
89
- Minor optimization improvement (and major documentation improvements) courtesy of Ada

Test/Expect/basexec01.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ x, scaled 100000 10000. 10000. 1.0000E-04
2020
1.0000E-08
2121
asc: 1, 0
2222
string tests:
23-
abc abc < = >: 0 -1 0
24-
abc a < = >: 0 0 -1
25-
def zzz < = >: -1 0 0
23+
abc abc < = >: false true false
24+
abc a < = >: false false true
25+
def zzz < = >: true false false
2626
str,n: hello,7
2727
left: hello right: hello
2828
str,n: goodbye,3

Test/Expect/basexec03.txt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
hello, world!
2-
HELLO, WORLD!
3-
4-
GOODBYE!
5-
closed handle
6-
+0:+000: 0: 000: 0:000
7-
-99:-099: -99:-099:-99:-99
8-
+99:+099: 99: 099: 99:099
9-
x xx xxxxxxx xxxxxx xxxxxxx
10-
[a] [ab] [abc ] [ abc] [ abc ]
11-
-2 -3
12-
0.3000
13-
0.4000
14-
0.5000
15-
0.6000
16-
0.7000
17-
0.8000
18-
0.9000
19-
1.0000
20-
0 : a, b = 0 -1
21-
1 : a, b = -1 0
22-
2 : a, b = -1 -1
1+
hello, world!
2+
HELLO, WORLD!
3+
4+
GOODBYE!
5+
closed handle
6+
+0:+000: 0: 000: 0:000
7+
-99:-099: -99:-099:-99:-99
8+
+99:+099: 99: 099: 99:099
9+
x xx xxxxxxx xxxxxx xxxxxxx
10+
[a] [ab] [abc ] [ abc] [ abc ]
11+
-2 -3
12+
0.3000
13+
0.4000
14+
0.5000
15+
0.6000
16+
0.7000
17+
0.8000
18+
0.9000
19+
1.0000
20+
0 : a, b = false true
21+
1 : a, b = true false
22+
2 : a, b = true true

frontends/basic/basiclang.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ ParsePrintStatement(AST *ast)
838838
} else if (IsGenericType(type) || IsPointerType(type)) {
839839
// create a hex call
840840
seq = addPrintHex(seq, handle, basic_print_unsigned, expr, fmtAst);
841+
} else if (IsBoolType(type)) {
842+
seq = addPrintCall(seq, handle, basic_print_boolean, expr, fmtAst);
841843
} else if (IsUnsignedType(type)) {
842844
if (IsInt64Type(type)) {
843845
seq = addPrintDec(seq, handle, basic_print_longunsigned, expr, fmtAst);

frontends/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,7 @@ extern AST *basic_print_unsigned_3;
10821082
extern AST *basic_print_unsigned_4;
10831083
extern AST *basic_print_char;
10841084
extern AST *basic_print_nl;
1085+
extern AST *basic_print_boolean;
10851086
extern AST *basic_put;
10861087
extern AST *basic_print_longinteger;
10871088
extern AST *basic_print_longunsigned;

frontends/types.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ AST *basic_print_unsigned_3;
5050
AST *basic_print_unsigned_4;
5151
AST *basic_print_longinteger;
5252
AST *basic_print_longunsigned;
53+
AST *basic_print_boolean;
5354
AST *basic_print_char;
5455
AST *basic_print_nl;
5556
AST *basic_put;
@@ -2281,6 +2282,7 @@ InitGlobalFuncs(void)
22812282
basic_print_string = getBasicPrimitive("_basic_print_string");
22822283
basic_print_char = getBasicPrimitive("_basic_print_char");
22832284
basic_print_nl = getBasicPrimitive("_basic_print_nl");
2285+
basic_print_boolean = getBasicPrimitive("_basic_print_boolean");
22842286
basic_put = getBasicPrimitive("_basic_put");
22852287
basic_lock_io = getBasicPrimitive("__lockio");
22862288
basic_unlock_io = getBasicPrimitive("__unlockio");

include/libsys/basicfmt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ int _basic_print_string(unsigned h, const char *ptr, unsigned fmt)
150150
return _fmtstr(tf, fmt, ptr);
151151
}
152152

153+
int _basic_print_boolean(unsigned h, int x, unsigned fmt)
154+
{
155+
const char *ptr = x ? "true" : "false";
156+
return _basic_print_string(h, ptr, fmt);
157+
}
158+
153159
int _basic_print_unsigned(unsigned h, int x, unsigned fmt, int base)
154160
{
155161
TxFunc tf = _gettxfunc(h);

sys/common.spin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ pri {++complexio} file "libsys/basicfmt.c" _basic_close(h)
330330
pri {++complexio} file "libc/unix/posixio.c" _freefile() : r=long
331331
pri file "libsys/basicfmt.c" _basic_print_nl(h)
332332
pri file "libsys/basicfmt.c" _basic_print_char(h, c, fmt = 0)
333+
pri file "libsys/basicfmt.c" _basic_print_boolean(h, c, fmt = 0)
333334
pri file "libsys/basicfmt.c" _basic_print_string(h, ptr, fmt = 0)
334335
pri file "libsys/basicfmt.c" _basic_print_integer(h, x, fmt = 0, base=10)
335336
pri file "libsys/basicfmt.c" _basic_print_integer_2(h, x1, x2, fmt = 0, base=10)

sys/common.spin.h

Lines changed: 659 additions & 653 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)