[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[COMMITTED] libpoke: add pk_keyword_p service
From: |
Jose E. Marchesi |
Subject: |
[COMMITTED] libpoke: add pk_keyword_p service |
Date: |
Wed, 26 Apr 2023 22:44:53 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
2023-04-26 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/libpoke.h: Prototype for pk_keyword_p.
* libpoke/libpoke.c (pk_keyword_p): New function.
* libpoke/Makefile.am: Generate $(srcdir)/pkl-keywords.def.
* testsuite/poke.libpoke/api.c (test_pk_keyword_p): New test.
* .gitignore: Add /libpoke/pkl-keywords.def.
---
.gitignore | 1 +
ChangeLog | 8 ++++++++
libpoke/Makefile.am | 14 ++++++++++++++
libpoke/libpoke.c | 21 +++++++++++++++++++++
libpoke/libpoke.h | 6 ++++++
libpoke/pkl-lex.l | 2 ++
testsuite/poke.libpoke/api.c | 8 ++++++++
7 files changed, 60 insertions(+)
diff --git a/.gitignore b/.gitignore
index cdbcec19..e9ed0a9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -73,6 +73,7 @@ config.h.in
/libpoke/pvm-vm.h
/libpoke/pvm-vm1.c
/libpoke/pvm-vm2.c
+/libpoke/pkl-keywords.def
/poke/pk-map-lex.c
/poke/pk-map-lex.h
/poke/pk-map-tab.c
diff --git a/ChangeLog b/ChangeLog
index 61f2ad81..d2ff9a51 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-04-26 Jose E. Marchesi <jemarch@gnu.org>
+
+ * libpoke/libpoke.h: Prototype for pk_keyword_p.
+ * libpoke/libpoke.c (pk_keyword_p): New function.
+ * libpoke/Makefile.am: Generate $(srcdir)/pkl-keywords.def.
+ * testsuite/poke.libpoke/api.c (test_pk_keyword_p): New test.
+ * .gitignore: Add /libpoke/pkl-keywords.def.
+
2023-04-25 Jose E. Marchesi <jemarch@gnu.org>
* testsuite/poke.std/std-test.pk: Do not use "standard" types.
diff --git a/libpoke/Makefile.am b/libpoke/Makefile.am
index 493e7abd..f7a66113 100644
--- a/libpoke/Makefile.am
+++ b/libpoke/Makefile.am
@@ -93,6 +93,20 @@ EXTRA_DIST = ras
BUILT_SOURCES = pkl-gen.pkc pkl-gen-builtins.pkc pkl-gen-attrs.pkc pkl-asm.pkc
+# The pkl-keywords.def file is generated from the contents
+# of the flex input file pkl-lex.l
+
+pkl-keywords.def: $(srcdir)/pkl-lex.l
+ outfile=`basename "$@"`; \
+ $(AWK) \
+'/BEGINNING OF KEYWORDS/,/END OF KEYWORDS/ { if ($$1 != "/*") print
"PKL_DEF_KEYWORD(" $$1 ")"; }' \
+ < $< > $$outfile.tmp \
+ && mv $$outfile.tmp $(srcdir)/$$outfile
+
+EXTRA_DIST += pkl-keywords.def
+MOSTLYCLEANFILES += pkl-keywords.def.tmp
+BUILT_SOURCES += pkl-keywords.def
+
AM_LFLAGS = -d
# The Automake generated .l.c rule is broken: When executed in a VPATH build,
# - The .c file gets generated in the build directory. But since it requires
diff --git a/libpoke/libpoke.c b/libpoke/libpoke.c
index 4849e21e..49e360c6 100644
--- a/libpoke/libpoke.c
+++ b/libpoke/libpoke.c
@@ -1117,3 +1117,24 @@ pk_register_iod (pk_compiler pkc, struct pk_iod_if
*iod_if)
(void) ios_register_foreign_iod (&foreign_iod_if);
return pkc->status;
}
+
+int
+pk_keyword_p (pk_compiler pkc, const char *str)
+{
+ static const char *keywords[] =
+ {
+#define PKL_DEF_KEYWORD(s) s,
+# include "pkl-keywords.def"
+#undef PKL_DEF_KEYWORD
+ NULL,
+ };
+ int i;
+
+ for (i = 0; keywords[i] != NULL; ++i)
+ {
+ if (STREQ (str, keywords[i]))
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
index 7732f96c..680bda82 100644
--- a/libpoke/libpoke.h
+++ b/libpoke/libpoke.h
@@ -1294,4 +1294,10 @@ struct pk_iod_if
int pk_register_iod (pk_compiler pkc, struct pk_iod_if *iod_if)
LIBPOKE_API;
+/* Given a string, determine whether it corresponds to a Poke
+ keyword. */
+
+int pk_keyword_p (pk_compiler pkc, const char *str)
+ LIBPOKE_API;
+
#endif /* ! LIBPOKE_H */
diff --git a/libpoke/pkl-lex.l b/libpoke/pkl-lex.l
index a1e051f6..1830cde0 100644
--- a/libpoke/pkl-lex.l
+++ b/libpoke/pkl-lex.l
@@ -260,6 +260,7 @@ S ::
return STR;
}
+ /* BEGINNING OF KEYWORDS */
"asm" { return ASM; }
"pinned" { return PINNED; }
"struct" { return STRUCT; }
@@ -304,6 +305,7 @@ S ::
"enum" { return ENUM; }
"computed" { return COMPUTED; }
"immutable" { return IMMUTABLE; }
+ /* END OF KEYWORDS */
"uint<" { return UINTCONSTR; }
"int<" { return INTCONSTR; }
diff --git a/testsuite/poke.libpoke/api.c b/testsuite/poke.libpoke/api.c
index 616eba1c..c37dfde8 100644
--- a/testsuite/poke.libpoke/api.c
+++ b/testsuite/poke.libpoke/api.c
@@ -98,6 +98,13 @@ test_pk_compiler_free (pk_compiler pkc)
pk_compiler_free (pkc);
}
+static void
+test_pk_keyword_p (pk_compiler pkc)
+{
+ T ("pk_keyword_p_1", pk_keyword_p (pkc, "if"));
+ T ("pk_keyword_p_2", !pk_keyword_p (pkc, "foo"));
+}
+
int
main ()
{
@@ -106,6 +113,7 @@ main ()
pkc = test_pk_compiler_new ();
test_pk_compiler_free (pkc);
+ test_pk_keyword_p (pkc);
return 0;
}
--
2.30.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [COMMITTED] libpoke: add pk_keyword_p service,
Jose E. Marchesi <=