Skip to content

Distribute and run LLMs with a single file.

Add make syntax highlighting

Justine Tunney6e274b2d6a17
diff --git a/llamafile/high.cpp b/llamafile/high.cpp
index 6e140954..77fbd0a0 100644
--- a/llamafile/high.cpp
+++ b/llamafile/high.cpp
@@ -25,6 +25,35 @@
// syntax highlighter demo
+static std::string basename(const std::string_view path) {
+ size_t i, e;
+ if ((e = path.size())) {
+ while (e > 1 && path[e - 1] == '/')
+ --e;
+ i = e - 1;
+ while (i && path[i - 1] != '/')
+ --i;
+ return std::string(path.substr(i, e - i));
+ } else {
+ return ".";
+ }
+}
+
+static std::string extname(const std::string_view path) {
+ std::string name = basename(path);
+ size_t dot_pos = name.find_last_of('.');
+ if (dot_pos == std::string::npos || dot_pos == name.length() - 1)
+ return name;
+ return std::string(name.substr(dot_pos + 1));
+}
+
+std::string tolower(const std::string_view &s) {
+ std::string b;
+ for (char c : s)
+ b += tolower(c);
+ return b;
+}
+
int main(int argc, char *argv[]) {
// process flags
@@ -64,8 +93,9 @@ int main(int argc, char *argv[]) {
const char *ext;
if (lang) {
h = Highlight::create(lang);
- } else if (inpath && (ext = strrchr(inpath, '.'))) {
- h = Highlight::create(ext + 1);
+ } else if (inpath) {
+ if (!(h = Highlight::create(tolower(extname(inpath)))))
+ h = new HighlightMarkdown;
} else {
h = Highlight::create("markdown");
}
diff --git a/llamafile/highlight.cpp b/llamafile/highlight.cpp
index 83588f1e..cda98467 100644
--- a/llamafile/highlight.cpp
+++ b/llamafile/highlight.cpp
@@ -19,6 +19,9 @@
Highlight *Highlight::create(const std::string_view &lang) {
+ if (lang == "txt")
+ return new HighlightTxt;
+
if (lang == "md" || //
lang == "markdown")
return new HighlightMarkdown;
@@ -85,6 +88,7 @@ Highlight *Highlight::create(const std::string_view &lang) {
return new HighlightCss;
if (lang == "html" || //
+ lang == "xhtml" || //
lang == "xml")
return new HighlightHtml;
@@ -158,5 +162,12 @@ Highlight *Highlight::create(const std::string_view &lang) {
lang == "forth")
return new HighlightForth;
- return new HighlightPlain;
+ if (lang == "mk" || //
+ lang == "make" || //
+ lang == "gmake" || //
+ lang == "makefile" || //
+ lang == "gmakefile")
+ return new HighlightMake;
+
+ return nullptr;
}
diff --git a/llamafile/highlight.h b/llamafile/highlight.h
index ca685651..6df55998 100644
--- a/llamafile/highlight.h
+++ b/llamafile/highlight.h
@@ -31,7 +31,8 @@
#define HI_ATTRIB "\033[35m" // magenta
#define HI_LINENO "\033[2m" // fade
#define HI_CONTIN "\033[33m" // yellow
-#define HI_LABEL "\033[2;33m" // dim yellow
+#define HI_LABEL "\033[33m" // yellow
+#define HI_DEF "\033[2;33m" // dim yellow
#define HI_TYPE "\033[36m" // cyan
#define HI_CLASS "\033[1;36m" // bold cyan
#define HI_SELECTOR "\033[33m" // yellow
@@ -106,6 +107,8 @@ is_keyword_f is_keyword_typescript_constant;
is_keyword_f is_keyword_forth;
is_keyword_f is_keyword_forth_def;
is_keyword_f is_keyword_m4;
+is_keyword_f is_keyword_make;
+is_keyword_f is_keyword_make_builtin;
}
class Highlight {
@@ -116,10 +119,10 @@ class Highlight {
virtual void flush(std::string *result) = 0;
};
-class HighlightPlain : public Highlight {
+class HighlightTxt : public Highlight {
public:
- HighlightPlain();
- ~HighlightPlain() override;
+ HighlightTxt();
+ ~HighlightTxt() override;
void feed(std::string *result, std::string_view input) override;
void flush(std::string *result) override;
};
@@ -506,3 +509,15 @@ class HighlightM4 : public Highlight {
int t_ = 0;
std::string word_;
};
+
+class HighlightMake : public Highlight {
+ public:
+ HighlightMake();
+ ~HighlightMake() override;
+ void feed(std::string *result, std::string_view input) override;
+ void flush(std::string *result) override;
+
+ private:
+ int t_ = 0;
+ std::string word_;
+};
diff --git a/llamafile/highlight_forth.cpp b/llamafile/highlight_forth.cpp
index 2fa12205..83148298 100644
--- a/llamafile/highlight_forth.cpp
+++ b/llamafile/highlight_forth.cpp
@@ -67,7 +67,7 @@ void HighlightForth::feed(std::string *r, std::string_view input) {
} else if (is_keyword_forth_def(word_.data(), word_.size())) {
*r += HI_KEYWORD;
*r += word_;
- *r += HI_LABEL;
+ *r += HI_DEF;
is_label_ = true;
} else if (is_keyword_forth(word_.data(), word_.size())) {
*r += HI_KEYWORD;
diff --git a/llamafile/highlight_make.cpp b/llamafile/highlight_make.cpp
new file mode 100644
index 00000000..97eb5e8a
--- /dev/null
+++ b/llamafile/highlight_make.cpp
@@ -0,0 +1,215 @@
+// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;coding:utf-8 -*-
+// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
+//
+// Copyright 2024 Mozilla Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "highlight.h"
+#include "string.h"
+#include <ctype.h>
+
+enum {
+ NORMAL,
+ WORD,
+ COMMENT,
+ DOLLAR,
+ DOLLAR2,
+ VARIABLE,
+ BACKSLASH,
+};
+
+static bool is_automatic_variable(int c) {
+ switch (c) {
+ case '@':
+ case '%':
+ case '<':
+ case '?':
+ case '^':
+ case '+':
+ case '|':
+ case '*':
+ return true;
+ default:
+ return false;
+ }
+}
+
+HighlightMake::HighlightMake() {
+}
+
+HighlightMake::~HighlightMake() {
+}
+
+void HighlightMake::feed(std::string *r, std::string_view input) {
+ for (size_t i = 0; i < input.size();) {
+ wchar_t c = read_wchar(input, &i);
+ switch (t_) {
+
+ Normal:
+ case NORMAL:
+ if (!isascii(c) || isalpha(c) || c == '_' || c == '-' || c == '.') {
+ t_ = WORD;
+ append_wchar(&word_, c);
+ break;
+ } else if (c == '#') {
+ t_ = COMMENT;
+ *r += HI_COMMENT;
+ *r += '#';
+ } else if (c == '$') {
+ t_ = DOLLAR;
+ *r += '$';
+ } else if (c == '\\') {
+ t_ = BACKSLASH;
+ *r += HI_ESCAPE;
+ *r += '\\';
+ } else {
+ append_wchar(r, c);
+ }
+ break;
+
+ case BACKSLASH:
+ append_wchar(r, c);
+ *r += HI_RESET;
+ t_ = NORMAL;
+ break;
+
+ case WORD:
+ if (!isascii(c) || isalnum(c) || c == '_' || c == '-' || c == '.') {
+ append_wchar(&word_, c);
+ } else {
+ if (is_keyword_make(word_.data(), word_.size())) {
+ *r += HI_KEYWORD;
+ *r += word_;
+ *r += HI_RESET;
+ } else {
+ *r += word_;
+ }
+ word_.clear();
+ t_ = NORMAL;
+ goto Normal;
+ }
+ break;
+
+ case DOLLAR:
+ if (isdigit(c) || is_automatic_variable(c)) {
+ *r += HI_VAR;
+ append_wchar(r, c);
+ *r += HI_RESET;
+ t_ = NORMAL;
+ } else if (c == '$') {
+ t_ = DOLLAR2;
+ *r += '$';
+ } else if (c == '(') {
+ t_ = VARIABLE;
+ *r += '(';
+ } else {
+ t_ = NORMAL;
+ goto Normal;
+ }
+ break;
+
+ case DOLLAR2:
+ if (c == '(') {
+ t_ = VARIABLE;
+ *r += '(';
+ } else {
+ t_ = NORMAL;
+ goto Normal;
+ }
+ break;
+
+ case VARIABLE:
+ if (isalnum(c) || //
+ c == '%' || //
+ c == '*' || //
+ c == '+' || //
+ c == '-' || //
+ c == '.' || //
+ c == '<' || //
+ c == '?' || //
+ c == '@' || //
+ c == '_') {
+ append_wchar(&word_, c);
+ } else if (c == '$' && word_.empty()) {
+ t_ = DOLLAR;
+ *r += '$';
+ } else if (c == ')' || //
+ c == ':') {
+ *r += HI_VAR;
+ *r += word_;
+ *r += HI_RESET;
+ word_.clear();
+ append_wchar(r, c);
+ t_ = NORMAL;
+ } else {
+ if (is_keyword_make_builtin(word_.data(), word_.size())) {
+ *r += HI_BUILTIN;
+ *r += word_;
+ *r += HI_RESET;
+ } else {
+ *r += word_;
+ }
+ word_.clear();
+ t_ = NORMAL;
+ goto Normal;
+ }
+ break;
+
+ case COMMENT:
+ if (c == '\n') {
+ *r += HI_RESET;
+ *r += '\n';
+ t_ = NORMAL;
+ } else {
+ append_wchar(r, c);
+ }
+ break;
+
+ default:
+ __builtin_unreachable();
+ }
+ }
+}
+
+void HighlightMake::flush(std::string *r) {
+ switch (t_) {
+ case WORD:
+ if (is_keyword_make(word_.data(), word_.size())) {
+ *r += HI_KEYWORD;
+ *r += word_;
+ *r += HI_RESET;
+ } else {
+ *r += word_;
+ }
+ word_.clear();
+ break;
+ case VARIABLE:
+ if (is_keyword_make_builtin(word_.data(), word_.size())) {
+ *r += HI_BUILTIN;
+ *r += word_;
+ *r += HI_RESET;
+ } else {
+ *r += word_;
+ }
+ word_.clear();
+ break;
+ case COMMENT:
+ case BACKSLASH:
+ *r += HI_RESET;
+ break;
+ default:
+ break;
+ }
+ t_ = NORMAL;
+}
diff --git a/llamafile/highlight_markdown.cpp b/llamafile/highlight_markdown.cpp
index 208aa24e..d432986f 100644
--- a/llamafile/highlight_markdown.cpp
+++ b/llamafile/highlight_markdown.cpp
@@ -207,7 +207,8 @@ void HighlightMarkdown::feed(std::string *r, std::string_view input) {
append_wchar(r, c);
lang_ += tolower(c);
} else {
- highlighter_ = Highlight::create(lang_);
+ if (!(highlighter_ = Highlight::create(lang_)))
+ highlighter_ = new HighlightTxt;
lang_.clear();
t_ = CODE;
goto Code;
diff --git a/llamafile/highlight_perl.cpp b/llamafile/highlight_perl.cpp
index d0894f43..7fd6e726 100644
--- a/llamafile/highlight_perl.cpp
+++ b/llamafile/highlight_perl.cpp
@@ -161,26 +161,26 @@ void HighlightPerl::feed(std::string *r, std::string_view input) {
} else if (c == '\'') {
t_ = QUOTE;
*r += HI_STRING;
- append_wchar(r, c);
+ *r += '\'';
expect_ = EXPECT_OPERATOR;
} else if (c == '"') {
t_ = DQUOTE;
*r += HI_STRING;
- append_wchar(r, c);
+ *r += '"';
expect_ = EXPECT_OPERATOR;
} else if (c == '=' && (!last_ || last_ == '\n')) {
t_ = EQUAL;
} else if (c == '\\') {
t_ = BACKSLASH;
*r += HI_ESCAPE;
- append_wchar(r, c);
+ *r += '\\';
} else if (c == '`') {
t_ = TICK;
*r += HI_STRING;
- append_wchar(r, c);
+ *r += '`';
expect_ = EXPECT_OPERATOR;
} else if (c == '$') {
- append_wchar(r, c);
+ *r += '$';
t_ = VAR;
expect_ = EXPECT_OPERATOR;
} else if (c == '@' || c == '%') {
@@ -190,10 +190,10 @@ void HighlightPerl::feed(std::string *r, std::string_view input) {
expect_ = EXPECT_OPERATOR;
} else if (c == '#') {
*r += HI_COMMENT;
- append_wchar(r, c);
+ *r += '#';
t_ = COMMENT;
} else if (c == '<') {
- append_wchar(r, c);
+ *r += '<';
t_ = LT;
expect_ = EXPECT_VALUE;
} else if (c == '/' && expect_ == EXPECT_VALUE && last_ != '/') {
@@ -204,7 +204,7 @@ void HighlightPerl::feed(std::string *r, std::string_view input) {
append_wchar(r, c);
t_ = REGEX;
} else if (c == '\n') {
- append_wchar(r, c);
+ *r += '\n';
if (pending_heredoc_) {
*r += HI_STRING;
pending_heredoc_ = false;
diff --git a/llamafile/highlight_test.cpp b/llamafile/highlight_test.cpp
index 4d147607..ae1478ac 100644
--- a/llamafile/highlight_test.cpp
+++ b/llamafile/highlight_test.cpp
@@ -47,11 +47,11 @@ const char *const kLanguages[] = {
"lisp", //
"lua", //
"m4", //
+ "make", //
"markdown", //
"pascal", //
"perl", //
"php!", //
- "plain", //
"python", //
"ruby", //
"rust", //
@@ -59,6 +59,7 @@ const char *const kLanguages[] = {
"sql", //
"swift", //
"tcl", //
+ "txt", //
"typescript", //
"zig", //
};
diff --git a/llamafile/highlight_plain.cpp b/llamafile/highlight_txt.cpp
similarity index 81%
rename from llamafile/highlight_plain.cpp
rename to llamafile/highlight_txt.cpp
index b0401633..18d5e390 100644
--- a/llamafile/highlight_plain.cpp
+++ b/llamafile/highlight_txt.cpp
@@ -17,16 +17,16 @@
#include "highlight.h"
-HighlightPlain::HighlightPlain() {
+HighlightTxt::HighlightTxt() {
}
-HighlightPlain::~HighlightPlain() {
+HighlightTxt::~HighlightTxt() {
}
-void HighlightPlain::feed(std::string *r, std::string_view input) {
+void HighlightTxt::feed(std::string *r, std::string_view input) {
for (size_t i = 0; i < input.size(); ++i)
*r += input[i] & 255;
}
-void HighlightPlain::flush(std::string *r) {
+void HighlightTxt::flush(std::string *r) {
}
diff --git a/llamafile/is_keyword_make.c b/llamafile/is_keyword_make.c
new file mode 100644
index 00000000..593c3513
--- /dev/null
+++ b/llamafile/is_keyword_make.c
@@ -0,0 +1,197 @@
+/* ANSI-C code produced by gperf version 3.1 */
+/* Command-line: gperf --output-file=llamafile/is_keyword_make.c llamafile/is_keyword_make.gperf */
+/* Computed positions: -k'1,3-4' */
+
+#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
+/* The character set is not based on ISO-646. */
+#error "gperf generated tables don't work with this execution character set. Please report a bug to <[email protected]>."
+#endif
+
+#line 1 "llamafile/is_keyword_make.gperf"
+
+#include <string.h>
+
+#define TOTAL_KEYWORDS 19
+#define MIN_WORD_LENGTH 2
+#define MAX_WORD_LENGTH 9
+#define MIN_HASH_VALUE 4
+#define MAX_HASH_VALUE 30
+/* maximum key range = 27, duplicates = 0 */
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static unsigned int
+hash (register const char *str, register size_t len)
+{
+ static const unsigned char asso_values[] =
+ {
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 5, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 10, 31, 5,
+ 5, 0, 0, 31, 31, 10, 15, 31, 31, 0,
+ 0, 0, 0, 31, 0, 0, 31, 10, 5, 0,
+ 31, 10, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
+ 31, 31, 31, 31, 31, 31, 31
+ };
+ register unsigned int hval = len;
+
+ switch (hval)
+ {
+ default:
+ hval += asso_values[(unsigned char)str[3]+1];
+ /*FALLTHROUGH*/
+ case 3:
+ hval += asso_values[(unsigned char)str[2]];
+ /*FALLTHROUGH*/
+ case 2:
+ case 1:
+ hval += asso_values[(unsigned char)str[0]];
+ break;
+ }
+ return hval;
+}
+
+const char *
+is_keyword_make (register const char *str, register size_t len)
+{
+ struct stringpool_t
+ {
+ char stringpool_str4[sizeof("else")];
+ char stringpool_str6[sizeof("export")];
+ char stringpool_str8[sizeof("override")];
+ char stringpool_str10[sizeof("endef")];
+ char stringpool_str12[sizeof("if")];
+ char stringpool_str13[sizeof("sinclude")];
+ char stringpool_str14[sizeof("ifeq")];
+ char stringpool_str15[sizeof("ifneq")];
+ char stringpool_str16[sizeof("ifndef")];
+ char stringpool_str17[sizeof("private")];
+ char stringpool_str18[sizeof("-include")];
+ char stringpool_str20[sizeof("ifdef")];
+ char stringpool_str22[sizeof("include")];
+ char stringpool_str23[sizeof("undefine")];
+ char stringpool_str24[sizeof("-sinclude")];
+ char stringpool_str25[sizeof("endif")];
+ char stringpool_str26[sizeof("define")];
+ char stringpool_str28[sizeof("unexport")];
+ char stringpool_str30[sizeof("vpath")];
+ };
+ static const struct stringpool_t stringpool_contents =
+ {
+ "else",
+ "export",
+ "override",
+ "endef",
+ "if",
+ "sinclude",
+ "ifeq",
+ "ifneq",
+ "ifndef",
+ "private",
+ "-include",
+ "ifdef",
+ "include",
+ "undefine",
+ "-sinclude",
+ "endif",
+ "define",
+ "unexport",
+ "vpath"
+ };
+ #define stringpool ((const char *) &stringpool_contents)
+ static const int wordlist[] =
+ {
+ -1, -1, -1, -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str4,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str6,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str8,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str10,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str12,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str13,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str14,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str15,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str16,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str17,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str18,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str20,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str22,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str23,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str24,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str25,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str26,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str28,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str30
+ };
+
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+ {
+ register unsigned int key = hash (str, len);
+
+ if (key <= MAX_HASH_VALUE)
+ {
+ register int o = wordlist[key];
+ if (o >= 0)
+ {
+ register const char *s = o + stringpool;
+
+ if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
+ return s;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/llamafile/is_keyword_make.gperf b/llamafile/is_keyword_make.gperf
new file mode 100644
index 00000000..f4d7e842
--- /dev/null
+++ b/llamafile/is_keyword_make.gperf
@@ -0,0 +1,28 @@
+%{
+#include <string.h>
+%}
+%pic
+%compare-strncmp
+%language=ANSI-C
+%readonly-tables
+%define lookup-function-name is_keyword_make
+%%
+-include
+-sinclude
+define
+else
+endef
+endif
+export
+if
+ifdef
+ifeq
+ifndef
+ifneq
+include
+override
+private
+sinclude
+undefine
+unexport
+vpath
diff --git a/llamafile/is_keyword_make_builtin.c b/llamafile/is_keyword_make_builtin.c
new file mode 100644
index 00000000..37f87334
--- /dev/null
+++ b/llamafile/is_keyword_make_builtin.c
@@ -0,0 +1,240 @@
+/* ANSI-C code produced by gperf version 3.1 */
+/* Command-line: gperf --output-file=llamafile/is_keyword_make_builtin.c llamafile/is_keyword_make_builtin.gperf */
+/* Computed positions: -k'2,4' */
+
+#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
+/* The character set is not based on ISO-646. */
+#error "gperf generated tables don't work with this execution character set. Please report a bug to <[email protected]>."
+#endif
+
+#line 1 "llamafile/is_keyword_make_builtin.gperf"
+
+#include <string.h>
+
+#define TOTAL_KEYWORDS 35
+#define MIN_WORD_LENGTH 2
+#define MAX_WORD_LENGTH 10
+#define MIN_HASH_VALUE 2
+#define MAX_HASH_VALUE 46
+/* maximum key range = 45, duplicates = 0 */
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static unsigned int
+hash (register const char *str, register size_t len)
+{
+ static const unsigned char asso_values[] =
+ {
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 5, 15, 47,
+ 10, 0, 15, 0, 5, 5, 47, 47, 30, 47,
+ 0, 0, 0, 47, 0, 15, 20, 0, 10, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
+ 47, 47, 47, 47, 47, 47
+ };
+ register unsigned int hval = len;
+
+ switch (hval)
+ {
+ default:
+ hval += asso_values[(unsigned char)str[3]];
+ /*FALLTHROUGH*/
+ case 3:
+ case 2:
+ hval += asso_values[(unsigned char)str[1]];
+ break;
+ }
+ return hval;
+}
+
+const char *
+is_keyword_make_builtin (register const char *str, register size_t len)
+{
+ struct stringpool_t
+ {
+ char stringpool_str2[sizeof("or")];
+ char stringpool_str3[sizeof("and")];
+ char stringpool_str4[sizeof("join")];
+ char stringpool_str5[sizeof("error")];
+ char stringpool_str6[sizeof("origin")];
+ char stringpool_str7[sizeof("foreach")];
+ char stringpool_str8[sizeof("dir")];
+ char stringpool_str9[sizeof("file")];
+ char stringpool_str10[sizeof("value")];
+ char stringpool_str12[sizeof("warning")];
+ char stringpool_str13[sizeof("basename")];
+ char stringpool_str14[sizeof("word")];
+ char stringpool_str15[sizeof("words")];
+ char stringpool_str16[sizeof("notdir")];
+ char stringpool_str17[sizeof("if")];
+ char stringpool_str18[sizeof("wordlist")];
+ char stringpool_str19[sizeof("addprefix")];
+ char stringpool_str20[sizeof("subst")];
+ char stringpool_str21[sizeof("suffix")];
+ char stringpool_str22[sizeof("abspath")];
+ char stringpool_str23[sizeof("wildcard")];
+ char stringpool_str24[sizeof("sort")];
+ char stringpool_str25[sizeof("findstring")];
+ char stringpool_str28[sizeof("patsubst")];
+ char stringpool_str29[sizeof("firstword")];
+ char stringpool_str30[sizeof("strip")];
+ char stringpool_str31[sizeof("filter")];
+ char stringpool_str33[sizeof("lastword")];
+ char stringpool_str34[sizeof("addsuffix")];
+ char stringpool_str35[sizeof("filter-out")];
+ char stringpool_str38[sizeof("realpath")];
+ char stringpool_str39[sizeof("call")];
+ char stringpool_str40[sizeof("shell")];
+ char stringpool_str44[sizeof("eval")];
+ char stringpool_str46[sizeof("flavor")];
+ };
+ static const struct stringpool_t stringpool_contents =
+ {
+ "or",
+ "and",
+ "join",
+ "error",
+ "origin",
+ "foreach",
+ "dir",
+ "file",
+ "value",
+ "warning",
+ "basename",
+ "word",
+ "words",
+ "notdir",
+ "if",
+ "wordlist",
+ "addprefix",
+ "subst",
+ "suffix",
+ "abspath",
+ "wildcard",
+ "sort",
+ "findstring",
+ "patsubst",
+ "firstword",
+ "strip",
+ "filter",
+ "lastword",
+ "addsuffix",
+ "filter-out",
+ "realpath",
+ "call",
+ "shell",
+ "eval",
+ "flavor"
+ };
+ #define stringpool ((const char *) &stringpool_contents)
+ static const int wordlist[] =
+ {
+ -1, -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str2,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str3,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str4,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str5,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str6,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str7,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str8,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str9,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str10,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str12,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str13,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str14,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str15,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str16,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str17,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str18,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str19,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str20,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str21,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str22,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str23,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str24,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str25,
+ -1, -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str28,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str29,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str30,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str31,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str33,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str34,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str35,
+ -1, -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str38,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str39,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str40,
+ -1, -1, -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str44,
+ -1,
+ (int)(size_t)&((struct stringpool_t *)0)->stringpool_str46
+ };
+
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+ {
+ register unsigned int key = hash (str, len);
+
+ if (key <= MAX_HASH_VALUE)
+ {
+ register int o = wordlist[key];
+ if (o >= 0)
+ {
+ register const char *s = o + stringpool;
+
+ if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
+ return s;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/llamafile/is_keyword_make_builtin.gperf b/llamafile/is_keyword_make_builtin.gperf
new file mode 100644
index 00000000..e1bc07d3
--- /dev/null
+++ b/llamafile/is_keyword_make_builtin.gperf
@@ -0,0 +1,44 @@
+%{
+#include <string.h>
+%}
+%pic
+%compare-strncmp
+%language=ANSI-C
+%readonly-tables
+%define lookup-function-name is_keyword_make_builtin
+%%
+abspath
+addprefix
+addsuffix
+and
+basename
+call
+dir
+error
+eval
+file
+filter
+filter-out
+findstring
+firstword
+flavor
+foreach
+if
+join
+lastword
+notdir
+or
+origin
+patsubst
+realpath
+shell
+sort
+strip
+subst
+suffix
+value
+warning
+wildcard
+word
+wordlist
+words