Add Conway's Game of Life

This commit is contained in:
Justine Tunney 2020-11-18 08:26:03 -08:00
parent db33973e0a
commit dba7552c1e
22 changed files with 664 additions and 186 deletions

View file

@ -16,10 +16,10 @@ LIBC_CALLS_ARTIFACTS += LIBC_CALLS_A
LIBC_CALLS = $(LIBC_CALLS_A_DEPS) $(LIBC_CALLS_A)
LIBC_CALLS_A = o/$(MODE)/libc/calls/syscalls.a
LIBC_CALLS_A_FILES := \
$(wildcard libc/calls/*) \
$(wildcard libc/calls/typedef/*) \
$(wildcard libc/calls/thunks/*) \
$(wildcard libc/calls/struct/*)
$(wildcard libc/calls/struct/*) \
$(wildcard libc/calls/*)
LIBC_CALLS_A_HDRS = $(filter %.h,$(LIBC_CALLS_A_FILES))
LIBC_CALLS_A_SRCS_S = $(filter %.S,$(LIBC_CALLS_A_FILES))
LIBC_CALLS_A_SRCS_C = $(filter %.c,$(LIBC_CALLS_A_FILES))

View file

@ -43,22 +43,22 @@ static textwindows int64_t ParseInt(char16_t **p) {
return x;
}
static textwindows void WriteAll(int64_t h, void *buf, size_t n) {
static noinline textwindows void DoAll(int64_t h, void *buf, size_t n,
bool32 (*f)()) {
char *p;
size_t i;
uint32_t wrote;
for (p = buf, i = 0; i < n; i += wrote) {
WriteFile(h, p + i, n - i, &wrote, NULL);
uint32_t x;
for (p = buf, i = 0; i < n; i += x) {
f(h, p + i, n - i, &x, NULL);
}
}
static textwindows void ReadAll(int64_t h, void *buf, size_t n) {
char *p;
size_t i;
uint32_t got;
for (p = buf, i = 0; i < n; i += got) {
ReadFile(h, p + i, n - i, &got, NULL);
}
static noinline textwindows void WriteAll(int64_t h, void *buf, size_t n) {
DoAll(h, buf, n, WriteFile);
}
static noinline textwindows void ReadAll(int64_t h, void *buf, size_t n) {
DoAll(h, buf, n, ReadFile);
}
textwindows void WinMainForked(void) {

View file

@ -16,9 +16,6 @@ int ioctl(int, uint64_t, void *);
#include "libc/macros.h"
#include "libc/sysv/consts/termios.h"
struct termios;
struct winsize;
#define ioctl(FD, REQUEST, MEMORY) ioctl$dispatch(FD, REQUEST, MEMORY)
#define __IOCTL_DISPATCH(CMP, FD, REQUEST, MEMORY) \

View file

@ -2,13 +2,12 @@
#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
#ifndef __STRICT_ANSI__
#include "libc/bits/safemacros.h"
#include "libc/calls/struct/metatermios.h"
#include "libc/calls/struct/termios.h"
#include "libc/str/str.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct termios;
union metatermios;
#define COPY_TERMIOS(TO, FROM) \
do { \
memset((TO), 0, sizeof(*(TO))); \

View file

@ -33,7 +33,6 @@ relegated noreturn void die(void) {
if (!once) {
once = true;
if (!IsTiny()) {
g_runstate |= RUNSTATE_BROKEN;
if (IsDebuggerPresent(false)) DebugBreak();
ShowBacktrace(STDERR_FILENO, NULL);
}

View file

@ -203,7 +203,6 @@ relegated void __oncrash(int sig, struct siginfo *si, ucontext_t *ctx) {
int gdbpid, err;
static bool once;
err = errno;
g_runstate |= RUNSTATE_BROKEN;
if (once) abort();
once = true;
/* TODO(jart): Needs translation for ucontext_t and possibly siginfo_t. */

View file

@ -53,7 +53,6 @@ void __ubsan_abort(const struct UbsanSourceLocation *loc,
} else {
abort();
}
g_runstate |= RUNSTATE_BROKEN;
if (IsDebuggerPresent(false)) DebugBreak();
__start_fatal(loc->file, loc->line);
fprintf(stderr, "%s\r\n", description);

View file

@ -1,23 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.h"
.comm g_runstate,4
.source __FILE__

View file

@ -1,5 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_NT_IOCP_H_
#define COSMOPOLITAN_LIBC_NT_IOCP_H_
#include "libc/nt/struct/overlapped.h"
#include "libc/nt/struct/overlappedentry.h"
#if 0
/* ░░░░
@ -26,8 +28,6 @@
cosmopolitan § new technology » i/o completion ports
*/
#endif
#include "libc/nt/struct/overlapped.h"
#include "libc/nt/struct/overlappedentry.h"
#define kNtFileSkipCompletionPortOnSuccess 1
#define kNtFileSkipSetEventOnHandle 2

View file

@ -30,7 +30,6 @@
/ @asyncsignalsafe
_Exit: push %rbp
mov %rsp,%rbp
orl $RUNSTATE_TERMINATE,g_runstate(%rip)
#if SupportsWindows()
testb IsWindows()
jz 1f
@ -49,4 +48,3 @@ _Exit: push %rbp
3: .quad 0
.endfn _Exit,globl,protected
.hidden __NR_exit
.hidden g_runstate

View file

@ -39,7 +39,6 @@ abort: push %rbp
mov %rsp,%rbp
and $-16,%rsp
sub $16,%rsp
orl $RUNSTATE_BROKEN,g_runstate(%rip)
testb IsWindows()
jnz 2f
mov SIG_SETMASK,%edi
@ -61,4 +60,3 @@ abort: push %rbp
2: mov $134,%edi # exit(128+SIGABRT) [bash-ism]
call _Exit
.endfn abort,globl,protected
.hidden g_runstate

View file

@ -31,7 +31,6 @@
_construct:
push %rbp
mov %rsp,%rbp
orb $RUNSTATE_INITIALIZED,g_runstate(%rip)
ezlea __init_array_start,ax # static ctors in forward order
.weak __init_array_start # could be called multiple times
ezlea __init_array_end,cx # idempotency recommended

View file

@ -72,7 +72,7 @@ privileged interruptfn void ftrace_hook(void) {
const char *symbol;
struct StackFrame *frame;
LOAD_DEFAULT_RBX();
if (g_symbols && !(g_runstate & RUNSTATE_BROKEN)) {
if (g_symbols) {
frame = __builtin_frame_address(0);
symbol =
&g_symbols->name_base[g_symbols

View file

@ -50,7 +50,6 @@
.section .initprologue,"ax",@progbits
.type _init,@function
.globl _init
.comm g_runstate,4
_init: push %rbp
mov %rsp,%rbp
.profilable

View file

@ -4,20 +4,15 @@
#include "libc/dce.h"
#include "libc/runtime/runtime.h"
#define RUNSTATE_INITIALIZED (1 << 0)
#define RUNSTATE_BROKEN (1 << 1)
#define RUNSTATE_TERMINATE (1 << 2)
#define STACK_CEIL 0x700000000000ul
#define STACK_SIZE FRAMESIZE
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
hidden extern bool _mmap_asan_mode;
hidden extern char **g_freebsdhint;
hidden extern unsigned g_runstate;
hidden extern void *g_stacktop;
extern hidden bool _mmap_asan_mode;
extern hidden char **g_freebsdhint;
extern hidden void *g_stacktop;
void _init(void) hidden;
void _piro(int) hidden;
@ -29,12 +24,6 @@ void _jmpstack(void *, void *, ...) hidden noreturn;
long _setstack(void *, void *, ...) hidden;
int GetDosArgv(const char16_t *, char *, size_t, char **, size_t) hidden;
forceinline void AssertNeverCalledWhileTerminating(void) {
if (!NoDebug() && (g_runstate & RUNSTATE_TERMINATE)) {
abort();
}
}
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* ANSI */

View file

@ -24,7 +24,10 @@
* without meeting its requirements concerning secrecy or length.
*/
void *memfrob(void *buf, size_t size) {
unsigned char *p = (unsigned char *)buf;
for (size_t i = 0; i < size; ++i) p[i] ^= '*';
size_t i;
unsigned char *p;
for (p = buf, i = 0; i < size; ++i) {
p[i] ^= '*';
}
return buf;
}