Skip to content

Instantly share code, notes, and snippets.

@alex-s168
alex-s168 / fileserver.rs
Created November 20, 2023 19:19
rust basic read only file server
use std::net::{TcpListener,TcpStream,Shutdown};
use std::result::Result;
use std::io::{Write,Read,BufRead,BufReader};
use std::thread;
use std::io;
use std::process::exit;
use std::path::Path;
use std::fs::{File,read_dir};
use std::env;
@alex-s168
alex-s168 / guide.md
Created January 23, 2024 11:56
Compiler Pipeline

Compiler Pipeline

What happens in the background when we enter tcc main.c -o out? - To find out, we need to explore the stages that a compiler goes trough.

1. (optional) preprocessor

takes in code, parses it, includes files, parses them, includes files, expands macros, ... Can also happen after (or during) main lexing (which is waaay smarter)

2. lexer (aka tokenizer)

Tokenizes your code example: printf("Hello, %s\n", getName()); -> printf ( "Hello, %s\n" , getName, ( ) ) ;

@alex-s168
alex-s168 / v16.txt
Last active January 29, 2024 13:41
6502 16-Bit Vector Extension
# 6502 16-bit vector extension
(The opcodes of this extension are choosen with the w65c02 in mind)
This extension is designed to speed up 2-D vector and memory operations.
## Registers
This extension adds one single SIMD register:
### V
A 16-bit general purpose register.
@alex-s168
alex-s168 / v32.txt
Last active January 29, 2024 13:43
6502 32-Bit Vector Extension
# 6502 32-bit vector extension
This extension is based on [16-bit vector extension)[https://gist.github.com/alex-s168/4affe0004397688aeb88fbd6e194bdc0].
All instructions and registers from the "old" extension are assumed to be present here.
## Registers
This extension adds one single SIMD register:
### W
A 32-bit single instruction multiple data (SIMD) register.
The low word of this register overlaps with the full `V` reigster.
@alex-s168
alex-s168 / get_parameters.h
Created February 14, 2024 21:33
GET parameter parsing in C
/*
Example usage:
```
char *url;
char *params[2] = { "name", "mail" };
urlGETAll(url, params, 2);
printf("name: %s\n", params[0]);
printf("mail: %s\n", params[1]);
```
*/
@alex-s168
alex-s168 / README.md
Created March 29, 2024 21:14
TicTacToe using Blitz.kt
@alex-s168
alex-s168 / cppgen.py
Created May 8, 2024 11:38
auto generate C++ wrappers for C libraries using ctags
import sys
import subprocess
start = sys.argv[2]
ty = sys.argv[3]
newty = sys.argv[4]
cmd = "ctags -x --c-kinds=f --_xformat=\"%N %S\" " + sys.argv[1]
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode('utf-8')
fns = output.split("\n")
: print ( ptr len -- )
0 do
dup
i + C@
dup 0= if
drop
leave
then
emit
loop