Publish VCC Plus OSS source distribution for 3.6.2 build 60

This commit is contained in:
Brian Holman committed 2026-11-13 00:14:03 -07:00
commit c652a5276d
1192 files changed
+272368

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: GPL-3.0-or-later
"""Run the compatibility smoke test, including nested tokenization, on both guest CPUs."""
import argparse
import os
from pathlib import Path
import subprocess
import tempfile
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("runtime", type=Path)
parser.add_argument("core", type=Path)
parser.add_argument("rom", type=Path)
args = parser.parse_args()
runtime, core, rom = [p.resolve(strict=True) for p in (args.runtime, args.core, args.rom)]
tests = Path(__file__).resolve().parent
runner = tests.parents[3] / "tests/toolchain/run-compiled.cpp"
env = dict(os.environ, VCC_CMOC_COMPAT="1")
with tempfile.TemporaryDirectory(prefix="vcc-compat-") as tmp:
def run(*args):
subprocess.run(args, cwd=tmp, env=env, check=True)
run("xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0",
runner, core, "-o", "run")
for opt in ("-O0", "-O2"):
cc = [runtime / "bin/cmoc", "--coco", opt, "-Werror"]
caller = [*cc, "--org=2800", "-o", "TEST.BIN", tests / "compat-check.c"]
print(f"{opt} caller with staged library", flush=True)
run(*caller, "-lvcccompat")
run("./run", rom, "TEST.BIN", "COMPAT PASS")
if opt == "-O0":
# The staged archive always contains the optimized implementation.
print("Checking the unoptimized compatibility routines as well", flush=True)
units = ["tokenize", "ctype", "format"]
for unit in units:
run(*cc, "-c", "-o", unit + ".o", tests.parent / (unit + ".c"))
run(*caller, *(unit + ".o" for unit in units))
run("./run", rom, "TEST.BIN", "COMPAT PASS")
if __name__ == "__main__":
main()
+119
View File
@@ -0,0 +1,119 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Build with the compatibility include directory and -lvcccompat. Run on either
// emulated CPU; a failed check reports its source line on the CoCo screen.
#ifdef COCO_HEADER_FIRST
#include <coco.h>
#endif
#include <stdint.h>
#include <limits.h>
#include <stddef.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <coco.h>
#define CHECK(test) do { if (!(test)) return __LINE__; } while (0)
struct Pair { uint8_t tag; uint16_t number; };
static int checkTokens(void)
{
char row[] = "||MARS|RED,,COLD|4||";
char plain[] = "A B";
char separators[] = " | ,";
char untouched[] = "ONE TWO";
char empty[] = "";
char *field, *trait;
// A fresh scan ignores the cursor's prior value. A token points into
// the original writable line. Splitting it can start a second scan.
CHECK(strtok_r(row, "|", &field) == row + 2);
CHECK(strcmp(row + 2, "MARS") == 0);
char *traits = strtok_r(NULL, "|", &field);
CHECK(traits == row + 7);
CHECK(strtok_r(traits, ",", &trait) == traits);
CHECK(strcmp(traits, "RED") == 0);
CHECK(strtok(plain, " ") == plain);
CHECK(strtok_r(NULL, ",", &trait) == traits + 5);
CHECK(strcmp(traits + 5, "COLD") == 0);
CHECK(strtok_r(NULL, ",", &trait) == NULL);
CHECK(strtok_r(NULL, "|", &field) == row + 17);
CHECK(strcmp(row + 17, "4") == 0);
CHECK(strtok_r(NULL, "|", &field) == NULL);
CHECK(strtok_r(NULL, "|", &field) == NULL);
CHECK(strtok(NULL, " ") == plain + 2);
CHECK(strtok_r(empty, ",", &field) == NULL);
CHECK(strtok_r(separators, " ,|", &field) == NULL);
CHECK(strtok_r(untouched, "", &field) == untouched);
CHECK(strcmp(untouched, "ONE TWO") == 0);
CHECK(strtok_r(NULL, "", &field) == NULL);
char changed[] = "A,B:C+D";
CHECK(strtok_r(changed, ",", &field) == changed);
CHECK(strtok_r(NULL, ":+", &field) == changed + 2);
CHECK(strcmp(changed + 2, "B") == 0);
// Starting a new string abandons the remainder of the previous one.
CHECK(strtok_r(untouched, " ", &field) == untouched);
CHECK(strtok_r(NULL, " ", &field) == untouched + 4);
return 0;
}
static int viaList(char *buf, size_t n, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int code = vsnprintf(buf, n, fmt, args);
va_end(args);
return code;
}
static int checks(void)
{
char box[18], longBuf[42];
const char raw[2] = { 'A', 'B' };
CHECK(sizeof(int8_t) == 1 && sizeof(int16_t) == 2 && sizeof(int32_t) == 4);
CHECK(sizeof(size_t) == 2 && sizeof(ptrdiff_t) == 2 && sizeof(uintptr_t) == sizeof(void *));
CHECK(offsetof(struct Pair, number) == 1 && CHAR_BIT == 8);
#ifdef _CMOC_unsigned_char_
CHECK(CHAR_MIN == 0 && CHAR_MAX == 255);
#else
CHECK(CHAR_MIN == -128 && CHAR_MAX == 127);
#endif
CHECK(iscntrl(EOF) == 0 && isspace(EOF) == 0 && tolower(EOF) == EOF && toupper(EOF) == EOF);
CHECK(isblank('\t') && !isblank('\r') && iscntrl(127) && !isprint(127));
CHECK(isprint(' ') && !isgraph(' ') && isgraph('!') && ispunct('!') && !ispunct('a'));
CHECK(isxdigit('F') && isxdigit('b') && !isxdigit('G') && islower('b') && isupper('B'));
strcpy(box, "abcd");
memmove(box + 1, box, 4);
box[5] = 0;
CHECK(strcmp(box, "aabcd") == 0);
CHECK(strlen("") == 0 && memmove(box, box, 0) == box);
CHECK(snprintf(box, sizeof(box), NULL) < 0 && box[0] == 0);
memset(box, '@', sizeof(box));
CHECK(snprintf(NULL, 0, "%s %c", "CoCo", '3') == 6);
CHECK(snprintf(box + 1, 0, "abc") == 3 && box[1] == '@');
CHECK(snprintf(box + 1, 1, "abc") == 3 && box[1] == 0 && box[2] == '@');
CHECK(snprintf(box + 1, 4, "earth") == 5 && strcmp(box + 1, "ear") == 0);
CHECK(box[0] == '@' && box[5] == '@');
CHECK(snprintf(box, 6, "earth") == 5 && strcmp(box, "earth") == 0);
CHECK(snprintf(box, sizeof(box), "%cX", 0) == 2 && !box[0] && box[1] == 'X' && !box[2]);
CHECK(viaList(box, sizeof(box), "%04x,%X,%o", 0x1aU, 0xbeefU, 8U) == 12);
CHECK(!strcmp(box, "001a,BEEF,10"));
CHECK(snprintf(box, sizeof(box), "%-4.2s|%.0u", raw, 0U) == 5 && strcmp(box, "AB |") == 0);
CHECK(snprintf(box, sizeof(box), "%05d %4.2d %%", -23, 3) == 12 && !strcmp(box, "-0023 03 %"));
CHECK(snprintf(longBuf, sizeof(longBuf), "%ld,%lu,%lo", LONG_MIN, ULONG_MAX, ULONG_MAX) == 34);
CHECK(!strcmp(longBuf, "-2147483648,4294967295,37777777777"));
CHECK(snprintf(box, sizeof(box), "%d", INT_MIN) == 6 && !strcmp(box, "-32768"));
CHECK(snprintf(NULL, 0, "%32767d", 1) == INT_MAX);
CHECK(snprintf(box, 2, "a%32767d", 1) < 0 && !strcmp(box, "a"));
CHECK(snprintf(box, 3, "x%f") < 0 && !strcmp(box, "x"));
CHECK(snprintf(box, 3, "x%") < 0 && !strcmp(box, "x"));
return checkTokens();
}
int main(void)
{
int failure = checks();
if (failure) printf("COMPAT FAIL %d\n", failure);
else printf("COMPAT PASS\n");
return failure != 0;
}