OBFI

Brainfuck Interpreter
git clone http://git.omkov.net/OBFI
Log | Tree | Refs | README | LICENCE | Download

AuthorJakob Wakeling <[email protected]>
Date2020-09-20 03:18:23
Commit72ba95922f02ef96b02c1a79069fe03a3dcd8132
Parente2b8eb19108e47f66fc01a113ae53c95cd0cfd43

Add basic comments

Diffstat

M src/obfi.c | 5 +++++

1 files changed, 5 insertions, 0 deletions

diff --git a/src/obfi.c b/src/obfi.c
index 67b6e7b..db7f355 100644
--- a/src/obfi.c
+++ b/src/obfi.c
@@ -136,14 +136,17 @@ int main(int ac, char *av[]) { A0 = av[0];
 	free(S); free(fb); free(fc); return 0;
 }
 
+/* Check if s2 is fully matched at the start of s1 */
 static inline int cmp(const char *s1, const char *s2) {
 	size_t i = 0; for (; s2[i] && s1[i] == s2[i]; ++i) {} return !s2[i];
 }
 
+/* Execute an array of Brainfuck instructions */
 static inline int run(const char *fb, const long *fc) {
 	uint_fast8_t *M = calloc(TAPELEN, sizeof (*M)), *p = M;
 	if (!M) { return 1; }
 
+	// Execute each optimised Brainfuck instruction
 	for (size_t i = 0; fb[i]; ++i) switch (fb[i]) {
 	case 1: { p  += fc[i]; break; }
 	case 2: { *p += fc[i]; break; }
@@ -159,6 +162,7 @@ static inline int run(const char *fb, const long *fc) {
 	free(M); return 0;
 }
 
+/* Print help information */
 static void hlp(void) {
 	puts("OBFI - OMKOV Brainfuck Interpreter\n");
 	puts("USAGE: obfi file\n");
@@ -168,6 +172,7 @@ static void hlp(void) {
 	return;
 }
 
+/* Print version information */
 static void ver(void) {
 	puts("OBFI, version " PROJECT_VERSION);
 	puts("Copyright (C) 2020, Jakob Wakeling");