-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
54 lines (43 loc) · 1.28 KB
/
common.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef COMMON_H
#define COMMON_H
#define LASSERT(args, cond, fmt, ...) \
if (!(cond)) \
{ \
lval* err = lval_err(fmt, ##__VA_ARGS__); \
lval_del(args); \
return err; \
}
#define LASSERT_TYPE(func, args, index, expect) \
LASSERT(args, args->cell[index]->type == expect, \
"Function '%s' passed incorrect type for argument %i. " \
"Got %s, Expected %s.", \
func, index, ltype_name(args->cell[index]->type), ltype_name(expect))
#define LASSERT_NUM(func, args, num) \
LASSERT(args, args->count == num, \
"Function '%s' passed incorrect number of arguments. " \
"Got %i, Expected %i.", \
func, args->count, num)
#define LASSERT_NOT_EMPTY(func, args, index) \
LASSERT(args, args->cell[index]->count != 0, \
"Function '%s' passed {} for argument %i.", func, index);
/* Stubbing out readline and history for windows
* Apparently windows handles history and
* navigation all well by default. */
#ifdef _WIN32
#include <string.h>
static char buffer[2048];
char* readline(char* prompt)
{
fputs(prompt, stdout);
fgets(buffer, 2048, stdin);
char* cpy = malloc(strlen(buffer)+1);
strcpy(cpy, buffer);
cpy[strlen(cpy)-1] = "\0";
return cpy;
}
void add_history(char* unused) {}
#else
#include <readline/history.h>
#include <readline/readline.h>
#endif
#endif