Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TinyBasic/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class OpCode(IntEnum):
out.append(buf[-1] | 0x80)


test = "".join(map("{:02X}".format, out)) # ty: ignore[no-matching-overload]
test = "".join(map("{:02X}".format, out))
assert test == "".join(
line[5:line.index(";", 5)] for line in interpreter.splitlines() if len(line) > 5
)
2 changes: 1 addition & 1 deletion aoc2024/day11.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
cache[stone] = sum(counts) # pyright: ignore[reportCallIssue, reportArgumentType]
else:
q.append(t)
q.extend(zip(repeat(n), compress(stones, map(not_, counts)))) # pyright: ignore[reportArgumentType]
q.extend(zip(repeat(n), compress(stones, map(not_, counts)))) # ty: ignore[invalid-argument-type]

print(sum(caches[25].values()))
print(sum(caches[75].values()))
2 changes: 1 addition & 1 deletion aoc2024/day19.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def count(haystack: str) -> int:

with open("aoc2024/day19input.txt", "rt") as lines:
patterns = next(lines).rstrip().replace(" ", "").split(",")
count = counter(sorted(patterns, key=len, reverse=True)) # ty: ignore[invalid-argument-type]
count = counter(sorted(patterns, key=len, reverse=True))
next(lines)
counts = [count(line.rstrip()) for line in lines]

Expand Down
2 changes: 1 addition & 1 deletion aoc2025/day10.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def first_half(desired: list[int], buttons: list[tuple[int]]):
return total


def second_half(buttons: list[tuple[int]], joltages: list[tuple[int]]) -> int:
def second_half(buttons: list[tuple[int, ...]], joltages: list[tuple[int, ...]]) -> int:
total = 0
for button, joltage in zip(buttons, joltages):
A_eq = sparse.dok_array((len(joltage), len(button)))
Expand Down
8 changes: 7 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import re
import subprocess

Expand Down Expand Up @@ -43,10 +44,14 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
target = {
"test_4th": "4th",
"test_5th": "5th.ll",
"test_6th": "zig-out/bin/6th",
}[metafunc.function.__name__]
scenarios = scenarios.format(
argv0=f"./{target}",
uid=os.getuid(),
getuid=24 if platform.system() == "Darwin" else 102,
setuid=23 if platform.system() == "Darwin" else 105,
access=33 if platform.system() == "Darwin" else 21,
)
subprocess.run(["make", target], cwd="forth", check=True)
cp = subprocess.run(
Expand All @@ -63,6 +68,7 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
["actual", "expected"],
zip(
cp.stdout.splitlines(),
re.findall(r"(?<=\\ )(.+)$", scenarios, re.M),
re.findall(r"(?<=\\ )(.+)$", scenarios, flags=re.M),
),
ids=re.findall(r"^(.+?)(?= \\ )", scenarios, flags=re.M),
)
39 changes: 22 additions & 17 deletions forth/4th.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

#if __has_include ("cosmopolitan.h") /* https://justine.lol/ape.html */
#include "cosmopolitan.h"
#define __NR_brk __NR_linux_brk
#else
#include <assert.h>
#include <fcntl.h> /* O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_NONBLOCK */
#include <stddef.h> /* size_t, offsetof */
#include <stdio.h> /* EOF, getchar_unlocked, putchar_unlocked */
#include <stdlib.h> /* exit, strtol, syscall */
#include <string.h> /* memcmp, memmove, memcpy */
#include <sys/syscall.h> /* __NR_exit, __NR_open, __NR_close, __NR_read, __NR_write, __NR_creat, __NR_brk */
#include <sys/syscall.h> /* SYS_exit, SYS_open, SYS_close, SYS_read, SYS_write, SYS_creat, SYS_brk */
#include <unistd.h> /* read, write, intptr_t */
#endif

Expand Down Expand Up @@ -40,7 +39,7 @@ code_##_label
#include <stdarg.h>

