Make terminal ui binaries work well everywhere

Here's some screenshots of an emulator tui program that was compiled on
Linux, then scp'd it to Windows, Mac, and FreeBSD.

https://justine.storage.googleapis.com/blinkenlights-cmdexe.png
https://justine.storage.googleapis.com/blinkenlights-imac.png
https://justine.storage.googleapis.com/blinkenlights-freebsd.png
https://justine.storage.googleapis.com/blinkenlights-lisp.png

How is this even possible that we have a nontrivial ui binary that just
works on Mac, Windows, Linux, and BSD? Surely a first ever achievement.

Fixed many bugs. Bootstrapped John McCarthy's metacircular evaluator on
bare metal in half the size of Altair BASIC (about 2.5kb) and ran it in
emulator for fun and profit.
This commit is contained in:
Justine Tunney
2020-10-10 21:18:53 -07:00
parent 680daf1210
commit 9e3e985ae5
276 changed files with 7026 additions and 3790 deletions

View File

@@ -31,6 +31,11 @@ TEST(strchr, text) {
char buf[] = "hellothere";
EXPECT_STREQ("there", strchr(buf, 't'));
}
TEST(strchr, testsse) {
char buf[] = "hellohellohellohellohellohellohellohello"
"theretheretheretheretheretheretherethere";
EXPECT_STREQ("theretheretheretheretheretheretherethere", strchr(buf, 't'));
}
TEST(rawmemchr, text) {
char buf[] = "hellothere";
EXPECT_STREQ("there", rawmemchr(buf, 't'));

View File

@@ -37,8 +37,16 @@ TEST(tpenc, test) {
EXPECT_EQ(0x8080808080FEul, tpenc(INT_MIN));
}
TEST(tpenc, theimp) {
ASSERT_EQ(0x88989FF0, tpenc(L'😈'));
}
TEST(tpenc, testBeyondTheStandard) {
ASSERT_EQ(0xBFBFBFBFBFFF, tpenc(-1));
}
uint64_t Tpenc(int x) {
return (v = tpenc(x));
return (v = tpenc(VEIL("r", x)));
}
BENCH(tpenc, bench) {
@@ -47,6 +55,7 @@ BENCH(tpenc, bench) {
EZBENCH(donothing, Tpenc(' '));
EZBENCH(donothing, Tpenc(0x7f));
EZBENCH(donothing, Tpenc(L''));
EZBENCH(donothing, Tpenc(-1));
EZBENCH(donothing, Tpenc(INT_MIN));
fprintf(stderr, "\n");
}

View File

@@ -61,3 +61,7 @@ TEST(tpencode, testMathematicalNotMuhPolicyDrivenBehavior_nonCanonicalNul) {
ASSERT_BINEQ(u"└Ç", PROGN(ASSERT_EQ(2, tpencode(buf, 8, 0, true)), buf));
ASSERT_BINEQ(u"└Ç", PROGN(ASSERT_EQ(2, (tpencode)(buf, 8, 0, true)), buf));
}
TEST(tpencode, testC1Csi) {
ASSERT_BINEQ(u"›", PROGN(ASSERT_EQ(2, tpencode(buf, 8, 0x9B, false)), buf));
}

View File

@@ -0,0 +1,27 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ This program is free software; you can redistribute it and/or modify │
│ it under the terms of the GNU General Public License as published by │
│ the Free Software Foundation; version 2 of the License. │
│ │
│ This program is distributed in the hope that it will be useful, but │
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
│ General Public License for more details. │
│ │
│ You should have received a copy of the GNU General Public License │
│ along with this program; if not, write to the Free Software │
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
│ 02110-1301 USA │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
TEST(tprecode16to8, test) {
char b[128];
EXPECT_EQ(69, tprecode16to8(b, 128, u"(╯°□°)╯︵L┻━┻ 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷𐌸𐌹"));
EXPECT_STREQ("(╯°□°)╯︵L┻━┻ 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷𐌸𐌹", b);
}

View File

@@ -28,3 +28,9 @@ TEST(tprecode8to16, test) {
EXPECT_STREQ(u"hello☻♥", buf);
tfree(buf);
}
TEST(tprecode8to16, test2) {
char16_t b[128];
EXPECT_EQ(34, tprecode8to16(b, 128, "(╯°□°)╯︵L┻━┻ 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷𐌸𐌹"));
EXPECT_STREQ(u"(╯°□°)╯︵L┻━┻ 𐌰𐌱𐌲𐌳𐌴𐌵𐌶𐌷𐌸𐌹", b);
}

View File

@@ -42,6 +42,7 @@
#include "libc/zip.h"
#include "third_party/zlib/zlib.h"
STATIC_YOINK("zip_uri_support");
STATIC_YOINK("libc/testlib/hyperion.txt");
TEST(undeflate, testEmbeddedPlaintextConstant) {
@@ -86,7 +87,7 @@ TEST(undeflate, testEmbeddedCompressedZipFile_theHardWay) {
struct DeflateState ds;
uint8_t *map, *cd, *cf, *lf, *data;
found = false;
ASSERT_NE(-1, (fd = open(findcombinary(), O_RDONLY)));
ASSERT_NE(-1, (fd = open(FindComBinary(), O_RDONLY)));
ASSERT_NE(-1, fstat(fd, &st));
ASSERT_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));