summaryrefslogtreecommitdiffstats
path: root/eshtrans
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-22 13:36:29 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-22 13:36:29 (EST)
commitd533dc560cf422043069feeb741b6f85579748b6 (patch)
tree5491d01d3ad2f39f6acf0bd87bc637e364706f4b /eshtrans
parente95515664a943d8968c492f242a7d4b0729ea4b5 (diff)
downloadeggshell-d533dc560cf422043069feeb741b6f85579748b6.zip
eggshell-d533dc560cf422043069feeb741b6f85579748b6.tar.gz
eggshell-d533dc560cf422043069feeb741b6f85579748b6.tar.bz2
eshtrans/backend: Add support for static vars and functions
Diffstat (limited to 'eshtrans')
-rw-r--r--eshtrans/backend/codegen.esh63
-rw-r--r--eshtrans/backend/main.esh1
2 files changed, 64 insertions, 0 deletions
diff --git a/eshtrans/backend/codegen.esh b/eshtrans/backend/codegen.esh
index a9c3cef..e257990 100644
--- a/eshtrans/backend/codegen.esh
+++ b/eshtrans/backend/codegen.esh
@@ -19,6 +19,8 @@
# <http://www.gnu.org/licenses/>.
sc=
+tu_id=
+static_fn_n=
sgetc()
{
@@ -26,13 +28,30 @@ sgetc()
sc="${sc%.}"
}
+add_static_fn()
+{
+ local fn="${1}"
+
+ printf '__%s_static_fns="${__%s_static_fns} %s:__%s_fn%d"\n' \
+ "${tu_id}" "${tu_id}" "${fn}" ${static_fn_n}
+ printf '__%s_fn%d' "${tu_id}" ${static_fn_n}
+ static_fn_n=$((${static_fn_n} + 1))
+}
+
codegen_sub()
{
local array="${1}"
shift 1
local ionum=
+ local static=
+ local static_fname=
+ local fname=
ionum=false
+ static=false
+ static_fname=false
+ fname=''
+
IFS="${RS}"
for t in ${array}; do
if ${ionum}; then
@@ -43,7 +62,43 @@ codegen_sub()
esac
ionum=false
fi
+
+ # State machine for static variables and functions
+ case "${t%${US}*}" in
+ T_STATIC)
+ static=true
+ continue
+ ;;
+ esac
+ if ${static}; then
+ static=false
+ case "${t%${US}*}" in
+ T_FNAME)
+ static_fname=true
+ fname="${t}"
+ continue
+ ;;
+ *)
+ toktext T_STATIC
+ printf ' '
+ ;;
+ esac
+ elif ${static_fname}; then
+ static_fname=false
+ case "${t%${US}*}" in
+ T_LPAREN)
+ add_static_fn "${fname#*${US}}"
+ ;;
+ *)
+ toktext T_STATIC
+ printf ' '
+ toktext "${fname}"
+ ;;
+ esac
+ fi
+
toktext "${t}"
+
case "${t%${US}*}" in
T_NEWLINE|T_LPAREN)
# Indenting lines can mess up here-documents.
@@ -119,3 +174,11 @@ sh_set_tu_id()
return 0
}
+
+sh_start_tu()
+{
+ printf '__tu=%s\n' "${tu_id}"
+ printf '__%s_static_vars=\n' "${tu_id}"
+ printf '__%s_static_fns=\n' "${tu_id}"
+ static_fn_n=0
+}
diff --git a/eshtrans/backend/main.esh b/eshtrans/backend/main.esh
index 485e9be..8851053 100644
--- a/eshtrans/backend/main.esh
+++ b/eshtrans/backend/main.esh
@@ -24,6 +24,7 @@ sh_codegen()
shift 1
sh_set_tu_id "${toks}"
+ sh_start_tu
if printf '%s' "${toks}" | sh_parse_stack; then
return 0
else