From 4c3b2fec322feb8afd23703866d81f1dda51b6ae Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 11 Feb 2023 09:41:54 -0800 Subject: Add a bytecode interpreter. I wrote it in C because I actually like programming in C. Turns out setting up a Makefile is really easy too. --- bytecode/slice.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 bytecode/slice.c (limited to 'bytecode/slice.c') diff --git a/bytecode/slice.c b/bytecode/slice.c new file mode 100644 index 0000000..c7b2820 --- /dev/null +++ b/bytecode/slice.c @@ -0,0 +1,15 @@ +#include + +#include "slice.h" + +struct slice slice(struct slice a, size_t i, size_t j) +{ + assert(i <= a.size && j <= a.size && i <= j); + return (struct slice) { .size = j - i, .buf = a.buf + i }; +} + +struct slice slice1(struct slice a, size_t i) +{ + assert(i <= a.size); + return (struct slice) { .size = a.size - i, .buf = a.buf + i }; +} -- cgit v1.3.1