Skip to content

Instantly share code, notes, and snippets.

function Query_Execute() {
/* Call ExecutionPlan_Execute on a different thread
* and wait for it to exit */
char *error = NULL;
pthread_t thread;
pthread_create(&thread, NULL, ExecutionPlan_Execute, NULL);
pthread_join(thread, &error);
if(error != NULL) {
// Exception been thrown.
function A() {
jump there; // Can't jump outside of current scope.
}
function B() {
there:
...
}
try {
// Perform work which might throw an exception
work();
} catch (error *e) {
reportError(e);
}
if(cond) {
raise Exception("something went wrong")
}
@swilly22
swilly22 / dictInit.c
Created February 15, 2018 06:02
redis dict init
uint64_t dictStringHash(const void *key) {
return dictGenHashFunction(key, strlen(key));
}
void *dictStringDup(void *privdata, const void *key) {
DICT_NOTUSED(privdata);
size_t key_len = strlen(key);
char *copy = malloc((key_len + 1) * sizeof(char));
strcpy(copy, key);
copy[key_len] = 0;
@swilly22
swilly22 / arithmetic_expression.y
Created November 26, 2017 09:40
Arithmetic expression grammar
// (exp)
arithmetic_expression ::= LEFT_PARENTHESIS arithmetic_expression RIGHT_PARENTHESIS.
// exp + exp
arithmetic_expression ::= arithmetic_expression binary_operator arithmetic_expression.
// func(exp)
arithmetic_expression ::= STRING LEFT_PARENTHESIS arithmetic_expression_list RIGHT_PARENTHESIS.
// 9
arithmetic_expression ::= value.
// friend.age
arithmetic_expression ::= variable.
@swilly22
swilly22 / eval.h
Created November 26, 2017 09:38
expression_eval
Evaluate(root) {
if(node_is_const(root)) {
return root.value;
}
for(child in root) {
evaluate(child);
}
return root.op(root.children);
@swilly22
swilly22 / calc.y
Created November 26, 2017 09:34
Calculator grammar
exp: exp op exp
exp: '(' exp ')'
exp: number
op: +
-
*
/
@swilly22
swilly22 / calc.t
Created November 26, 2017 09:33
Calculator grammar
exp: exp op exp
exp: '(' exp ')'
exp: number
op: +
-
*
/