summaryrefslogtreecommitdiffstats
path: root/eshtrans
diff options
context:
space:
mode:
Diffstat (limited to 'eshtrans')
-rw-r--r--eshtrans/backend/codegen.esh26
-rw-r--r--eshtrans/frontend/lexer.esh22
-rw-r--r--eshtrans/frontend/parser.esh7
-rw-r--r--eshtrans/tokens.esh4
4 files changed, 58 insertions, 1 deletions
diff --git a/eshtrans/backend/codegen.esh b/eshtrans/backend/codegen.esh
index 8fd1088..2637d51 100644
--- a/eshtrans/backend/codegen.esh
+++ b/eshtrans/backend/codegen.esh
@@ -55,6 +55,9 @@ codegen_sub()
local fname=
local static=
local static_fname=
+ local type=
+ local params=
+ local types=
local t=
print_spc=false
@@ -63,6 +66,9 @@ codegen_sub()
fname=''
static=false
static_fname=false
+ type=false
+ params=0
+ types=''
IFS="${RS}"
for t in ${array}; do
@@ -94,11 +100,22 @@ codegen_sub()
;;
T_FNAME)
fname="${t}"
+ params=0
+ types=''
;;
T_STATIC)
static=true
continue
;;
+ T_TYPE)
+ type=true
+ params=$((${params} + 1))
+ types="${types}${t#*${US}}:"
+ continue
+ ;;
+ T_COMMA)
+ continue
+ ;;
esac
if ${pragma}; then
pragma=false
@@ -128,6 +145,10 @@ codegen_sub()
toktext "${fname}"
;;
esac
+ elif ${type}; then
+ type=false
+ types="${types}${t#*${US}} "
+ continue
fi
# Function start/end tokens
@@ -139,6 +160,11 @@ codegen_sub()
else
printf ':;'
fi
+ if [ ${params} -gt 0 ]; then
+ printf ' __check_args %s %d %s %s;' \
+ "${fname#*${US}}" ${params} \
+ "'${types% }'" '"${@}"'
+ fi
;;
T_FN_END)
if ! ${pragma_nostack}; then
diff --git a/eshtrans/frontend/lexer.esh b/eshtrans/frontend/lexer.esh
index 6eb168a..275e928 100644
--- a/eshtrans/frontend/lexer.esh
+++ b/eshtrans/frontend/lexer.esh
@@ -221,6 +221,11 @@ next()
next_io
return
;;
+ ',')
+ lgetc
+ tok=T_COMMA
+ return
+ ;;
*)
next_word
return
@@ -438,7 +443,7 @@ scan_word()
lines=$((${lines} + 1))
word="${word}${c}"
;;
- ' '|"${HT}"|'&'|'|'|';'|'('|')'|'<'|'>')
+ ' '|"${HT}"|'&'|'|'|';'|'('|')'|'<'|'>'|',')
if ! ${in_param} && ! ${quoted}; then
break
fi
@@ -949,6 +954,21 @@ accept()
tok="${t}"
fi
;;
+ T_TYPE)
+ # Types are recognized as literal T_WORDs.
+ if ! [ "x${tok%%${US}*}" = 'xT_WORD' ]; then
+ return 1
+ fi
+ # Validate type.
+ case "${tok#*${US}}" in
+ 'bool'|'int'|'string')
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+ tok="T_TYPE${US}${tok#T_WORD${US}}"
+ ;;
T_NAME)
# Names 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 7966fb6..2607d96 100644
--- a/eshtrans/frontend/parser.esh
+++ b/eshtrans/frontend/parser.esh
@@ -421,6 +421,13 @@ 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
+ expect T_NAME
+ done
+ fi
expect T_RPAREN
if linebreak && function_body; then
#ptrace_pass simple_command
diff --git a/eshtrans/tokens.esh b/eshtrans/tokens.esh
index d8e57ca..a2c6b37 100644
--- a/eshtrans/tokens.esh
+++ b/eshtrans/tokens.esh
@@ -47,6 +47,7 @@ tokname()
T_PIPE) n='"|"';;
T_LPAREN) n='"("';;
T_RPAREN) n='")"';;
+ T_COMMA) n='","';;
# Reserved words
T_IF) n='"if"';;
T_THEN) n='"then"';;
@@ -69,6 +70,7 @@ tokname()
T_LOCAL) n='"local"';;
T_RETURN) n='"return"';;
# Special symbols
+ T_TYPE) n='parameter type';;
T_NAME) n='parameter name';;
T_FNAME) n='function name';;
T_CMDNAME) n='command name';;
@@ -114,6 +116,7 @@ toktext()
T_PIPE) n='|';;
T_LPAREN) n='(';;
T_RPAREN) n=')';;
+ T_COMMA) n=',';;
# Reserved words
T_IF) n='if';;
T_THEN) n='then';;
@@ -136,6 +139,7 @@ toktext()
T_LOCAL) n='local';;
T_RETURN) n='return';;
# Special symbols
+ T_TYPE) n="${t#*${US}}";;
T_NAME) n="${t#*${US}}";;
T_FNAME) n="${t#*${US}}";;
T_CMDNAME) n="${t#*${US}}";;