Skip to content

Instantly share code, notes, and snippets.

@andydude
andydude / scheme_list.py
Last active October 11, 2024 19:35
Impl. of (scheme list) == (srfi 1) in Python.
"""
scheme_list.py -- by andydude
This is an implementation of (scheme list) == (srfi 1) in Python.
"""
import itertools
from typing import Callable
from scheme_base import (
car,
@andydude
andydude / scheme_base.py
Created October 5, 2024 12:33
Impl. of (scheme base) in Python.
"""
scheme_base.py -- by andydude
This is an implementation of (scheme base) in Python.
"""
class char_t(str):
def __init__(self, o):
if isinstance(o, int):
self.__init__(chr(o))
@andydude
andydude / hex0-4.py
Created September 22, 2024 16:49
Hex0 assembler, revised
# -*- mode: python; -*-
from dataclasses import dataclass
from enum import IntEnum
from functools import reduce
class Var(IntEnum):
SOF = -2
EOF = -1
WS = 0
@andydude
andydude / indent-sexpr.py
Created August 18, 2024 02:38
indent-sexpr
#!/usr/bin/env python3
import hy
import io
TAB = " "
class Writer:
indent: int = -1
def __init__(self):
@andydude
andydude / hex0.scm
Created August 16, 2024 04:20
Hex0 assembler in scheme
(import (scheme base)
(scheme char)
(scheme file)
(scheme read)
(scheme write))
(define hold
(make-parameter 0))
(define toggle
@andydude
andydude / hex0.py
Created August 16, 2024 04:18
Hex0 assembler in python
from dataclasses import dataclass
from typing import List, Tuple
from enum import IntEnum
@dataclass
class ScannerDFA:
class Variable(IntEnum):
EOF = -1
@andydude
andydude / mbr_try1.asm
Last active August 14, 2024 01:05
First attempt at a master boot record.
[bits 16]
[org 0x7C00]
start:
cli
xor si,si
mov ss,si
mov sp,0x7DBE
popa
mov es,si
bool btr(int *a, int b) {
int c = (*a >> b) & 1;
*a &= ~(1 << b);
return c;
}
@andydude
andydude / conf.c
Last active April 25, 2019 06:49
Config Reader
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void
strvec_slurp (char **envstrvec, size_t size, size_t nitems,
const char *filename)
{
FILE *fp = fopen (filename, "r");
@andydude
andydude / prog.c
Created December 31, 2018 18:00
IOCCC 2017
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
typedef unsigned char*_;
_ s,i,z,e,O,F=
#include W
"; ; } { { { { { } { { } ; } { ; ; { } ; { { } ; } ; { { { { } { { } \
; } { { { { { } { ; } { } { { } { { } { { { ; ; { { } { { } { ; } { \
} { { { { { } ; } { } { { } { { { \