aboutsummaryrefslogtreecommitdiff
path: root/sloth.h
blob: 809b99d17339723d7d75c62514c553a01b209482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
#include <stdint.h>
#include <stddef.h>

/* Replace '16' by desired byte size on both following lines. */
#define SLOTH_BITS 16
typedef uint16_t SlothByte;

typedef const char* SlothError;
typedef struct Sloth {
	SlothByte *stack;
	size_t stack_size;
	size_t stack_capacity;
	SlothByte mem[1 << SLOTH_BITS];
} Sloth;

void sloth_deinit(Sloth *ctx);
SlothError sloth_exec(Sloth *ctx, const char *s);
SlothError sloth_exec_line(Sloth *ctx, char *s);
SlothError sloth_pop(Sloth *ctx, SlothByte *v);
SlothError sloth_push(Sloth *ctx, SlothByte v);
void sloth_inspect_stack(const Sloth *ctx);