Files @ 85419b0950c7
Branch filter:

Location: CSY/reowolf/examples/utility.c - annotation

MH
Rewrote typing to use indices.

Currently it is slower than before, because we do a HashMap lookup
followed up by actually using the index. But it serves as the basis
for a faster type inferencer.

The main goal, however, is to fix the manner in which polymorph
types are determined. The typing queue of functions still needs to
correctly write this data to the type table.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "../reowolf.h"

size_t get_user_msg(char * buf, size_t cap) {
	memset(buf, 0, cap);
	printf("Insert a msg of max len %zu: ", cap);
	fgets(buf, cap, stdin);
	for(size_t len = 0; len<cap; len++)
		if(buf[len]==0 || buf[len]=='\n')
			return len;
	return cap;
}
void rw_err_peek(Connector * c) {
	printf("Error str `%s`\n", reowolf_error_peek(NULL));
}

// allocates a buffer!
char * buffer_pdl(char * filename) {
	FILE *f = fopen(filename, "rb");
	if (f == NULL) {
		printf("Opening pdl file returned errno %d!\n", errno);
		exit(1);
	}
	fseek(f, 0, SEEK_END);
	long fsize = ftell(f);
	fseek(f, 0, SEEK_SET);
	char *pdl = malloc(fsize + 1);
	fread(pdl, 1, fsize, f);
	fclose(f);
	pdl[fsize] = 0;
	return pdl;
}