Skip to content

Instantly share code, notes, and snippets.

View simonask's full-sized avatar

Simon Ask Ulsnes simonask

View GitHub Profile
/*
cc === "current continuation"
*/
bar: {
foo()
}
foo: {
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#define NOINLINE __attribute__((noinline))
const size_t CONTINUATION_STACK_SIZE = 8192;
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>
#define NOINLINE __attribute__((noinline))
typedef unsigned char byte;
typedef struct Continuation {
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>
typedef unsigned char byte;
typedef struct Continuation {
void* rip;
void* rsp;
/*
My very own setjmp.
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
typedef struct Continuation {
void* rip;
foo: [a, b] {
a + b
}
foo(2, 3) // => 5
ast: foo.ast.copy()
ast_addition: ast.children(0)
ast_call: ast_addition.children(0)
ast_call_target: ast_call.caller
/* simplified; no UNLESS. */
conditional: IF expression EOL body EOL post_conditional { $$ = snow_ast_if_else($2, $4, $6); }
post_conditional: END
| ELSEIF expression EOL body EOL post_conditional { $$ = snow_ast_if_else($2, $4, $6); }
| ELSE body EOL { $$ = $2; }
func parse_function(input)
{
return_type = parse_type(input)
name = parse_name_token(input)
parameters = parse_parameter_list(input)
body = parse_scope(input)
return new Function(return_type, name, parameters, body)
}
#include <stdio.h>
struct A { A() { printf("A()\n"); } ~A() { printf("~A()\n"); } };
struct B { B() { printf("B()\n"); } ~B() { printf("~B()\n"); } };
void foo(void* lbl)
{
goto *lbl;
}
void foo()
{
A a;
goto out;
B b;
out:
return;
}