aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Lockwood2021-07-08 19:38:59 -0600
committerAlexis Lockwood2021-07-08 19:38:59 -0600
commit6952ba1cc69282636c3b5f372aa62d2fc6375163 (patch)
treede440bd8e3835d8fe4c831e7dfbd82904905bad5
parentdd8628859c8c1d82a021efbb705cae0a6570eb12 (diff)
Make keyword functions accessible
-rwxr-xr-xgen_kws.py14
-rw-r--r--lib/ls.c1
-rw-r--r--lib/ls_internal.c1
-rw-r--r--lib/ls_internal.h7
-rw-r--r--lib/ls_kw_impl.c5
-rw-r--r--lib/ls_kw_impl_GOSUB_RETURN.c1
-rw-r--r--lib/ls_kw_impl_GOTO.c1
-rw-r--r--lib/ls_kw_impl_LOOPS.c1
-rw-r--r--lib/ls_kw_impl_PRINT.c1
-rw-r--r--lib/ls_kws.c52
-rw-r--r--lib/ls_kws.h54
-rw-r--r--lib/ls_types.h17
12 files changed, 80 insertions, 75 deletions
diff --git a/gen_kws.py b/gen_kws.py
index b6d44db..c607eaf 100755
--- a/gen_kws.py
+++ b/gen_kws.py
@@ -9,6 +9,7 @@ Usage: gen_kws.py source
gen_kws.py show
"""
+import time
import sys
OFFSET = 0x80
@@ -148,10 +149,11 @@ if TARGET == "show":
print()
sys.exit()
-print("// This code was auto-generated")
+print("// This code was generated by gen_kws.py at",
+ time.strftime("%a %d %b %Y %I:%M:%S %p %Z")) # like date(1)
if TARGET == "source":
- print('#include "ls_kws.h"')
+ #print('#include "ls_kws.h"')
print('#include "ls_internal.h"')
print()
@@ -167,8 +169,6 @@ if TARGET == "source":
print()
for i in KEYWORDS:
- if not i.noexec:
- print(f'LS_KW_FUN({i.name});')
print(f'static const LS_PROGMEM char _kw_name_{i.name}[] = '
f'"{i.name}";')
@@ -182,8 +182,14 @@ if TARGET == "source":
sys.exit()
if TARGET == "header":
+ print('#ifndef LS_TYPES_H')
+ print('# error "ls_kws.h should not be included directly! Include ls_types.h instead."')
+ print('#endif')
print('#ifndef LS_KWS_H')
print('#define LS_KWS_H')
+ for i in KEYWORDS:
+ if not i.noexec:
+ print(f'LS_KW_FUN({i.name});')
print('typedef enum {')
top = max(i.index for i in KEYWORDS)
for i in range(OFFSET, top + 1):
diff --git a/lib/ls.c b/lib/ls.c
index ab704ce..e0a1be4 100644
--- a/lib/ls.c
+++ b/lib/ls.c
@@ -7,7 +7,6 @@
#include "ls.h"
// Supporting modules
-#include "ls_kws.h"
#include "ls_expr.h"
#include "ls_internal.h"
diff --git a/lib/ls_internal.c b/lib/ls_internal.c
index c4fa400..1c20820 100644
--- a/lib/ls_internal.c
+++ b/lib/ls_internal.c
@@ -7,7 +7,6 @@
#include "ls_internal.h"
// Supporting modules
-#include "ls_kws.h"
#include "ls_expr.h"
#include "ls_lex.h"
diff --git a/lib/ls_internal.h b/lib/ls_internal.h
index 540e128..831d1d2 100644
--- a/lib/ls_internal.h
+++ b/lib/ls_internal.h
@@ -9,7 +9,6 @@
// Supporting modules
#include "ls.h"
#include "ls_types.h"
-#include "ls_kws.h"
// Standard headers
#include <stdbool.h>
@@ -34,12 +33,6 @@
/// Get the original value from a littlescript_kw_hashmap[] sentinel.
#define LS_HASHMAP_ENTRY_UNPACK_SENTINEL(x) ((x) & 0x7Fu)
-/// Define a keyword function. This is used by the code generated by gen_kws.py
-#define LS_KW_FUN(n) \
- void ls_kw_fun_ ## n ( \
- ls_t * self \
- )
-
/// Initial hash value. Set a uint8_t to this and then use
/// LS_KW_HASH() to update with each character
#define LS_KW_HASH_DEFAULT 0
diff --git a/lib/ls_kw_impl.c b/lib/ls_kw_impl.c
index 1fbf671..ed54939 100644
--- a/lib/ls_kw_impl.c
+++ b/lib/ls_kw_impl.c
@@ -5,7 +5,6 @@
// Supporting modules
#include "ls_internal.h"
-#include "ls_kws.h"
#include "ls_expr.h"
#include "ls_lex.h"
#include "ls_goto.h"
@@ -24,10 +23,6 @@
/// Call for keywords without implementations.
static void _no_impl(ls_t * self);
-// TODO just make these public
-void ls_kw_fun_GOTO(ls_t * self);
-void ls_kw_fun_GOSUB(ls_t * self);
-
// --- PUBLIC VARIABLES --------------------------------------------------------
// --- PRIVATE VARIABLES -------------------------------------------------------
// --- PUBLIC FUNCTIONS --------------------------------------------------------
diff --git a/lib/ls_kw_impl_GOSUB_RETURN.c b/lib/ls_kw_impl_GOSUB_RETURN.c
index 78a0901..90bae09 100644
--- a/lib/ls_kw_impl_GOSUB_RETURN.c
+++ b/lib/ls_kw_impl_GOSUB_RETURN.c
@@ -5,7 +5,6 @@
// Supporting modules
#include "ls_internal.h"
-#include "ls_kws.h"
#include "ls_expr.h"
#include "ls_lex.h"
#include "ls_goto.h"
diff --git a/lib/ls_kw_impl_GOTO.c b/lib/ls_kw_impl_GOTO.c
index a3b2198..badbb8b 100644
--- a/lib/ls_kw_impl_GOTO.c
+++ b/lib/ls_kw_impl_GOTO.c
@@ -6,7 +6,6 @@
// Supporting modules
#include "ls_internal.h"
#include "ls_expr.h"
-#include "ls_kws.h"
#include "ls_lex.h"
#include "ls_goto.h"
diff --git a/lib/ls_kw_impl_LOOPS.c b/lib/ls_kw_impl_LOOPS.c
index b23c7d6..b42531f 100644
--- a/lib/ls_kw_impl_LOOPS.c
+++ b/lib/ls_kw_impl_LOOPS.c
@@ -7,7 +7,6 @@
// Supporting modules
#include "ls_internal.h"
-#include "ls_kws.h"
#include "ls_expr.h"
#include "ls_lex.h"
diff --git a/lib/ls_kw_impl_PRINT.c b/lib/ls_kw_impl_PRINT.c
index e336f4c..739f93b 100644
--- a/lib/ls_kw_impl_PRINT.c
+++ b/lib/ls_kw_impl_PRINT.c
@@ -6,7 +6,6 @@
// Supporting modules
#include "ls_internal.h"
#include "ls_expr.h"
-#include "ls_kws.h"
#include "ls_lex.h"
// Standard headers
diff --git a/lib/ls_kws.c b/lib/ls_kws.c
index a68b560..8f60061 100644
--- a/lib/ls_kws.c
+++ b/lib/ls_kws.c
@@ -1,5 +1,4 @@
-// This code was auto-generated
-#include "ls_kws.h"
+// This code was generated by gen_kws.py at Thu 08 Jul 2021 07:38:18 PM MDT
#include "ls_internal.h"
const LS_PROGMEM uint8_t ls_kw_hashmap_indices[] = {
@@ -104,111 +103,62 @@ const LS_PROGMEM uint8_t ls_kw_hashmap[] = {
static const LS_PROGMEM char _kw_name_ABS[] = "ABS";
static const LS_PROGMEM char _kw_name_AND[] = "AND";
static const LS_PROGMEM char _kw_name_AS[] = "AS";
-LS_KW_FUN(ASC);
static const LS_PROGMEM char _kw_name_ASC[] = "ASC";
static const LS_PROGMEM char _kw_name_AT[] = "AT";
-LS_KW_FUN(ATN);
static const LS_PROGMEM char _kw_name_ATN[] = "ATN";
-LS_KW_FUN(CALL);
static const LS_PROGMEM char _kw_name_CALL[] = "CALL";
-LS_KW_FUN(CAT);
static const LS_PROGMEM char _kw_name_CAT[] = "CAT";
-LS_KW_FUN(CHR);
static const LS_PROGMEM char _kw_name_CHR[] = "CHR";
-LS_KW_FUN(CLOSE);
static const LS_PROGMEM char _kw_name_CLOSE[] = "CLOSE";
-LS_KW_FUN(COS);
static const LS_PROGMEM char _kw_name_COS[] = "COS";
-LS_KW_FUN(COUNT);
static const LS_PROGMEM char _kw_name_COUNT[] = "COUNT";
-LS_KW_FUN(DATA);
static const LS_PROGMEM char _kw_name_DATA[] = "DATA";
-LS_KW_FUN(DEC);
static const LS_PROGMEM char _kw_name_DEC[] = "DEC";
-LS_KW_FUN(DEF);
static const LS_PROGMEM char _kw_name_DEF[] = "DEF";
-LS_KW_FUN(ELSE);
static const LS_PROGMEM char _kw_name_ELSE[] = "ELSE";
-LS_KW_FUN(END);
static const LS_PROGMEM char _kw_name_END[] = "END";
static const LS_PROGMEM char _kw_name_EQV[] = "EQV";
-LS_KW_FUN(ERASE);
static const LS_PROGMEM char _kw_name_ERASE[] = "ERASE";
-LS_KW_FUN(ERROR);
static const LS_PROGMEM char _kw_name_ERROR[] = "ERROR";
-LS_KW_FUN(FN);
static const LS_PROGMEM char _kw_name_FN[] = "FN";
-LS_KW_FUN(FOR);
static const LS_PROGMEM char _kw_name_FOR[] = "FOR";
-LS_KW_FUN(GOSUB);
static const LS_PROGMEM char _kw_name_GOSUB[] = "GOSUB";
-LS_KW_FUN(GOTO);
static const LS_PROGMEM char _kw_name_GOTO[] = "GOTO";
-LS_KW_FUN(HEX);
static const LS_PROGMEM char _kw_name_HEX[] = "HEX";
-LS_KW_FUN(IF);
static const LS_PROGMEM char _kw_name_IF[] = "IF";
static const LS_PROGMEM char _kw_name_IMP[] = "IMP";
-LS_KW_FUN(INPUT);
static const LS_PROGMEM char _kw_name_INPUT[] = "INPUT";
-LS_KW_FUN(LEFT);
static const LS_PROGMEM char _kw_name_LEFT[] = "LEFT";
-LS_KW_FUN(LET);
static const LS_PROGMEM char _kw_name_LET[] = "LET";
-LS_KW_FUN(LOG);
static const LS_PROGMEM char _kw_name_LOG[] = "LOG";
-LS_KW_FUN(MID);
static const LS_PROGMEM char _kw_name_MID[] = "MID";
-LS_KW_FUN(NEXT);
static const LS_PROGMEM char _kw_name_NEXT[] = "NEXT";
static const LS_PROGMEM char _kw_name_NOT[] = "NOT";
-LS_KW_FUN(OCT);
static const LS_PROGMEM char _kw_name_OCT[] = "OCT";
-LS_KW_FUN(ON);
static const LS_PROGMEM char _kw_name_ON[] = "ON";
static const LS_PROGMEM char _kw_name_OR[] = "OR";
-LS_KW_FUN(OPEN);
static const LS_PROGMEM char _kw_name_OPEN[] = "OPEN";
-LS_KW_FUN(PACK);
static const LS_PROGMEM char _kw_name_PACK[] = "PACK";
-LS_KW_FUN(PRINT);
static const LS_PROGMEM char _kw_name_PRINT[] = "PRINT";
-LS_KW_FUN(RANDOMIZE);
static const LS_PROGMEM char _kw_name_RANDOMIZE[] = "RANDOMIZE";
-LS_KW_FUN(READ);
static const LS_PROGMEM char _kw_name_READ[] = "READ";
-LS_KW_FUN(REM);
static const LS_PROGMEM char _kw_name_REM[] = "REM";
-LS_KW_FUN(RESTORE);
static const LS_PROGMEM char _kw_name_RESTORE[] = "RESTORE";
-LS_KW_FUN(RETURN);
static const LS_PROGMEM char _kw_name_RETURN[] = "RETURN";
-LS_KW_FUN(RIGHT);
static const LS_PROGMEM char _kw_name_RIGHT[] = "RIGHT";
-LS_KW_FUN(RND);
static const LS_PROGMEM char _kw_name_RND[] = "RND";
-LS_KW_FUN(SIN);
static const LS_PROGMEM char _kw_name_SIN[] = "SIN";
-LS_KW_FUN(SQR);
static const LS_PROGMEM char _kw_name_SQR[] = "SQR";
-LS_KW_FUN(STEP);
static const LS_PROGMEM char _kw_name_STEP[] = "STEP";
-LS_KW_FUN(SWAP);
static const LS_PROGMEM char _kw_name_SWAP[] = "SWAP";
-LS_KW_FUN(TAN);
static const LS_PROGMEM char _kw_name_TAN[] = "TAN";
static const LS_PROGMEM char _kw_name_THEN[] = "THEN";
static const LS_PROGMEM char _kw_name_TO[] = "TO";
-LS_KW_FUN(UNPACK);
static const LS_PROGMEM char _kw_name_UNPACK[] = "UNPACK";
static const LS_PROGMEM char _kw_name_UNTIL[] = "UNTIL";
-LS_KW_FUN(VAL);
static const LS_PROGMEM char _kw_name_VAL[] = "VAL";
-LS_KW_FUN(WEND);
static const LS_PROGMEM char _kw_name_WEND[] = "WEND";
-LS_KW_FUN(WHILE);
static const LS_PROGMEM char _kw_name_WHILE[] = "WHILE";
-LS_KW_FUN(WRITE);
static const LS_PROGMEM char _kw_name_WRITE[] = "WRITE";
static const LS_PROGMEM char _kw_name_XOR[] = "XOR";
diff --git a/lib/ls_kws.h b/lib/ls_kws.h
index f224ee0..6f2487b 100644
--- a/lib/ls_kws.h
+++ b/lib/ls_kws.h
@@ -1,6 +1,58 @@
-// This code was auto-generated
+// This code was generated by gen_kws.py at Thu 08 Jul 2021 07:38:18 PM MDT
+#ifndef LS_TYPES_H
+# error "ls_kws.h should not be included directly! Include ls_types.h instead."
+#endif
#ifndef LS_KWS_H
#define LS_KWS_H
+LS_KW_FUN(ASC);
+LS_KW_FUN(ATN);
+LS_KW_FUN(CALL);
+LS_KW_FUN(CAT);
+LS_KW_FUN(CHR);
+LS_KW_FUN(CLOSE);
+LS_KW_FUN(COS);
+LS_KW_FUN(COUNT);
+LS_KW_FUN(DATA);
+LS_KW_FUN(DEC);
+LS_KW_FUN(DEF);
+LS_KW_FUN(ELSE);
+LS_KW_FUN(END);
+LS_KW_FUN(ERASE);
+LS_KW_FUN(ERROR);
+LS_KW_FUN(FN);
+LS_KW_FUN(FOR);
+LS_KW_FUN(GOSUB);
+LS_KW_FUN(GOTO);
+LS_KW_FUN(HEX);
+LS_KW_FUN(IF);
+LS_KW_FUN(INPUT);
+LS_KW_FUN(LEFT);
+LS_KW_FUN(LET);
+LS_KW_FUN(LOG);
+LS_KW_FUN(MID);
+LS_KW_FUN(NEXT);
+LS_KW_FUN(OCT);
+LS_KW_FUN(ON);
+LS_KW_FUN(OPEN);
+LS_KW_FUN(PACK);
+LS_KW_FUN(PRINT);
+LS_KW_FUN(RANDOMIZE);
+LS_KW_FUN(READ);
+LS_KW_FUN(REM);
+LS_KW_FUN(RESTORE);
+LS_KW_FUN(RETURN);
+LS_KW_FUN(RIGHT);
+LS_KW_FUN(RND);
+LS_KW_FUN(SIN);
+LS_KW_FUN(SQR);
+LS_KW_FUN(STEP);
+LS_KW_FUN(SWAP);
+LS_KW_FUN(TAN);
+LS_KW_FUN(UNPACK);
+LS_KW_FUN(VAL);
+LS_KW_FUN(WEND);
+LS_KW_FUN(WHILE);
+LS_KW_FUN(WRITE);
typedef enum {
LS_KW_ABS = 0x80,
LS_KW_AND = 0x81,
diff --git a/lib/ls_types.h b/lib/ls_types.h
index f7856fc..7b8d218 100644
--- a/lib/ls_types.h
+++ b/lib/ls_types.h
@@ -12,7 +12,9 @@
// --- DEPENDENCIES ------------------------------------------------------------
// Supporting modules
-#include "ls_kws.h"
+// NOTE that ls_kws.h is included at the BOTTOM of this file. This is a slight
+// hack to avoid having to define some types in it that gen_kws.py would have
+// to know about.
// Standard headers
#include <stdbool.h>
@@ -61,11 +63,21 @@
/// Check if a token represents a keyword
#define LS_TOK_KEYWORD(tok) ((tok) >= (ls_token_ty_t) LS_KW_OFFSET)
+/// Define a keyword function. This is used by the code generated by gen_kws.py
+#define LS_KW_FUN(n) \
+ void ls_kw_fun_ ## n ( \
+ struct ls_s * self \
+ )
+
+
// --- ACCESSORY DEFINITIONS ---------------------------------------------------
// Forward declaration of the main Value type.
struct ls_value_s;
+// Forward declaration of ls_t/struct ls_s.
+struct ls_s;
+
/// Basic integer type. This is used for integers in scripts.
typedef int32_t ls_int_t;
@@ -376,4 +388,7 @@ typedef uint8_t ls_token_t;
// --- PUBLIC VARIABLES --------------------------------------------------------
// --- PUBLIC FUNCTIONS --------------------------------------------------------
+// --- UGLY DEPENDENCY HACKS, SEE ABOVE ----------------------------------------
+#include "ls_kws.h"
+
#endif // !defined(LS_TYPES_H)