Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am samrat on github.
  • I am samrat (https://keybase.io/samrat) on keybase.
  • I have a public key ASDAdhJJ4_BQOj6cV92Mh7yINIEZSUwasgwdGKfkCXh0SAo

To claim this, I am signing this object:

;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 59794
;; flags: qr rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; smingh.org. IN A
;; ANSWER SECTION:
smingh.org. 10523 IN A 104.198.14.52
;; AUTHORITY SECTION:
@samrat
samrat / gist:fe9ec27ec1f9e3640632b542d7c5ff7a
Created July 21, 2017 02:40
Tiva C launchpad (GDB + OpenOCD)
Start OpenOCD in a separate terminal:
openocd -f /usr/share/openocd/scripts/board/ek-lm4f120xl.cfg
$ cat gdb.cmd
target remote localhost:3333
set arm abi APCS
monitor reset halt
file main.elf
load
rm -f myutop.top
ocamlbuild -clean
ocamlbuild -r -use-ocamlfind -tag thread -package extlib,utop -I src/ myutop.top
ocamlfind ocamldep -package extlib,utop -modules src/instr.ml > src/instr.ml.depends
ocamlfind ocamldep -package extlib,utop -modules src/util.ml > src/util.ml.depends
ocamlfind ocamldep -package extlib,utop -modules src/qbe_lexer.mli > src/qbe_lexer.mli.depends
ocamlfind ocamlc -c -thread -package extlib,utop -I src -o src/qbe_lexer.cmi src/qbe_lexer.mli
ocamlfind ocamldep -package extlib,utop -modules src/qbe_lexer.ml > src/qbe_lexer.ml.depends
ocamlfind ocamlc -c -thread -package extlib,utop -I src -o src/instr.cmo src/instr.ml
ocamlfind ocamlc -c -thread -package extlib,utop -I src -o src/util.cmo src/util.ml
function d $foo(d %m) {
@start
%v3 =d div d_4.2, %m
ret %v3
}
function w $foo(w %x) {
@start
jnz %x, @cond, @end
@cond
%B0 =l alloc4 8
%B1 =l add %B0, 4
storew 12, %B0
storew 111, %B1
%v5 =w add 1, %x
ret %B0
@samrat
samrat / etc-linux.c.patch
Last active August 18, 2016 10:04
Building lcc on x64 Linux
diff --git a/etc/linux.c b/etc/linux.c
index 5df6059..f039d69 100755
--- a/etc/linux.c
+++ b/etc/linux.c
@@ -17,18 +17,18 @@ char *cpp[] = { LCCDIR "gcc/cpp",
"$1", "$2", "$3", 0 };
char *include[] = {"-I" LCCDIR "include", "-I" LCCDIR "gcc/include", "-I/usr/include", 0 };
char *com[] = {LCCDIR "rcc", "-target=x86/linux", "$1", "$2", "$3", 0 };
-char *as[] = { "/usr/bin/as", "-o", "$3", "$1", "$2", 0 };
+char *as[] = { "/usr/bin/as", "--32", "-o", "$3", "$1", "$2", 0 };
@samrat
samrat / lisp.erl
Last active August 16, 2016 14:48
A small Lisp interpreter in Erlang
-module(lisp).
-export([repl/0]).
-type expr() :: {ident, string()}
| {int, integer()}
| {bool, boolean()}
| {list, [expr()]}
| no_match.
-type token() :: {ident, string()}
import Data.Char
-- Grammar
-- =======
-- expr -> id | num | list
-- list -> '(' seq ')'
-- seq -> {expr}
data Exp = EIdent String
| EInt String
@samrat
samrat / gist:f5f25efd0285694204ce6be5a0e5b7f0
Created July 5, 2016 15:48
arrowhead in a geometry shader
/* Arrowhead */
float ang = (PI / 6.0) - atan(vDir[0].y, vDir[0].x);
gl_Position = gl_in[0].gl_Position + vec4(vDir[0], 0.0, 0.0) + vec4(-cos(ang)*0.04, sin(ang)*0.04, 0.0, 0.0);
EmitVertex();
gl_Position = gl_in[0].gl_Position + vec4(vDir[0], 0.0, 0.0);
EmitVertex();
ang = -(PI / 6.0) - atan(vDir[0].y, vDir[0].x);