84 lines
1.7 KiB
Django/Jinja
Executable File
84 lines
1.7 KiB
Django/Jinja
Executable File
{% extends "base/wrap.c.j2" %}
|
|
{% block headers %}
|
|
{{ super() }}
|
|
#include <stdio.h>
|
|
#include "tack.h"
|
|
|
|
static tack_t mock = {0};
|
|
|
|
const char *mock_name(int func) {
|
|
switch (func) {
|
|
{% for f in functions %}
|
|
case {{ f.name }}_INDEX: return "{{ f.name }}";
|
|
{% endfor %}
|
|
}
|
|
}
|
|
|
|
void mock_print(const indexed_call_t *packed) {
|
|
if (packed == NULL) {
|
|
printf("NULL()\n");
|
|
return;
|
|
}
|
|
switch (packed->func) {
|
|
{% for f in functions %}
|
|
case {{ f.name }}_INDEX: {
|
|
INDEXED_{{ f.types }} *unpacked = (INDEXED_{{ f.types }} *)packed;
|
|
{% if f.args %}
|
|
ARGS_{{ f.types }} args = unpacked->args;
|
|
{% endif %}
|
|
printf("{{ f.name }}({{ f.args|printf }});\n"
|
|
{%- for arg in f.args %}, args.a{{ loop.index }}{% endfor -%});
|
|
break;
|
|
}
|
|
{% endfor %}
|
|
}
|
|
}
|
|
|
|
void *mock_get(int idx) {
|
|
return tack_get(&mock, idx);
|
|
}
|
|
|
|
void *mock_peek() {
|
|
return tack_peek(&mock);
|
|
}
|
|
|
|
void *mock_cur() {
|
|
return tack_cur(&mock);
|
|
}
|
|
|
|
void *mock_shift() {
|
|
return tack_shift(&mock);
|
|
}
|
|
|
|
void *mock_slide(int func) {
|
|
if (mock.pos >= mock.len) {
|
|
return NULL;
|
|
}
|
|
indexed_call_t **stack = (indexed_call_t **)mock.data;
|
|
for (int i = mock.pos; i < mock.len; i++) {
|
|
if (stack[i]->func == func) {
|
|
mock.pos = i + 1;
|
|
return stack[i];
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void mock_push(void *call) {
|
|
tack_push(&mock, call);
|
|
}
|
|
|
|
void *mock_pop() {
|
|
return tack_pop(&mock);
|
|
}
|
|
|
|
{% endblock %}
|
|
|
|
{% block func_prefix %}gles_{% endblock %}
|
|
{% block call %}
|
|
emit_{{ func.name }}({{ func.args|args(0) }});
|
|
{% if not func.void %}
|
|
return ({{ func.return }})0;
|
|
{% endif %}
|
|
{% endblock %}
|