summaryrefslogtreecommitdiffstats
path: root/eshtrans
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-28 23:51:45 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-28 23:51:45 (EST)
commit8deefba550f1223986961a60bf48a3692466ae66 (patch)
tree73c087afdaab08daa5b6f8db3d907defc7fb37e1 /eshtrans
parent5fe3df1974d7e26d42d2729a60372e2f4c599bcd (diff)
downloadeggshell-8deefba550f1223986961a60bf48a3692466ae66.zip
eggshell-8deefba550f1223986961a60bf48a3692466ae66.tar.gz
eggshell-8deefba550f1223986961a60bf48a3692466ae66.tar.bz2
eshtrans: Support "void" in parameter lists
Diffstat (limited to 'eshtrans')
-rw-r--r--eshtrans/backend/codegen.esh7
-rw-r--r--eshtrans/frontend/lexer.esh15
-rw-r--r--eshtrans/frontend/parser.esh12
-rw-r--r--eshtrans/funcparams.esh6
-rw-r--r--eshtrans/tokens.esh2
5 files changed, 37 insertions, 5 deletions
diff --git a/eshtrans/backend/codegen.esh b/eshtrans/backend/codegen.esh
index 2637d51..b9e2c10 100644
--- a/eshtrans/backend/codegen.esh
+++ b/eshtrans/backend/codegen.esh
@@ -113,6 +113,10 @@ codegen_sub()
types="${types}${t#*${US}}:"
continue
;;
+ T_VOID)
+ params=-1
+ continue
+ ;;
T_COMMA)
continue
;;
@@ -164,6 +168,9 @@ codegen_sub()
printf ' __check_args %s %d %s %s;' \
"${fname#*${US}}" ${params} \
"'${types% }'" '"${@}"'
+ elif [ ${params} -eq -1 ]; then
+ printf ' __check_args %s 0 "" "${@}";' \
+ "${fname#*${US}}"
fi
;;
T_FN_END)
diff --git a/eshtrans/frontend/lexer.esh b/eshtrans/frontend/lexer.esh
index 275e928..a30e7f5 100644
--- a/eshtrans/frontend/lexer.esh
+++ b/eshtrans/frontend/lexer.esh
@@ -954,6 +954,21 @@ accept()
tok="${t}"
fi
;;
+ T_VOID)
+ # Types are recognized as literal T_WORDs.
+ if ! [ "x${tok%%${US}*}" = 'xT_WORD' ]; then
+ return 1
+ fi
+ # Validate type.
+ case "${tok#*${US}}" in
+ 'void')
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+ tok="T_VOID${US}${tok#T_WORD${US}}"
+ ;;
T_TYPE)
# Types are recognized as literal T_WORDs.
if ! [ "x${tok%%${US}*}" = 'xT_WORD' ]; then
diff --git a/eshtrans/frontend/parser.esh b/eshtrans/frontend/parser.esh
index 2607d96..9a63c03 100644
--- a/eshtrans/frontend/parser.esh
+++ b/eshtrans/frontend/parser.esh
@@ -421,12 +421,14 @@ simple_command()
return 0
elif accept T_FNAME; then
if accept T_LPAREN; then
- if accept T_TYPE; then
- expect T_NAME
- while accept T_COMMA; do
- expect T_TYPE
+ if ! accept T_VOID; then
+ if accept T_TYPE; then
expect T_NAME
- done
+ while accept T_COMMA; do
+ expect T_TYPE
+ expect T_NAME
+ done
+ fi
fi
expect T_RPAREN
if linebreak && function_body; then
diff --git a/eshtrans/funcparams.esh b/eshtrans/funcparams.esh
index cfabe61..8630eee 100644
--- a/eshtrans/funcparams.esh
+++ b/eshtrans/funcparams.esh
@@ -10,8 +10,14 @@ greet(bool doprint, int i, string s)
fi
}
+bye(void)
+{
+ printf 'Goodbye, cruel world!'
+}
+
main()
{
greet true 3 'Hello, world!'
+ bye
return 0
}
diff --git a/eshtrans/tokens.esh b/eshtrans/tokens.esh
index a2c6b37..d8584f2 100644
--- a/eshtrans/tokens.esh
+++ b/eshtrans/tokens.esh
@@ -69,6 +69,7 @@ tokname()
T_STATIC) n='"static"';;
T_LOCAL) n='"local"';;
T_RETURN) n='"return"';;
+ T_VOID) n='"void"';;
# Special symbols
T_TYPE) n='parameter type';;
T_NAME) n='parameter name';;
@@ -138,6 +139,7 @@ toktext()
T_STATIC) n='static';;
T_LOCAL) n='local';;
T_RETURN) n='return';;
+ T_VOID) n='void';;
# Special symbols
T_TYPE) n="${t#*${US}}";;
T_NAME) n="${t#*${US}}";;