Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
Implement asprintf for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jackoalan committed Nov 25, 2017
1 parent 191ac39 commit 6c480c7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion extern/boo
11 changes: 8 additions & 3 deletions include/hecl/Frontend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {}
Expand Down Expand Up @@ -206,14 +208,17 @@ struct IRNode
case Op::Sub: return "-"sv;
case Op::Mul: return "*"sv;
case Op::Div: return "/"sv;
default: return ""sv;
}
}

static std::string_view KindToStr(Kind k)
{
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;
Expand Down
1 change: 1 addition & 0 deletions include/hecl/winsupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
13 changes: 13 additions & 0 deletions lib/winsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 6c480c7

Please sign in to comment.