Skip to content

Commit

Permalink
Made BASIC booleans print as true and false
Browse files Browse the repository at this point in the history
  • Loading branch information
totalspectrum committed Oct 14, 2023
1 parent 324388c commit d21714d
Show file tree
Hide file tree
Showing 9 changed files with 697 additions and 678 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version 6.6.0
- Implemented proper boolean type for C
- Fixed -- operator for floats
- Made the BASIC boolean type a distinct type
- Made BASIC booleans print as "true" and "false"

Version 6.5.4
- Minor optimization improvement (and major documentation improvements) courtesy of Ada
Expand Down
6 changes: 3 additions & 3 deletions Test/Expect/basexec01.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ x, scaled 100000 10000. 10000. 1.0000E-04
1.0000E-08
asc: 1, 0
string tests:
abc abc < = >: 0 -1 0
abc a < = >: 0 0 -1
def zzz < = >: -1 0 0
abc abc < = >: false true false
abc a < = >: false false true
def zzz < = >: true false false
str,n: hello,7
left: hello right: hello
str,n: goodbye,3
Expand Down
44 changes: 22 additions & 22 deletions Test/Expect/basexec03.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
hello, world!
HELLO, WORLD!

GOODBYE!
closed handle
+0:+000: 0: 000: 0:000
-99:-099: -99:-099:-99:-99
+99:+099: 99: 099: 99:099
x xx xxxxxxx xxxxxx xxxxxxx
[a] [ab] [abc ] [ abc] [ abc ]
-2 -3
0.3000
0.4000
0.5000
0.6000
0.7000
0.8000
0.9000
1.0000
0 : a, b = 0 -1
1 : a, b = -1 0
2 : a, b = -1 -1
hello, world!
HELLO, WORLD!
GOODBYE!
closed handle
+0:+000: 0: 000: 0:000
-99:-099: -99:-099:-99:-99
+99:+099: 99: 099: 99:099
x xx xxxxxxx xxxxxx xxxxxxx
[a] [ab] [abc ] [ abc] [ abc ]
-2 -3
0.3000
0.4000
0.5000
0.6000
0.7000
0.8000
0.9000
1.0000
0 : a, b = false true
1 : a, b = true false
2 : a, b = true true
2 changes: 2 additions & 0 deletions frontends/basic/basiclang.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@ ParsePrintStatement(AST *ast)
} else if (IsGenericType(type) || IsPointerType(type)) {
// create a hex call
seq = addPrintHex(seq, handle, basic_print_unsigned, expr, fmtAst);
} else if (IsBoolType(type)) {
seq = addPrintCall(seq, handle, basic_print_boolean, expr, fmtAst);
} else if (IsUnsignedType(type)) {
if (IsInt64Type(type)) {
seq = addPrintDec(seq, handle, basic_print_longunsigned, expr, fmtAst);
Expand Down
1 change: 1 addition & 0 deletions frontends/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ extern AST *basic_print_unsigned_3;
extern AST *basic_print_unsigned_4;
extern AST *basic_print_char;
extern AST *basic_print_nl;
extern AST *basic_print_boolean;
extern AST *basic_put;
extern AST *basic_print_longinteger;
extern AST *basic_print_longunsigned;
Expand Down
2 changes: 2 additions & 0 deletions frontends/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ AST *basic_print_unsigned_3;
AST *basic_print_unsigned_4;
AST *basic_print_longinteger;
AST *basic_print_longunsigned;
AST *basic_print_boolean;
AST *basic_print_char;
AST *basic_print_nl;
AST *basic_put;
Expand Down Expand Up @@ -2281,6 +2282,7 @@ InitGlobalFuncs(void)
basic_print_string = getBasicPrimitive("_basic_print_string");
basic_print_char = getBasicPrimitive("_basic_print_char");
basic_print_nl = getBasicPrimitive("_basic_print_nl");
basic_print_boolean = getBasicPrimitive("_basic_print_boolean");
basic_put = getBasicPrimitive("_basic_put");
basic_lock_io = getBasicPrimitive("__lockio");
basic_unlock_io = getBasicPrimitive("__unlockio");
Expand Down
6 changes: 6 additions & 0 deletions include/libsys/basicfmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ int _basic_print_string(unsigned h, const char *ptr, unsigned fmt)
return _fmtstr(tf, fmt, ptr);
}

int _basic_print_boolean(unsigned h, int x, unsigned fmt)
{
const char *ptr = x ? "true" : "false";
return _basic_print_string(h, ptr, fmt);
}

int _basic_print_unsigned(unsigned h, int x, unsigned fmt, int base)
{
TxFunc tf = _gettxfunc(h);
Expand Down
1 change: 1 addition & 0 deletions sys/common.spin
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ pri {++complexio} file "libsys/basicfmt.c" _basic_close(h)
pri {++complexio} file "libc/unix/posixio.c" _freefile() : r=long
pri file "libsys/basicfmt.c" _basic_print_nl(h)
pri file "libsys/basicfmt.c" _basic_print_char(h, c, fmt = 0)
pri file "libsys/basicfmt.c" _basic_print_boolean(h, c, fmt = 0)
pri file "libsys/basicfmt.c" _basic_print_string(h, ptr, fmt = 0)
pri file "libsys/basicfmt.c" _basic_print_integer(h, x, fmt = 0, base=10)
pri file "libsys/basicfmt.c" _basic_print_integer_2(h, x1, x2, fmt = 0, base=10)
Expand Down
1,312 changes: 659 additions & 653 deletions sys/common.spin.h

Large diffs are not rendered by default.

0 comments on commit d21714d

Please sign in to comment.