Skip to content

Instantly share code, notes, and snippets.

View H2CO3's full-sized avatar
🦀

Árpád Goretity  H2CO3

🦀
View GitHub Profile
//
// hash_table.hpp
// The Shift-C compiler
//
// Created by Arpad Goretity (H2CO3)
// on 02/06/2015
//
// Licensed under the 2-clause BSD License
//
@H2CO3
H2CO3 / c99.c
Created September 13, 2015 19:44
typedef struct {
int x;
} Foo;
int main()
{
int n = 1;
int VLA_is_not_in_cplusplus[n];
Foo f = { .x = 42 };
f = (Foo){ 42 };
// takes no arguments, and returns a StringLiteral AST node containing the current date formatted as a string
macro CompilationDateAsString() -> std::ASTNode * {
// imagine that we already have date/time support in our standard library
let cur_date = new std::Date();
return std::StringLiteralAST(cur_date.to_string());
}
// So, the following main() function:
fn main() {
print(@CompilationDateAsString());
def read_FASTA_file(fname):
with open(fname, "r") as f:
sequs = filter(len, f.read().split(">"))
return ["".join(seq.split("\n")[1:]) for seq in sequs]
@H2CO3
H2CO3 / mp.c
Created November 4, 2015 15:23
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
void try_mprotect(void *p, size_t len, int prot)
{
if (mprotect(p, len, prot) != 0) {
$ swift tree.swift
tree.swift:1:8: error: recursive value type 'Node' is not allowed
struct Node {
^
0 swift 0x000000010248933b llvm::sys::PrintStackTrace(__sFILE*) + 43
1 swift 0x0000000102489a7b SignalHandler(int) + 379
2 libsystem_platform.dylib 0x00007fff95d1bf1a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fff5f689e20 _sigtramp + 3382107936
4 swift 0x000000010067889b swift::irgen::TypeConverter::convertAnyNominalType(swift::CanType, swift::NominalTypeDecl*) + 379
5 swift 0x0000000100678295 swift::irgen::TypeConverter::convertType(swift::CanType) + 181
override func llvmType() -> LLVMTypeRef {
// a function with a 'Void' argument is a
// special case: it means '0 arguments'.
var args: [LLVMTypeRef] = []
if self.argType != VoidType() {
args.append(self.argType.llvmType())
}
return LLVMFunctionType(
self.retType.llvmType(),
@H2CO3
H2CO3 / pc.cc
Created February 29, 2016 22:20
// cloud must be sorted beforehand
size_t num_rows = 10;
size_t num_cols = 10;
size_t min_x = … // find from cloud
size_t max_x = … // find from cloud
size_t dx = (max_x - min_x) / num_rows;
size_t min_y = … // find from cloud
#include <vector>
#include <array>
#include <cstdio>
#include <iostream>
#include <random>
enum State: unsigned char {
Empty,
X,
#include <stdio.h>
#include <spn/ctx.h>
typedef struct {
SpnContext *ctx;
SpnFunction *fn;
SpnValue arg;
} CallbackData;