Implement asprintf for Windows

This commit is contained in:
Jack Andersen 2017-11-24 16:49:50 -10:00
parent 698d6a846e
commit 1987a6e3d3
4 changed files with 23 additions and 4 deletions

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit 3c90192351218a7c20ba7f96aa21b965293cc367
Subproject commit b23da43f05b59b249b5672f31ce0427a1e7ac0e6

View File

@ -63,7 +63,9 @@ struct Token
{
switch (k)
{
case Kind::None: return "none"sv;
case Kind::None:
default:
return "none"sv;
case Kind::Eof: return "eof"sv;
case Kind::Lf: return "lf"sv;
case Kind::Plus: return "+"sv;
@ -156,7 +158,7 @@ class Scanner
int _read();
bool read();
static char chr(char c) { return (c < 32 || c > 127) ? '.' : c; }
static char chr(char c) { return (c < 32) ? '.' : c; }
public:
Scanner(Diagnostics& diag) : m_diag(diag) {}
@ -206,6 +208,7 @@ struct IRNode
case Op::Sub: return "-"sv;
case Op::Mul: return "*"sv;
case Op::Div: return "/"sv;
default: return ""sv;
}
}
@ -213,7 +216,9 @@ struct IRNode
{
switch (k)
{
case Kind::None: return "none"sv;
case Kind::None:
default:
return "none"sv;
case Kind::Call: return "call"sv;
case Kind::Imm: return "imm"sv;
case Kind::Binop: return "binop"sv;

View File

@ -10,5 +10,6 @@
#include "windows.h"
void* memmem(const void *haystack, size_t hlen, const void *needle, size_t nlen);
int asprintf(char** buf, const char* format, ...);
#endif // _HECL_WINSUPPORT_H_

View File

@ -34,3 +34,16 @@ void *memmem(const void *haystack, size_t hlen, const void *needle, size_t nlen)
return NULL;
}
int asprintf(char** buf, const char* format, ...)
{
va_list ap;
va_start(ap, format);
int len = vsnprintf(nullptr, 0, format, ap);
va_end(ap);
*buf = (char*)malloc(len + 1);
va_start(ap, format);
vsnprintf(*buf, len + 1, format, ap);
va_end(ap);
return len;
}