/* https://github.com/emscripten-core/emscripten/issues/6708 */
enum SYS {__NR_read, __NR_write, __NR_open, __NR_close, __NR_brk=0x0c, __NR_exit=0x3c, __NR_creat=0x55};
enum SYS {SYS_read, SYS_write, SYS_open, SYS_close, SYS_brk=0x0c, SYS_exit=0x3c, SYS_creat=0x55};
int syscall(int sysno, ...)
{
va_list ap;
Expand All @@ -49,19 +48,25 @@ int syscall(int sysno, ...)

switch(sysno)
{
case __NR_read : status = read(va_arg(ap, int), va_arg(ap, void *), va_arg(ap, size_t)); break;
case __NR_write: status = write(va_arg(ap, int), va_arg(ap, const void *), va_arg(ap, size_t)); break;
case __NR_open : status = open(va_arg(ap, const char *), va_arg(ap, int), va_arg(ap, mode_t)); break;
case __NR_close: status = close(va_arg(ap, int)); break;
case __NR_brk : status = (intptr_t)va_arg(ap, void *); status = status ? brk((void *)status) : (intptr_t)sbrk(0); break;
case __NR_exit : status = va_arg(ap, int); va_end(ap); exit(status);
case __NR_creat: status = creat(va_arg(ap, const char *), va_arg(ap, mode_t)); break;
case SYS_read : status = read(va_arg(ap, int), va_arg(ap, void *), va_arg(ap, size_t)); break;
case SYS_write: status = write(va_arg(ap, int), va_arg(ap, const void *), va_arg(ap, size_t)); break;
case SYS_open : status = open(va_arg(ap, const char *), va_arg(ap, int), va_arg(ap, mode_t)); break;
case SYS_close: status = close(va_arg(ap, int)); break;
case SYS_brk : status = (intptr_t)va_arg(ap, void *); status = status ? brk((void *)status) : (intptr_t)sbrk(0); break;
case SYS_exit : status = va_arg(ap, int); va_end(ap); exit(status);
case SYS_creat: status = creat(va_arg(ap, const char *), va_arg(ap, mode_t)); break;
}
va_end(ap);
return status;
}
#endif

#ifdef __APPLE__
#define SYS_creat 0x55
#define SYS_brk 0x0c
#define fflush_unlocked fflush
#endif

enum Flags {F_IMMED=0x80, F_HIDDEN=0x20, F_LENMASK=0x1f};
struct word_t {
struct word_t *link;
Expand Down Expand Up @@ -398,13 +403,13 @@ DEFCONST(__DOCOL, 0, "DODOES", __DODOES, &&DODOES);
DEFCONST(__DODOES, 0, "F_IMMED", __F_IMMED, F_IMMED);
DEFCONST(__F_IMMED, 0, "F_HIDDEN", __F_HIDDEN, F_HIDDEN);
DEFCONST(__F_HIDDEN, 0, "F_LENMASK", __F_LENMASK, F_LENMASK);
DEFCONST(__F_LENMASK, 0, "SYS_EXIT", SYS_EXIT, __NR_exit);
DEFCONST(SYS_EXIT, 0, "SYS_OPEN", SYS_OPEN, __NR_open);
DEFCONST(SYS_OPEN, 0, "SYS_CLOSE", SYS_CLOSE, __NR_close);
DEFCONST(SYS_CLOSE, 0, "SYS_READ", SYS_READ, __NR_read);
DEFCONST(SYS_READ, 0, "SYS_WRITE", SYS_WRITE, __NR_write);
DEFCONST(SYS_WRITE, 0, "SYS_CREAT", SYS_CREAT, __NR_creat);
DEFCONST(SYS_CREAT, 0, "SYS_BRK", SYS_BRK, __NR_brk);
DEFCONST(__F_LENMASK, 0, "SYS_EXIT", SYS_EXIT, SYS_exit);
DEFCONST(SYS_EXIT, 0, "SYS_OPEN", SYS_OPEN, SYS_open);
DEFCONST(SYS_OPEN, 0, "SYS_CLOSE", SYS_CLOSE, SYS_close);
DEFCONST(SYS_CLOSE, 0, "SYS_READ", SYS_READ, SYS_read);
DEFCONST(SYS_READ, 0, "SYS_WRITE", SYS_WRITE, SYS_write);
DEFCONST(SYS_WRITE, 0, "SYS_CREAT", SYS_CREAT, SYS_creat);
DEFCONST(SYS_CREAT, 0, "SYS_BRK", SYS_BRK, SYS_brk);
DEFCONST(SYS_BRK, 0, "O_RDONLY", __O_RDONLY, O_RDONLY);
DEFCONST(__O_RDONLY, 0, "O_WRONLY", __O_WRONLY, O_WRONLY);
DEFCONST(__O_WRONLY, 0, "O_RDWR", __O_RDWR, O_RDWR);
Expand Down
7 changes: 6 additions & 1 deletion forth/5th.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syscall.h>
#include <sys/syscall.h>
#include <unistd.h>

#ifdef EMSCRIPTEN
Expand All @@ -14,6 +14,11 @@
enum SYS {SYS_exit, SYS_open, SYS_close, SYS_read, SYS_write, SYS_creat, SYS_brk};
#endif

#ifdef __APPLE__
#define SYS_creat 24
#define SYS_brk 214
#endif

#define NEXT __attribute__((musttail)) return ip->word->code(env, sp, rsp, ip + 1, ip->word)
#define DEFCODE_(_link, _flag, _name, _label) \
intptr_t *_label(struct interp_t *, intptr_t *, union instr_t **, union instr_t *, union instr_t *); \
Expand Down
Loading
Loading