Skip to content

Instantly share code, notes, and snippets.

@lpereira
lpereira / finf.c
Created March 22, 2024 18:49
FINF Is Not Forth!
/*
* FINF 0.1.5a (21 Jul 2005) https://tia.mat.br/
*
* Interpreter for the "finf" (finf is not forth) language
* Copyright (C) 2005 L. A. F. Pereira <l@tia.mat.br>
*
* 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.
*
@lpereira
lpereira / coro.c
Created March 22, 2012 01:12
Simple coroutine implementation in C
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <ucontext.h>
typedef struct coro_t_ coro_t;
typedef struct thread_t_ thread_t;
typedef int (*coro_function_t)(coro_t *coro);
typedef enum {
CORO_NEW,
/*
* SPSC Bounded Queue
* Based on public domain C++ version by mstump[1]. Released under
* the same license terms.
*
* [1] https://github.com/mstump/queues/blob/master/include/spsc-bounded-queue.hpp
*/
#if !defined(__ATOMIC_RELAXED)
#!/usr/bin/python
# https://www.youtube.com/watch?v=hm5qmqHUudQ
def regressao_julia(d, k):
# A fórmula enorme, segundo a jornalista:
return (d - k*k) // (k+k)
def raiz(n):
tentativa = n
while True:
@lpereira
lpereira / gist:c0bf3ca3148321395037
Created June 23, 2014 22:26
Integer to string conversion benchmark
#include <chrono>
#include <cstdint>
#include <iostream>
#include <random>
#include <sstream>
using namespace std;
using namespace std::chrono;
const uint64_t P01 = 10;
@lpereira
lpereira / gist:ccbb99a0ed288a2e9487
Created May 14, 2015 10:57
Lwan template interpreter
New Old
movsx esi,BYTE PTR [r14+0x8] movsx esi,BYTE PTR [r13+0x8]
mov rdi,r12 mov rdi,rbp
add rbx,0x1 add r13,0x18
call 0x412fd0 <strbuf_append_char> call 0x413ed0 <strbuf_append_char>
mov rax,QWORD PTR [r15+rbx*8] mov eax,DWORD PTR [r13+0x0]
jmp QWORD PTR [rax*8+0x416440] mov rax,QWORD PTR [rax*8+0x4166a0]
jmp rax
@lpereira
lpereira / parse-number.c
Created June 7, 2015 22:04
Number parsing using C11 _Generic
/* parse_number() using C11 _Generic */
/* @lafp, 2015-06-07 */
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
#define parse_number(Input, Output) \
_Generic((*Output), \
int: parse_number_strtoint, \
/* Build with google benchmark */
#include "benchmark/benchmark.h"
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
struct error_code {
int code;
};
struct error_context {
const struct error_code *code;
const char *msg;
const char *file;
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <benchmark/benchmark.h>
unsigned int odd_constant = 0xdeadbeef | 1;
static unsigned int hash_crc32_orig(const void *keyptr)
{
unsigned int hash = odd_constant;