Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
CFLAGS=-std=c99 -pedantic -Wall -Werror
.PHONY: run forth
run: forth
./forth test.fs
forth: forth.c
$(CC) $(CFLAGS) -o forth forth.c
@fogus
fogus / daiyon.c
Created January 10, 2022 12:30 — forked from typeswitch-dev/daiyon.c
第四 (Daiyon) — a Japanese & Forth inspired postfix language
#include <stdio.h>
#include <string.h>
#include <assert.h>
FILE *in; long M[1<<24]={0}, *D, *R, H=0x130000, IP=0, T;
long getu() { long t, h = getc(in); if (h < 0xC0) return h;
t = ((h&0x1F) << 6) | (getc(in) & 0x3F); if (h < 0xE0) return t;
t = ( t << 6) | (getc(in) & 0x3F); if (h < 0xF0) return t;
t = ( t << 6) | (getc(in) & 0x3F); return t & 0x1FFFFF; }
void putu(long c) { if (c < 0x80) { putchar(c); return; }
if (c < 0x7FF) { putchar(0xC0|(c>>6)); } else {
// v is vector testing equiv
// obj is RHS operand, potentially infinite seq
else if(obj instanceof List)
{
Collection ma = (Collection) obj;
if(ma instanceof Counted)
if(ma.size() != v.count())
return false;
@fogus
fogus / TinyForth.ino
Created January 3, 2022 15:14 — forked from monsonite/TinyForth.ino
A Tiny Forth for Arduino - adapted from code from T. NAKAGAWA
// Tiny FORTH by T. NAKAGAWA 2004/07/04-10,7/29,8/5-6
/*
Tiny FORTH
Experimental Forth for Arduino
T. Nakagawa
2004/07/10
*/
#include <stdio.h>
@fogus
fogus / spec-moar.clj
Last active November 16, 2021 14:22
(defn- spec-checking-fn
"Takes a function name, a function f, and an fspec and returns a thunk that
first conforms the arguments given then calls f with those arguments if
the conform succeeds. Otherwise, an exception is thrown containing information
about the conform failure."
[fn-name f fn-spec]
(let [fn-spec (@#'s/maybe-spec fn-spec)
conform! (fn [fn-name role spec data args]
(let [conformed (s/conform spec data)]
(if (= ::s/invalid conformed)
(ns clojure.spec.test.alpha
(:refer-clojure :exclude [test])
(:require
[clojure.pprint :as pp]
[clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen]
[clojure.string :as str]))
(in-ns 'clojure.spec.test.check)
(in-ns 'clojure.spec.test.alpha)
@fogus
fogus / simpl_2015_32bit_list8.ino
Created September 14, 2021 19:30 — forked from anonymous/simpl_2015_32bit_list8.ino
32bit version of SIMPL "Serial Interpreted Minimal Programming Language"
// SIMPL
// A Serial Interpreted Minimal Programming Language
// Inspired by Txtzyme - by Ward Cunningham
// Ken Boak 2013 - 2016
// Filename simpl_2015_32bit_list8
// Requires UART routines - compiles on Arduino 1.04
// This is the slim version of simpl that removes all of the Arduino specific routines
@fogus
fogus / tforth.asm
Created September 14, 2021 19:30 — forked from anonymous/tforth.asm
TinyForth for AVR by T. NAKAGAWA
; Tiny FORTH
; T. NAKAGAWA
; 2004/08/02-05
; Additional comments by Ken Boak Jan 2016
; Register
; r0: temporary
; r1-15: input buffer (terminated by 0x00, separated by 0x20)
; r16: temporary
@fogus
fogus / VTL.ino
Created September 14, 2021 19:29 — forked from monsonite/VTL.ino
VTL - A Very Tiny Language for Arduino
// Very Tiny Language T. Nakagawa 2004/05/23 2004/06/26
#include <uart.h>
#include <avr/io.h>
#define F_CPU 16000000UL // define the clock frequency as 16MHz
#define BAUD 115200*2
#include <util/setbaud.h> // Set up the Uart baud rate generator
(defn update-keys-naive
"m f => {(f k) v ...}
Given a map m and a function f of 1-argument, returns a new map whose
keys are the result of applying f to the keys of m, mapped to the
corresponding values of m.
f must return a unique key for each key of m."
{:added "1.11"}
[m f]
(let [ret (with-meta