summaryrefslogtreecommitdiff
path: root/val.c
blob: 9e832a602fa79f44d48578c0dc4e391cd7953c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include "val.h"

void print_val(Val v) {
	switch (v.ty) {
	case TY_NIL:
		printf("nil");
		break;
	case TY_NUM:
		printf("%f",AS_NUM(v));
		break;
	case TY_BOOL:
		printf("%s",AS_BOOL(v) ? "true" : "false");
		break;
	}
}

void println_val(Val v) {
	print_val(v);
	putchar('\n');
}

static const char *ty_names[] = {
	"nil",
	"num",
	"bool",
};

const char *valty_str(ValTy ty) {
	return ty_names[ty];
}