]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Merge branch 'master' into cooking
authorWolfgang Bumiller <blub@speed.at>
Fri, 25 Jan 2013 15:03:38 +0000 (16:03 +0100)
committerWolfgang Bumiller <blub@speed.at>
Fri, 25 Jan 2013 15:03:38 +0000 (16:03 +0100)
15 files changed:
CHANGES
Makefile
ast.c
ast.h
distro/deb/Makefile [new file with mode: 0644]
distro/deb/control [new file with mode: 0644]
doc/gmqcc.1
exec.c
gmqcc.h
ir.c
parser.c
tests/parens.qc [new file with mode: 0644]
tests/parens.tmpl [new file with mode: 0644]
tests/varargs.qc
tests/varargs.tmpl

diff --git a/CHANGES b/CHANGES
index e147a0c8bc7d0ba59a29de4634a9c40e76177640..7a0013b82223057a3e28e091d0f8a25c4ab8ca1f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -25,6 +25,10 @@ Release v0.2.4
         - Various optimizations and progs-size reductions.
         - A new spell-checking algorithm tries to hint you at existing
           variables on error.
+        - Some problems with VM related vector-instructions issues
+          have been solved in both DP and our own executor. A new
+          compatbility option (enabled by default) has been added for
+          now: -flegacy-vector-maths
     * qcvm:
         - Improved commandline argument handling.
         - More builtins: sqrt(), normalize()
index 33b77c9d9fe564193a0c5c83c1237d1ee4b844a9..dd9c1f0adaff5bd3f0062f9fe657e3026d40b5a9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -179,8 +179,8 @@ install-qcvm: $(QCVM)
        install    -m755  $(QCVM)      $(DESTDIR)$(BINDIR)/qcvm
 install-doc:
        install -d -m755               $(DESTDIR)$(MANDIR)/man1
-       install    -m755  doc/gmqcc.1  $(DESTDIR)$(MANDIR)/man1/
-       install    -m755  doc/qcvm.1   $(DESTDIR)$(MANDIR)/man1/
+       install    -m644  doc/gmqcc.1  $(DESTDIR)$(MANDIR)/man1/
+       install    -m644  doc/qcvm.1   $(DESTDIR)$(MANDIR)/man1/
 
 # DO NOT DELETE
 
diff --git a/ast.c b/ast.c
index 5a553cfffbf3fe366084b9ba15e48d719853c03b..108489ff24ad51f563d1d854f4739e6a7adebcfe 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -348,7 +348,7 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
     self->getter = NULL;
     self->desc   = NULL;
 
-    self->argcounter = NULL;
+    self->argcounter  = NULL;
 
     return self;
 }
@@ -1083,8 +1083,9 @@ ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype)
     vtype->hasvalue = true;
     vtype->constval.vfunc = self;
 
-    self->varargs = NULL;
-    self->argc    = NULL;
+    self->varargs     = NULL;
+    self->argc        = NULL;
+    self->fixedparams = NULL;
 
     return self;
 }
@@ -1112,6 +1113,8 @@ void ast_function_delete(ast_function *self)
         ast_delete(self->varargs);
     if (self->argc)
         ast_delete(self->argc);
+    if (self->fixedparams)
+        ast_unref(self->fixedparams);
     mem_d(self);
 }
 
@@ -1612,13 +1615,23 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
 
     if (self->argc) {
         ir_value *va_count;
+        ir_value *fixed;
+        ir_value *sub;
         if (!ast_local_codegen(self->argc, self->ir_func, true))
             return false;
         cgen = self->argc->expression.codegen;
         if (!(*cgen)((ast_expression*)(self->argc), self, false, &va_count))
             return false;
+        cgen = self->fixedparams->expression.codegen;
+        if (!(*cgen)((ast_expression*)(self->fixedparams), self, false, &fixed))
+            return false;
+        sub = ir_block_create_binop(self->curblock, ast_ctx(self),
+                                    ast_function_label(self, "va_count"), INSTR_SUB_F,
+                                    ir_builder_get_va_count(ir), fixed);
+        if (!sub)
+            return false;
         if (!ir_block_create_store_op(self->curblock, ast_ctx(self), INSTR_STORE_F,
-                                      va_count, ir_builder_get_va_count(ir)))
+                                      va_count, sub))
         {
             return false;
         }
diff --git a/ast.h b/ast.h
index 2e9858fc85054ed6c6ff81dd7ebbe295d7bd7e77..94f388e596a36ee395788a29585799d83a49546d 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -648,6 +648,7 @@ struct ast_function_s
 
     ast_value   *varargs;
     ast_value   *argc;
+    ast_value   *fixedparams;
 };
 ast_function* ast_function_new(lex_ctx ctx, const char *name, ast_value *vtype);
 /* This will NOT delete the underlying ast_value */
diff --git a/distro/deb/Makefile b/distro/deb/Makefile
new file mode 100644 (file)
index 0000000..535cf1c
--- /dev/null
@@ -0,0 +1,23 @@
+BASEDIR := ../..
+PREFIX  := /usr
+HEADER  := $(BASEDIR)/gmqcc.h
+MAJOR   := `sed -n -e '/GMQCC_VERSION_MAJOR/{s/.* .* //;p;q;}' $(HEADER)`
+MINOR   := `sed -n -e '/GMQCC_VERSION_MINOR/{s/.* .* //;p;q;}' $(HEADER)`
+PATCH   := `sed -n -e '/GMQCC_VERSION_PATCH/{s/.* .* //;p;q;}' $(HEADER)`
+DEBDIR  := gmqcc-$(MAJOR).$(MINOR).$(PATCH)
+DEB     := $(DEBDIR).deb
+
+base:
+       $(MAKE) -C $(BASEDIR) DESTDIR=distro/deb/$(DEBDIR) PREFIX=$(PREFIX) install
+       @install -d -m755 $(DEBDIR)/DEBIAN
+       @cp       control $(DEBDIR)/DEBIAN/control
+       @tar czf data.tar.gz -C $(DEBDIR)/ . --exclude=DEBIAN
+       @tar czf control.tar.gz -C $(DEBDIR)/DEBIAN/ .
+       @echo 2.0 > debian-binary
+       @ar r $(DEB) debian-binary control.tar.gz data.tar.gz
+       @rm -rf debian-binary control.tar.gz data.tar.gz $(DEBDIR)
+clean:
+       @rm -f $(DEB)
+
+
+all: base
diff --git a/distro/deb/control b/distro/deb/control
new file mode 100644 (file)
index 0000000..57cde3a
--- /dev/null
@@ -0,0 +1,13 @@
+Package: gmqcc
+Version: 0.3.0
+Section: user/hidden
+Priority: optional
+Architecture: i386
+Installed-Size: `du -ks usr|cut -f 1`
+Maintainer: Dale Weiler <killfieldengine@gmail.com>
+Description: An improved Quake C Compiler
+   For an enduring period of time the options for a decent compiler for the Quake C programming language
+   were confined to a specific compiler known as QCC. Attempts were made to extend and improve upon the
+   design of QCC, but many foreseen the consequences of building on a broken foundation. The solution
+   was obvious, a new compiler; one born from the NIH realm of sarcastic wit. We welcome you. You won't
+   find a better Quake C compiler.
index 74cdda4f72e7fdd9a876a0669f0db1b13a8640fd..ea5d005754a4ae3bcf579824484906284003832a 100644 (file)
-.\" Process with groff -man -Tascii file.3
-.TH GMQCC 1 2012-07-12 "" "gmqcc Manual"
-.SH NAME
-gmqcc \- A Quake C compiler built from the NIH realm of sarcastic wit
-.SH SYNOPSIS
-.B gmqcc
-[\fIOPTIONS\fR] [\fIfiles...\fR]
-.SH DESCRIPTION
-Traditionally, a QC compiler reads the file \fIprogs.src\fR which
-in its first line contains the output filename, and the rest is a
+.\"mdoc
+.Dd January 24, 2012
+.Dt GMQCC 1
+.Os
+.Sh NAME
+.Nm gmqcc
+.Nd A Quake C compiler built from the NIH realm of sarcastic wit
+.Sh SYNOPSIS
+.Nm gmqcc
+.Op Cm options
+.Op Ar files...
+.Sh DESCRIPTION
+Traditionally, a QC compiler reads the file
+.Pa progs.src
+which in its first line contains the output filename, and the rest is a
 list of QC source files that are to be compiled in order.
-\fBgmqcc\fR optionally takes options to specify the output and
+.Nm gmqcc
+optionally takes options to specify the output and
 input files on the commandline, and also accepts assembly files.
-.SH OPTIONS
-\fBgmqcc\fR mostly tries to mimic gcc's commandline handling, though
+.Sh OPTIONS
+.Nm gmqcc
+mostly tries to mimic gcc's commandline handling, though
 there are also traditional long-options available.
-.TP
-.B "-h, --help"
+.Bl -tag -width Ds
+.It Fl h , Fl -help
 Show a usage message and exit.
-.TP
-.B "-debug"
+.It Fl "debug"
 Turn on some compiler debugging mechanisms.
-.TP
-.B "-memchk"
+.It Fl memchk
 Turn on compiler mem-check. (Shows allocations and checks for leaks.)
-.TP
-.BI "-o, --output=" filename
+.It Fl o , Fl -output= Ns Ar filename
 Specify the output filename. Defaults to progs.dat. This will overwrite
-the output file listed in a \fIprogs.src\fR file in case such a file is used.
-.TP
-.BI "-O" number
+the output file listed in a
+.Pa progs.src
+file in case such a file is used.
+.Bl -tag -width indent
+.It Fl O Ns Ar number
 Specify the optimization level
-.RS
-.IP 3
+.It Ar 3
 Highest optimization level
-.IP 2
+.It Ar 2
 Default optimization level
-.IP 1
+.It Ar 1
 Minimal optimization level
-.IP 0
+.It Ar 0
 Disable optimization entirely
-.RE
-.TP
-.BI "-O" name "\fR, " "" -Ono- name
+.El
+.Pp
+.It Fl O Ns Ar name Fl Ono- Ns Ar name
 Enable or disable a specific optimization. Note that these options
 must be used after setting the optimization level, otherwise they'll
 be overwritten.
-.TP
-.B -Ohelp
+.It Fl O Ns Cm help
 List all possible optimizations and the optimization level they're
 activated at.
-.TP
-.BR -q ", " --quiet
+.It Fl q , Fl -quiet
 Be less verbose. In particular removes the messages about which files
 are being processed, and which compilation mode is being used, and
 some others. Warnings and errors will of course still be displayed.
-.TP
-.B "-E"
-Run only the preprocessor as if -fftepp was used and print the
-preprocessed code to stdout.
-.TP
-.BI -W warning "\fR, " "" -Wno- warning
+.It Fl E
+Run only the preprocessor as if
+.Fl f Ns Cm ftepp
+was used and print the preprocessed code to stdout.
+.It Fl W Ns Ar warning , Fl Wno- Ns Ar warning
 Enable or disable a warning.
-.TP
-.B -Wall
-Enable almost all warnings. Overrides preceding -W parameters.
-.sp
-The following warnings will \fBnot\fR be anbled:
-.in +4
-.nf
--Wuninitialized-global
-.fi
-.in
-.TP
-.BR -Werror ", " -Wno-error
+.It Fl W Ns Cm all
+Enable almost all warnings. Overrides preceding
+.Fl W
+parameters.
+.Pp
+The following warnings will
+.Em not
+be enabled:
+.Bl -tag -width indent -offset indent
+.It Fl W Ns Cm uninitialized-global
+.El
+.It Fl W Ns Cm error , Fl Wno- Ns Cm error
 Controls whether or not all warnings should be treated as errors.
-.TP
-.BI -Werror- warning "\fR, " "" -Wno-error- warning
+.It Fl Werror- Ns Ar warning , Fl Wno-error- Ns Ar warning
 Controls whether a specific warning should be an error.
-.TP
-.B -Whelp
+.It Fl W Ns Cm help
 List all possible warn flags.
-.TP
-.BI -f flag "\fR, " "" -fno- flag
+.It Fl f Ns Ar flag , Fl fno- Ns Ar flag
 Enable or disable a specific compile flag. See the list of flags
 below.
-.TP
-.B -fhelp
+.It Fl f Ns Cm help
 List all possible compile flags.
-.TP
-.B -nocolor
+.It Fl nocolor
 Disables colored output
-.TP
-.BI -config= file
-Use an ini file to read all the -O, -W and -f flag from. See the
-CONFIG section about the file format.
-.TP
-.BI "-redirout=" file
-Redirects standard output to a \fIfile\fR
-.TP
-.BI "-redirerr=" file
-Redirects standard error to a \fIfile\fR
-.TP
-.BI "-std=" standard
+.It Fl config= Ns Ar file
+Use an ini file to read all the
+.Fl O , Fl W
+and
+.Fl f
+flag from. See the
+.Sx CONFIG
+section about the file format.
+.It Fl redirout= Ns Ar file
+Redirects standard output to a
+.Ar file
+.It Fl redirerr= Ns Ar file
+Redirects standard error to a
+.Ar file
+.It Fl std= Ns Ar standard
 Use the specified standard for parsing QC code. The following standards
 are available:
-.IR gmqcc , qcc , fteqcc
-Selecting a standard also implies some -f options and behaves as if
-those options have been written right after the -std option, meaning
-if you changed them before the -std option, you're now overwriting
-them.
-.sp
-.BR -std=gmqcc " includes:"
-.in +4
-.nf
--fadjust-vector-fields
--fcorrect-logic
--ftrue-empty-strings
--floop-labels
--finitialized-nonconstants
--ftranslatable-strings
--f\fIno-\fRfalse-empty-strings
--Winvalid-parameter-count
--Wmissing-returnvalues
--fcorrect-ternary (cannot be turned off)
-.fi
-.in
-.sp
-.BR -std=qcc " includes:"
-.in +4
-.nf
--fassign-function-types
--f\fIno-\fRadjust-vector-fields
-.fi
-.in
-.sp
-.BR -std=fteqcc " includes:"
-.in +4
-.nf
--fftepp
--ftranslatable-strings
--fassign-function-types
--Wternary-precedence
--f\fIno-\fRadjust-vector-fields
--f\fIno-\fRcorrect-ternary
-.fi
-.in
-.TP
-.B "--add-info"
+.Ar gmqcc , Ar qcc , Ar fteqcc
+Selecting a standard also implies some
+.Fl f
+options and behaves as if
+those options have been written right after the
+.Fl std
+option, meaning
+if you changed them before the
+.Fl -std
+option, you're now overwriting them.
+.Pp
+.Fl std= Ns Cm gmqcc No includes:
+.Bl -tag -width indent -compact -offset Ds
+.It Fl f Ns Cm adjust-vector-fields
+.It Fl f Ns Cm correct-logic
+.It Fl f Ns Cm true-empty-strings
+.It Fl f Ns Cm loop-labels
+.It Fl f Ns Cm initialized-nonconstants
+.It Fl f Ns Cm translatable-strings
+.It Fl fno- Ns Cm false-empty-strings
+.It Fl W Ns Cm invalid-parameter-count
+.It Fl W Ns Cm missing-returnvalues
+.It Fl f Ns Cm correct-ternary Li (cannot be turned off)
+.El
+.Pp
+.Fl std= Ns Cm qcc No includes:
+.Bl -tag -width indent -compact -offset Ds
+.It Fl f Ns Cm assign-function-types
+.It Fl fIno- Ns Cm adjust-vector-fields
+.El
+.Pp
+.Fl std= Ns Cm fteqcc No includes:
+.Bl -tag -width indent -compact -offset Ds
+.It Fl f Ns Cm ftepp
+.It Fl f Ns Cm translatable-strings
+.It Fl f Ns Cm assign-function-types
+.It Fl W Ns Cm ternary-precedence
+.It Fl fno- Ns Cm adjust-vector-fields
+.It Fl fno- Ns Cm correct-ternary
+.El
+.It Fl -add-info
 Adds compiler information to the generated binary file. Currently
 this includes the following globals:
-.RS
-.IP "reserved:version"
+.Bl -tag -width indent -compact
+.It Li reserved:version
 String containing the compiler version as printed by the --version
 parameter.
-.RE
-.TP
-.BR "--correct" ", " "--no-correct"
+.El
+.It Fl -correct , Fl -no-correct
 When enabled, errors about undefined values try to suggest an existing
 value via spell checking.
-.TP
-.B "-dump"
+.It Fl dump
 DEBUG OPTION. Print the code's intermediate representation before the
 optimization and finalization passes to stdout before generating the
 binary.
-.TP
-.B "-dumpfin"
+.It Fl dumpfin
 DEBUG OPTION. Print the code's intermediate representation after the
 optimization and finalization passes to stdout before generating the
 binary. The instructions will be enumerated, and values will contain a
 list of liferanges.
-.SH COMPILE WARNINGS
-.TP
-.B -Wunused-variable
+.El
+.Sh COMPILE WARNINGS
+.Bl -tag -width Ds
+.It Fl W Ns Cm unused-variable
 Generate a warning about variables which are declared but never used.
-This can be avoided by adding the \fInoref\fR keyword in front of the
+This can be avoided by adding the
+.Ql noref
+keyword in front of the
 variable declaration. Additionally a complete section of unreferenced
-variables can be opened using \fI#pragma noref 1\fR, and closed via
-\fI#pragma noref 0\fR.
-.TP
-.B -Wused-uninitialized
+variables can be opened using
+.Ql #pragma noref 1
+and closed via
+.Ql #pragma noref 0 Ns .
+.It Fl W Ns Cm used-uninitialized
 Generate a warning if it is possible that a variable can be used
 without prior initialization. Note that this warning is not
 necessarily reliable if the initialization happens only under certain
-conditions. The other way is \fInot\fR possible: that the warning is
-\fInot\fR generated when uninitialized use \fIis possible\fR.
-.TP
-.B -Wunknown-control-sequence
+conditions. The other way is
+.Em not
+possible: that the warning is
+.Em not
+generated when uninitialized use
+.Em is
+possible.
+.It Fl W Ns Cm unknown-control-sequence
 Generate an error when an unrecognized control sequence in a string is
 used. Meaning: when there's a character after a backslash in a string
 which has no known meaning.
-.TP
-.B -Wextensions
+.It Fl W Ns Cm extensions
 Warn when using special extensions which are not part of the selected
 standard.
-.TP
-.B -Wfield-redeclared
+.It Fl W Ns Cm field-redeclared
 Generally QC compilers ignore redeclaration of fields. Here you can
 optionally enable a warning.
-.TP
-.B -Wmissing-return-values
-Functions which aren't of type \fIvoid\fR will warn if it possible to
+.It Fl W Ns Cm missing-return-values
+Functions which aren't of type
+.Ft void
+will warn if it possible to
 reach the end without returning an actual value.
-.TP
-.B -Winvalid-parameter-count
+.It Fl W Ns Cm invalid-parameter-count
 Warn about a function call with an invalid number of parameters.
-.TP
-.B -Wlocal-shadows
+.It Fl W Ns Cm local-shadows
 Warn when a locally declared variable shadows variable.
-.TP
-.B -Wlocal-constants
+.It Fl W Ns Cm local-constants
 Warn when the initialization of a local variable turns the variable
 into a constant. This is default behaviour unless
-\fI-finitialized-nonconstants\fR is used.
-.TP
-.B -Wvoid-variables
-There are only 2 known global variables of type void: end_sys_globals
-and end_sys_fields. Any other void-variable will warn.
-.TP
-.B -Wimplicit-function-pointer
-A global function which is not declared with the \fIvar\fR keyword is
+.Fl f Ns Cm initialized-nonconstants
+is used.
+.It Fl W Ns Cm void-variables
+There are only 2 known global variables of type void:
+.Ql end_sys_globals
+and
+.Ql end_sys_fields Ns .
+Any other void-variable will warn.
+.It Fl W Ns Cm implicit-function-pointer
+A global function which is not declared with the
+.Ql var
+keyword is
 expected to have an implementing body, or be a builtin. If neither is
 the case, it implicitly becomes a function pointer, and a warning is
 generated.
-.TP
-.B -Wvariadic-function
+.It Fl W Ns Cm variadic-function
 Currently there's no way for an in QC implemented function to access
 variadic parameters. If a function with variadic parameters has an
 implementing body, a warning will be generated.
-.TP
-.B -Wframe-macros
-Generate warnings about \fI$frame\fR commands, for instance about
+.It Fl W Ns Cm frame-macros
+Generate warnings about
+.Ql $frame
+commands, for instance about
 duplicate frame definitions.
-.TP
-.B -Weffectless-statement
+.It Fl W Ns Cm effectless-statement
 Warn about statements which have no effect. Any expression which does
 not call a function or assigns a variable.
-.TP
-.B -Wend-sys-fields
-The \fIend_sys_fields\fR variable is supposed to be a global variable
-of type \fIvoid\fR. It is also recognized as a \fIfield\fR but this
+.It Fl W Ns Cm end-sys-fields
+The
+.Ql end_sys_fields
+variable is supposed to be a global variable
+of type
+.Ft void Ns .
+It is also recognized as a \fIfield\fR but this
 will generate a warning.
-.TP
-.B -Wassign-function-types
+.It Fl W Ns Cm assign-function-types
 Warn when assigning to a function pointer with an unmatching
 signature. This usually happens in cases like assigning the null
 function to an entity's .think function pointer.
-.TP
-.B -Wpreprocessor
+.It Fl W Ns Cm preprocessor
 Enable warnings coming from the preprocessor. Like duplicate macro
 declarations. This warning triggers when there's a problem with the
 way the preprocessor has been used, it will \fBnot\fR affect warnings
 generated with the '#warning' directive. See -Wcpp.
-.TP
-.B -Wcpp
+.It Fl W Ns Cm cpp
 Show warnings created using the preprocessor's '#warning' directive.
-.TP
-.B -Wmultifile-if
+.It Fl W Ns Cm multifile-if
 Warn if there's a preprocessor \fI#if\fR spanning across several
 files.
-.TP
-.B -Wdouble-declaration
+.It Fl W Ns Cm double-declaration
 Warn about multiple declarations of globals. This seems pretty common
 in QC code so you probably do not want this unless you want to clean
 up your code.
-.TP
-.B -Wconst-var
+.It Fl W Ns Cm const-var
 The combination of \fIconst\fR and \fIvar\fR is not illegal, however
 different compilers may handle them differently. We were told, the
 intention is to create a function-pointer which is not assignable.
 This is exactly how we interpret it. However for this interpretation
-the \fIvar\fR keyword is considered superfluous (and philosophically
+the
+.Ql var
+keyword is considered superfluous (and philosophically
 wrong), so it is possible to generate a warning about this.
-.TP
-.B -Wmultibyte-character
+.It Fl W Ns Cm multibyte-character
 Warn about multibyte character constants, they do not work right now.
-.TP
-.B -Wternary-precedence
+.It Fl W Ns Cm ternary-precedence
 Warn if a ternary expression which contains a comma operator is used
 without enclosing parenthesis, since this is most likely not what you
-actually want. We recommend the \fI-fcorrect-ternary\fR option.
-.TP
-.B -Wunknown-pragmas
-Warn when encountering an unrecognized \fI#pragma\fR line.
-.TP
-.B -Wunreachable-code
+actually want. We recommend the
+.Fl f Ns Cm correct-ternary
+option.
+.It Fl W Ns Cm unknown-pragmas
+Warn when encountering an unrecognized
+.Ql #pragma
+line.
+.It Fl W Ns Cm unreachable-code
 Warn about unreachable code. That is: code after a return statement,
 or code after a call to a function marked as 'noreturn'.
-.TP
-.B -Wdebug
+.It Fl W Ns Cm debug
 Enable some warnings added in order to help debugging in the compiler.
 You won't need this.
-.B -Wunknown-attribute
+.It Fl W Ns Cm unknown-attribute
 Warn on an unknown attribute. The warning will inlclude only the first
 token inside the enclosing attribute-brackets. This may change when
 the actual attribute syntax is better defined.
-.TP
-.B -Wreserved-names
-Warn when using reserved names such as 'nil'.
-.TP
-.B -Wuninitialized-constant
-Warn about global constants (using the 'const' keyword) with no
+.It Fl W Ns Cm reserved-names
+Warn when using reserved names such as
+.Ql nil Ns .
+.It Fl W Ns Cm uninitialized-constant
+Warn about global constants (using the
+.Ql const
+keyword) with no
 assigned value.
-.TP
-.B -Wuninitialized-global
+.It Fl W Ns Cm uninitialized-global
 Warn about global variables with no initializing value. This is off by
 default, and is added mostly to help find null-values which are
 supposed to be replaced by the untyped 'nil' constant.
-.TP
-.B -Wdifferent-qualifiers
+.It Fl W Ns Cm different-qualifiers
 Warn when a variables is redeclared with a different qualifier. For
 example when redeclaring a variable as \'var\' which was previously
 marked \'const\'.
-.TP
-.B -Wdifferent-attributes
-Similar to the above but for attributes like "[[noreturn]]".
-.TP
-.B -Wdeprecated
+.It Fl W Ns Cm different-attributes
+Similar to the above but for attributes like
+.Ql [[noreturn]] Ns .
+.It Fl W Ns Cm deprecated
 Warn when a function is marked with the attribute
 "[[deprecated]]". This flag enables a warning on calls to functions
 marked as such.
-.TP
-.B -Wparenthesis
+.It Fl W Ns Cm parenthesis
 Warn about possible mistakes caused by missing or wrong parenthesis,
 like an assignment in an 'if' condition when there's no additional set
 of parens around the assignment.
-.SH COMPILE FLAGS
-.TP
-.B -fdarkplaces-string-table-bug
+.El
+.Sh COMPILE FLAGS
+.Bl -tag -width Ds
+.It Fl f Ns Cm darkplaces-string-table-bug
 Add some additional characters to the string table in order to
 compensate for a wrong boundcheck in some specific version of the
 darkplaces engine.
-.TP
-.B -fadjust-vector-fields
+.It Fl f Ns Cm adjust-vector-fields
 When assigning to field pointers of type \fI.vector\fR the common
 behaviour in compilers like \fIfteqcc\fR is to only assign the
 x-component of the pointer. This means that you can use the vector as
 such, but you cannot use its y and z components directly. This flag
 fixes this behaviour. Before using it make sure your code does not
 depend on the buggy behaviour.
-.TP
-.B -fftepp
+.It Fl f Ns Cm ftepp
 Enable a partially fteqcc-compatible preprocessor. It supports all the
 features used in the Xonotic codebase. If you need more, write a
 ticket.
-.TP
-.B -fftepp-predefs
+.It Fl f Ns Cm ftepp-predefs
 Enable some predefined macros. This only works in combination with
 \'-fftepp' and is currently not included by '-std=fteqcc'. The
 following macros will be added:
-.in +4
-.nf
+.Bd -literal -offset indent
 __LINE__
 __FILE__
 __COUNTER__
@@ -358,97 +352,88 @@ __RANDOM__
 __RANDOM_LAST__
 __DATE__
 __TIME__
-.fi
-.in
-Note that fteqcc also defines __NULL__ which is not implemented yet.
-(See -funtyped-nil about gmqcc's alternative to __NULL__).
-.TP
-.B -frelaxed-switch
+.Ed
+.Pp
+Note that fteqcc also defines
+.Li __NULL__
+which is not implemented yet.
+(See
+.Fl f Ns Cm untyped-nil
+about gmqcc's alternative to
+.Li __NULL__ Ns ).
+.It Fl f Ns Cm relaxed-switch
 Allow switch cases to use non constant variables.
-.TP
-.B -fshort-logic
+.It Fl f Ns Cm short-logic
 Perform early out in logical AND and OR expressions. The final result
 will be either a 0 or a 1, see the next flag for more possibilities.
-.TP
-.B -fperl-logic
+.It Fl f Ns Cm perl-logic
 In many languages, logical expressions perform early out in a special
 way: If the left operand of an AND yeilds true, or the one of an OR
 yields false, the complete expression evaluates to the right side.
-Thus \fItrue && 5\fI evaluates to 5 rather than 1.
-.TP
-.B -ftranslatable-strings
-Enable the underscore intrinsic: Using \fI_("A string constant")\fR
+Thus
+.Ql true && 5
+evaluates to 5 rather than 1.
+.It Fl f Ns Cm translatable-strings
+Enable the underscore intrinsic: Using
+.Ql _("A string constant")
 will cause the string immediate to get a name with a "dotranslate_"
 prefix. The darkplaces engine recognizes these and translates them in
 a way similar to how gettext works.
-.TP
-.B -finitialized-nonconstants
+.It Fl f Ns Cm initialized-nonconstants
 Don't implicitly convert initialized variables to constants. With this
 flag, the \fIconst\fR keyword is required to make a constant.
-.TP
-.B -fassign-function-types
+.It Fl f Ns Cm assign-function-types
 If this flag is not set, (and it is set by default in the qcc and
 fteqcc standards), assigning function pointers of mismatching
 signatures will result in an error rather than a warning.
-.TP
-.B -flno
+.It Fl f Ns Cm lno
 Produce a linenumber file along with the output .dat file.
-.TP
-.B -fcorrect-ternary
+.It Fl f Ns Cm correct-ternary
 Use C's operator precedence for ternary expressions. Unless your code
 depends on fteqcc-compatible behaviour, you'll want to use thi
 soption.
-.TP
-.B -fsingle-vector-defs
+.It Fl f Ns Cm single-vector-defs
 Normally vectors generate 4 defs, once for the vector, and once for
 its components with _x, _y, _z suffixes. This option
 prevents components from being listed.
-.TP
-.B -fcorrect-logic
-Most QC compilers translate if(a_vector) directly as an IF on the
-vector, which means only the x-component is checked. This causes
+.It Fl f Ns Cm correct-logic
+Most QC compilers translate
+.Ql if(a_vector)
+directly as an IF on the
+vector, which means only the x-component is checked. This option causes
 vectors to be cast to actual booleans via a NOT_V and, if necessary, a
 NOT_F chained to it.
-.in +4
-.nf
+.Bd -literal -offset indent
 if (a_vector) // becomes
 if not(!a_vector)
 // likewise
 a = a_vector && a_float // becomes
 a = !!a_vector && a_float
-.fi
-.in
-.TP
-.B -ftrue-empty-strings
+.Ed
+.It Fl f Ns Cm true-empty-strings
 An empty string is considered to be true everywhere. The NOT_S
 instruction usually considers an empty string to be false, this option
 effectively causes the unary not in strings to use NOT_F instead.
-.TP
-.B -ffalse-empty-strings
+.It Fl f Ns Cm false-empty-strings
 An empty string is considered to be false everywhere. This means loops
 and if statements which depend on a string will perform a NOT_S
 instruction on the string before using it.
-.TP
-.B -futf8
+.It Fl f Ns Cm utf8
 Enable utf8 characters. This allows utf-8 encoded character constants,
 and escape sequence codepoints in the valid utf-8 range. Effectively
 enabling escape sequences like '\\{x2211}'.
-.TP
-.B -fbail-on-werror
+.It Fl f Ns Cm bail-on-werror
 When a warning is treated as an error, and this option is set (which
 it is by default), it is like any other error and will cause
 compilation to stop. When disabling this flag by using
 \-fno-bail-on-werror, compilation will continue until the end, but no
 output is generated. Instead the first such error message's context is
 shown.
-.TP
-.B -floop-labels
+.It Fl f Ns Cm loop-labels
 Allow loops to be labeled, and allow 'break' and 'continue' to take an
 optional label to decide which loop to actually jump out of or
 continue.
-.sp
-.in +4
-.nf
+.Bd -literal -offset indent
 for :outer (i = 0; i < n; ++i) {
     while (inner) {
         ...;
@@ -456,10 +441,8 @@ for :outer (i = 0; i < n; ++i) {
             continue outer;
     }
 }
-.fi
-.in
-.TP
-.B -funtyped-nil
+.Ed
+.It Fl f Ns Cm untyped-nil
 Adds a global named 'nil' which is of no type and can be assigned to
 anything. No typechecking will be performed on assignments. Assigning
 to it is forbidden, using it in any other kind of expression is also
@@ -477,47 +460,42 @@ components.
 In that gmqcc the nil global is an actual global filled with zeroes,
 and can be assigned to anything including fields, vectors or function
 pointers, and they end up becoming zeroed.
-.TP
-.B -fpermissive
+.It Fl f Ns Cm permissive
 Various effects, usually to weaken some conditions.
-.RS
-.IP "with -funtyped-nil"
-Allow local variables named 'nil'. (This will not allow declaring a
-global of that name.)
-.RE
-.TP
-.B -fvariadic-args
+.Bl -tag -width indent -offset indent
+.It with Fl f Ns Cm untyped-nil
+Allow local variables named
+.Ql nil Ns .
+(This will not allow declaring a global of that name.)
+.El
+.It Fl f Ns Cm variadic-args
 Allow variadic parameters to be accessed by QC code. This can be
 achieved via the '...' function, which takes a parameter index and a
 typename.
-
+.Pp
 Example:
-.sp
-.in +4
-.nf
+.Bd -literal -offset indent
 void vafunc(string...count) {
     float i;
     for (i = 0; i < count; ++i)
         print(...(i, string), "\\n");
 }
-.fi
-.in
-.TP -flegacy-vector-maths
+.Ed
+.It Fl f Ns Cm legacy-vector-maths
 Most Quake VMs, including the one from FTEQW or up till recently
 Darkplaces, do not cope well with vector instructions with overlapping
 input and output. This option will avoid producing such code.
-.SH OPTIMIZATIONS
-.TP
-.B -Opeephole
+.El
+.Sh OPTIMIZATIONS
+.Bl -tag -width Ds
+.It Fl O Ns Cm peephole
 Some general peephole optimizations. For instance the code `a = b + c`
 typically generates 2 instructions, an ADD and a STORE. This
 optimization removes the STORE and lets the ADD write directly into A.
-.TP
-.B -Otail-recursion
+.It Fl O Ns Cm tail-recursion
 Tail recursive function calls will be turned into loops to avoid the
 overhead of the CALL and RETURN instructions.
-.TP
-.B -Ooverlap-locals
+.It Fl O Ns Cm overlap-locals
 Make all functions which use neither local arrays nor have locals
 which are seen as possibly uninitialized use the same local section.
 This should be pretty safe compared to other compilers which do not
@@ -528,44 +506,37 @@ as long as the functions cannot be called in a recursive manner. Since
 it's hard to know whether or not an array is actually fully
 initialized, especially when initializing it via a loop, we assume
 functions with arrays to be too dangerous for this optimization.
-.TP
-.B -Olocal-temps
+.It Fl O Ns Cm local-temps
 This promotes locally declared variables to "temps". Meaning when a
 temporary result of an operation has to be stored somewhere, a local
 variable which is not 'alive' at that point can be used to keep the
 result. This can reduce the size of the global section.
 This will not have declared variables overlap, even if it was
 possible.
-.TP
-.B -Oglobal-temps
+.It Fl O Ns Cm global-temps
 Causes temporary values which do not need to be backed up on a CALL to
 not be stored in the function's locals-area. With this, a CALL to a
 function may need to back up fewer values and thus execute faster.
-.TP
-.B -Ostrip-constant-names
+.It Fl O Ns Cm strip-constant-names
 Don't generate defs for immediate values or even declared constants.
 Meaning variables which are implicitly constant or qualified as such
 using the 'const' keyword.
-.TP
-.B -Ooverlap-strings
+.It Fl O Ns Cm overlap-strings
 Aggressively reuse strings in the string section. When a string should
 be added which is the trailing substring of an already existing
 string, the existing string's tail will be returned instead of the new
 string being added.
-
+.Pp
 For example the following code will only generate 1 string:
-
-.in +4
-.nf
+.Bd -literal -offset indent
 print("Hell you!\\n");
 print("you!\\n"); // trailing substring of "Hello you!\\n"
-.fi
-.in
+.Ed
+.Pp
 There's however one limitation. Strings are still processed in order,
 so if the above print statements were reversed, this optimization
 would not happen.
-.TP
-.B -Ocall-stores
+.It Fl O Ns Cm call-stores
 By default, all parameters of a CALL are copied into the
 parameter-globals right before the CALL instructions. This is the
 easiest and safest way to translate calls, but also adds a lot of
@@ -573,39 +544,48 @@ unnecessary copying and unnecessary temporary values. This
 optimization makes operations which are used as a parameter evaluate
 directly into the parameter-global if that is possible, which is when
 there's no other CALL instruction in between.
-.TP
-.B -Ovoid-return
+.It Fl O Ns Cm void-return
 Usually an empty RETURN instruction is added to the end of a void
 typed function. However, additionally after every function a DONE
 instruction is added for several reasons. (For example the qcvm's
 disassemble switch uses it to know when the function ends.). This
 optimization replaces that last RETURN with DONE rather than adding
 the DONE additionally.
-.TP
-.B -Ovector-components
+.It Fl O Ns Cm vector-components
 Because traditional QC code doesn't allow you to access individual
 vector components of a computed vector without storing it in a local
-first, sometimes people multiply it by a constant like '0 1 0' to get,
+first, sometimes people multiply it by a constant like
+.Ql '0 1 0'
+to get,
 in this case, the y component of a vector. This optimization will turn
 such a multiplication into a direct component access. If the factor is
 anything other than 1, a float-multiplication will be added, which is
 still faster than a vector multiplication.
-.SH CONFIG
+.El
+.Sh CONFIG
 The configuration file is similar to regular .ini files. Comments
 start with hashtags or semicolons, sections are written in square
 brackets and in each section there can be arbitrary many key-value
 pairs.
-.sp
+.Pp
 There are 3 sections currently:
-.IR flags ", " warnings ", and " optimizations .
-They contain a list of boolean values of the form `VARNAME = true` or
-`VARNAME = false`. The variable names are the same as for the
-corresponding -W, -f or -O flag written with only capital letters and
+.Ql flags Ns ,
+.Ql warnings Ns ,
+.Ql optimizations Ns .
+They contain a list of boolean values of the form
+.Ql VARNAME = true
+or
+.Ql VARNAME = false Ns .
+The variable names are the same as for the
+corresponding
+.Fl W , Fl f
+or
+.Fl O
+flag written with only capital letters and
 dashes replaced by underscores.
-.sp
+.Pp
 Here's an example:
-.in +4
-.nf
+.Bd -literal -offset indent
 # a GMQCC configuration file
 [flags]
     FTEPP = true
@@ -619,20 +599,19 @@ Here's an example:
 [optimizations]
     PEEPHOLE = true
     TAIL_RECURSION = true
-.fi
-.in
-.SH BUGS
+.Ed
+.Sh FILES
+.Bl -tag -width Ds
+.It gmqcc.ini.example
+A documented example for a gmqcc.ini file.
+.El
+.Sh SEE ALSO
+.Xr qcvm 1
+.Sh AUTHOR
+See <http://graphitemaster.github.com/gmqcc>.
+.Sh BUGS
 Currently the '-fftepp-predefs' flag is not included by '-std=fteqcc',
 partially because it is not entirely conformant to fteqcc.
-.sp
-
+.Pp
 Please report bugs on <http://github.com/graphitemaster/gmqcc/issues>,
 or see <http://graphitemaster.github.com/gmqcc> on how to contact us.
-.SH FILES
-.TP 20
-.B gmqcc.ini.example
-A documented example for a gmqcc.ini file.
-.SH SEE ALSO
-.IR qcvm (1)
-.SH AUTHOR
-See <http://graphitemaster.github.com/gmqcc>.
diff --git a/exec.c b/exec.c
index f4c9ecf458f1a5a21d3247ad5f6ffee121d993fc..101901d86c24fff8d5a61fe132d808b489e17e90 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -51,7 +51,7 @@ static void qcvmerror(qc_program *prog, const char *fmt, ...)
     putchar('\n');
 }
 
-qc_program* prog_load(const char *filename)
+qc_program* prog_load(const char *filename, bool skipversion)
 {
     qc_program   *prog;
     prog_header   header;
@@ -66,7 +66,7 @@ qc_program* prog_load(const char *filename)
         return NULL;
     }
 
-    if (header.version != 6) {
+    if (!skipversion && header.version != 6) {
         loaderror("header says this is a version %i progs, we need version 6\n", header.version);
         file_close(file);
         return NULL;
@@ -1080,7 +1080,7 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-    prog = prog_load(progsfile);
+    prog = prog_load(progsfile, noexec);
     if (!prog) {
         printf("failed to load program '%s'\n", progsfile);
         exit(1);
diff --git a/gmqcc.h b/gmqcc.h
index a6053a6d1cd60e5a21efb74534ed58183ddc1a6e..94a4bf638c48441674b4eed014a5ad00a8d82150 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -975,7 +975,7 @@ typedef struct qc_program_s {
     int    argc; /* current arg count for debugging */
 } qc_program;
 
-qc_program* prog_load(const char *filename);
+qc_program* prog_load(const char *filename, bool ignoreversion);
 void        prog_delete(qc_program *prog);
 
 bool prog_exec(qc_program *prog, prog_section_function *func, size_t flags, long maxjumps);
diff --git a/ir.c b/ir.c
index 897c60269835f7969ded3cfabb979c07b23ca078..38882ec85ebf24617fd2fa483427931728cf8d79 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -3113,7 +3113,7 @@ static ir_value* ir_gen_extparam_proto(ir_builder *ir)
     ir_value *global;
     char      name[128];
 
-    snprintf(name, sizeof(name), "EXTPARM#%i", (int)(vec_size(ir->extparam_protos)+8));
+    snprintf(name, sizeof(name), "EXTPARM#%i", (int)(vec_size(ir->extparam_protos)));
     global = ir_value_var(name, store_global, TYPE_VECTOR);
 
     vec_push(ir->extparam_protos, global);
index 2616081a1b52d0d7263494b03f57356d5dbc729f..159c7a829565980e2123b6cab446085720ade786 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -34,7 +34,6 @@
 #define PARSER_HT_SIZE    128
 #define TYPEDEF_HT_SIZE   16
 
-enum parser_pot { POT_PAREN, POT_TERNARY1, POT_TERNARY2 };
 typedef struct {
     lex_file *lex;
     int      tok;
@@ -89,12 +88,6 @@ typedef struct {
     /* we store the '=' operator info */
     const oper_info *assign_op;
 
-    /* Keep track of our ternary vs parenthesis nesting state.
-     * If we reach a 'comma' operator in a ternary without a paren,
-     * we shall trigger -Wternary-precedence.
-     */
-    enum parser_pot *pot;
-
     /* magic values */
     ast_value *const_vec[3];
 
@@ -386,23 +379,28 @@ static ast_value* parser_find_typedef(parser_t *parser, const char *name, size_t
 typedef struct
 {
     size_t etype; /* 0 = expression, others are operators */
-    int             paren;
+    bool            isparen;
     size_t          off;
     ast_expression *out;
     ast_block      *block; /* for commas and function calls */
     lex_ctx ctx;
 } sy_elem;
+
+enum {
+    PAREN_EXPR,
+    PAREN_FUNC,
+    PAREN_INDEX,
+    PAREN_TERNARY1,
+    PAREN_TERNARY2
+};
 typedef struct
 {
-    sy_elem *out;
-    sy_elem *ops;
+    sy_elem        *out;
+    sy_elem        *ops;
+    size_t         *argc;
+    unsigned int   *paren;
 } shunt;
 
-#define SY_PAREN_EXPR '('
-#define SY_PAREN_FUNC 'f'
-#define SY_PAREN_INDEX '['
-#define SY_PAREN_TERNARY '?'
-
 static sy_elem syexp(lex_ctx ctx, ast_expression *v) {
     sy_elem e;
     e.etype = 0;
@@ -410,7 +408,7 @@ static sy_elem syexp(lex_ctx ctx, ast_expression *v) {
     e.out   = v;
     e.block = NULL;
     e.ctx   = ctx;
-    e.paren = 0;
+    e.isparen = false;
     return e;
 }
 
@@ -421,7 +419,7 @@ static sy_elem syblock(lex_ctx ctx, ast_block *v) {
     e.out   = (ast_expression*)v;
     e.block = v;
     e.ctx   = ctx;
-    e.paren = 0;
+    e.isparen = false;
     return e;
 }
 
@@ -432,27 +430,21 @@ static sy_elem syop(lex_ctx ctx, const oper_info *op) {
     e.out   = NULL;
     e.block = NULL;
     e.ctx   = ctx;
-    e.paren = 0;
+    e.isparen = false;
     return e;
 }
 
-static sy_elem syparen(lex_ctx ctx, int p, size_t off) {
+static sy_elem syparen(lex_ctx ctx, size_t off) {
     sy_elem e;
     e.etype = 0;
     e.off   = off;
     e.out   = NULL;
     e.block = NULL;
     e.ctx   = ctx;
-    e.paren = p;
+    e.isparen = true;
     return e;
 }
 
-#ifdef DEBUGSHUNT
-# define DEBUGSHUNTDO(x) x
-#else
-# define DEBUGSHUNTDO(x)
-#endif
-
 /* With regular precedence rules, ent.foo[n] is the same as (ent.foo)[n],
  * so we need to rotate it to become ent.(foo[n]).
  */
@@ -537,7 +529,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
         return false;
     }
 
-    if (vec_last(sy->ops).paren) {
+    if (vec_last(sy->ops).isparen) {
         parseerror(parser, "unmatched parenthesis");
         return false;
     }
@@ -545,8 +537,6 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
     op = &operators[vec_last(sy->ops).etype - 1];
     ctx = vec_last(sy->ops).ctx;
 
-    DEBUGSHUNTDO(con_out("apply %s\n", op->op));
-
     if (vec_size(sy->out) < op->operands) {
         compile_error(ctx, "internal error: not enough operands: %i (operator %s (%i))", vec_size(sy->out),
                       op->op, (int)op->id);
@@ -661,6 +651,12 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             break;
 
         case opid1(','):
+            if (vec_size(sy->paren) && vec_last(sy->paren) == PAREN_FUNC) {
+                vec_push(sy->out, syexp(ctx, exprs[0]));
+                vec_push(sy->out, syexp(ctx, exprs[1]));
+                vec_last(sy->argc)++;
+                return true;
+            }
             if (blocks[0]) {
                 if (!ast_block_add_expr(blocks[0], exprs[1]))
                     return false;
@@ -1052,11 +1048,11 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             break;
 
         case opid2('?',':'):
-            if (vec_last(parser->pot) != POT_TERNARY2) {
+            if (vec_last(sy->paren) != PAREN_TERNARY2) {
                 compile_error(ctx, "mismatched parenthesis/ternary");
                 return false;
             }
-            vec_pop(parser->pot);
+            vec_pop(sy->paren);
             if (!ast_compare_type(exprs[1], exprs[2])) {
                 ast_type_to_string(exprs[1], ty1, sizeof(ty1));
                 ast_type_to_string(exprs[2], ty2, sizeof(ty2));
@@ -1364,11 +1360,10 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
 #undef NotSameType
 
     if (!out) {
-        compile_error(ctx, "failed to apply operand %s", op->op);
+        compile_error(ctx, "failed to apply operator %s", op->op);
         return false;
     }
 
-    DEBUGSHUNTDO(con_out("applied %s\n", op->op));
     vec_push(sy->out, syexp(ctx, out));
     return true;
 }
@@ -1381,20 +1376,27 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
     ast_call       *call;
 
     size_t          fid;
-    size_t          paramcount;
+    size_t          paramcount, i;
 
+    fid = vec_last(sy->ops).off;
     vec_shrinkby(sy->ops, 1);
-    fid = sy->ops[vec_size(sy->ops)].off;
 
     /* out[fid] is the function
      * everything above is parameters...
-     * 0 params = nothing
-     * 1 params = ast_expression
-     * more = ast_block
      */
+    if (!vec_size(sy->argc)) {
+        parseerror(parser, "internal error: no argument counter available");
+        return false;
+    }
+
+    paramcount = vec_last(sy->argc);
+    vec_pop(sy->argc);
 
-    if (vec_size(sy->out) < 1 || vec_size(sy->out) <= fid) {
-        parseerror(parser, "internal error: function call needs function and parameter list...");
+    if (vec_size(sy->out) < fid) {
+        parseerror(parser, "internal error: broken function call%lu < %lu+%lu\n",
+                   (unsigned long)vec_size(sy->out),
+                   (unsigned long)fid,
+                   (unsigned long)paramcount);
         return false;
     }
 
@@ -1420,42 +1422,28 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
     if (!call)
         return false;
 
-    if (fid+1 == vec_size(sy->out)) {
-        /* no arguments */
-        paramcount = 0;
-    } else if (fid+2 == vec_size(sy->out)) {
-        ast_block *params;
-        vec_shrinkby(sy->out, 1);
-        params = sy->out[vec_size(sy->out)].block;
-        if (!params) {
-            /* 1 param */
-            paramcount = 1;
-            vec_push(call->params, sy->out[vec_size(sy->out)].out);
-        } else {
-            paramcount = vec_size(params->exprs);
-            call->params = params->exprs;
-            params->exprs = NULL;
-            ast_delete(params);
-        }
-        if (parser->max_param_count < paramcount)
-            parser->max_param_count = paramcount;
-        (void)!ast_call_check_types(call);
-    } else {
-        parseerror(parser, "invalid function call");
+    if (fid+1 < vec_size(sy->out))
+        ++paramcount;
+
+    if (fid+1 + paramcount != vec_size(sy->out)) {
+        parseerror(parser, "internal error: parameter count mismatch: (%lu+1+%lu), %lu",
+                   (unsigned long)fid, (unsigned long)paramcount, (unsigned long)vec_size(sy->out));
         return false;
     }
 
+    for (i = 0; i < paramcount; ++i)
+        vec_push(call->params, sy->out[fid+1 + i].out);
+    vec_shrinkby(sy->out, paramcount);
+    (void)!ast_call_check_types(call);
+    if (parser->max_param_count < paramcount)
+        parser->max_param_count = paramcount;
+
     if (ast_istype(fun, ast_value)) {
         funval = (ast_value*)fun;
         if ((fun->expression.flags & AST_FLAG_VARIADIC) &&
             !(/*funval->cvq == CV_CONST && */ funval->hasvalue && funval->constval.vfunc->builtin))
         {
-            size_t va_count;
-            if (paramcount < vec_size(fun->expression.params))
-                va_count = 0;
-            else
-                va_count = paramcount - vec_size(fun->expression.params);
-            call->va_count = (ast_expression*)parser_const_float(parser, (double)va_count);
+            call->va_count = (ast_expression*)parser_const_float(parser, (double)paramcount);
         }
     }
 
@@ -1516,54 +1504,48 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
     return true;
 }
 
-static bool parser_close_paren(parser_t *parser, shunt *sy, bool functions_only)
+static bool parser_close_paren(parser_t *parser, shunt *sy)
 {
     if (!vec_size(sy->ops)) {
         parseerror(parser, "unmatched closing paren");
         return false;
     }
-    /* this would for bit a + (x) because there are no operators inside (x)
-    if (sy->ops[vec_size(sy->ops)-1].paren == 1) {
-        parseerror(parser, "empty parenthesis expression");
-        return false;
-    }
-    */
+
     while (vec_size(sy->ops)) {
-        if (vec_last(sy->ops).paren == SY_PAREN_FUNC) {
-            if (!parser_close_call(parser, sy))
-                return false;
-            break;
-        }
-        if (vec_last(sy->ops).paren == SY_PAREN_EXPR) {
-            if (!vec_size(sy->out)) {
-                compile_error(vec_last(sy->ops).ctx, "empty paren expression");
+        if (vec_last(sy->ops).isparen) {
+            if (vec_last(sy->paren) == PAREN_FUNC) {
+                vec_pop(sy->paren);
+                if (!parser_close_call(parser, sy))
+                    return false;
+                break;
+            }
+            if (vec_last(sy->paren) == PAREN_EXPR) {
+                vec_pop(sy->paren);
+                if (!vec_size(sy->out)) {
+                    compile_error(vec_last(sy->ops).ctx, "empty paren expression");
+                    vec_shrinkby(sy->ops, 1);
+                    return false;
+                }
                 vec_shrinkby(sy->ops, 1);
-                return false;
+                break;
             }
-            vec_shrinkby(sy->ops, 1);
-            return !functions_only;
-        }
-        if (vec_last(sy->ops).paren == SY_PAREN_INDEX) {
-            if (functions_only)
-                return false;
-            /* pop off the parenthesis */
-            vec_shrinkby(sy->ops, 1);
-            /* then apply the index operator */
-            if (!parser_sy_apply_operator(parser, sy))
-                return false;
-            return true;
-        }
-        if (vec_last(sy->ops).paren == SY_PAREN_TERNARY) {
-            if (functions_only)
-                return false;
-            if (vec_last(parser->pot) != POT_TERNARY1) {
-                parseerror(parser, "mismatched colon in ternary expression (missing closing paren?)");
-                return false;
+            if (vec_last(sy->paren) == PAREN_INDEX) {
+                vec_pop(sy->paren);
+                /* pop off the parenthesis */
+                vec_shrinkby(sy->ops, 1);
+                /* then apply the index operator */
+                if (!parser_sy_apply_operator(parser, sy))
+                    return false;
+                break;
             }
-            vec_last(parser->pot) = POT_TERNARY2;
-            /* pop off the parenthesis */
-            vec_shrinkby(sy->ops, 1);
-            return true;
+            if (vec_last(sy->paren) == PAREN_TERNARY1) {
+                vec_last(sy->paren) = PAREN_TERNARY2;
+                /* pop off the parenthesis */
+                vec_shrinkby(sy->ops, 1);
+                break;
+            }
+            compile_error(vec_last(sy->ops).ctx, "invalid parenthesis");
+            return false;
         }
         if (!parser_sy_apply_operator(parser, sy))
             return false;
@@ -1664,323 +1646,227 @@ static ast_expression* parse_vararg_do(parser_t *parser)
 
 static ast_expression* parse_vararg(parser_t *parser)
 {
-    bool             old_noops = parser->lex->flags.noops;
-    enum parser_pot *old_pot   = parser->pot;
+    bool           old_noops = parser->lex->flags.noops;
 
     ast_expression *out;
 
-    parser->pot = NULL;
     parser->lex->flags.noops = true;
     out = parse_vararg_do(parser);
 
-    parser->pot              = old_pot;
     parser->lex->flags.noops = old_noops;
     return out;
 }
 
-static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels)
+static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
 {
-    ast_expression *expr = NULL;
-    shunt sy;
-    size_t i;
-    bool wantop = false;
-    /* only warn once about an assignment in a truth value because the current code
-     * would trigger twice on: if(a = b && ...), once for the if-truth-value, once for the && part
-     */
-    bool warn_truthvalue = true;
-
-    /* count the parens because an if starts with one, so the
-     * end of a condition is an unmatched closing paren
-     */
-    int parens = 0;
-    int ternaries = 0;
-
-    sy.out = NULL;
-    sy.ops = NULL;
-
-    parser->lex->flags.noops = false;
-
-    parser_reclassify_token(parser);
-
-    while (true)
+    if (OPTS_FLAG(TRANSLATABLE_STRINGS) &&
+        parser->tok == TOKEN_IDENT &&
+        !strcmp(parser_tokval(parser), "_"))
     {
-        if (OPTS_FLAG(TRANSLATABLE_STRINGS) &&
-            parser->tok == TOKEN_IDENT && !strcmp(parser_tokval(parser), "_"))
-        {
-            /* a translatable string */
-            ast_value *val;
-
-            if (wantop) {
-                parseerror(parser, "expected operator or end of statement, got constant");
-                goto onerr;
-            }
+        /* a translatable string */
+        ast_value *val;
 
-            parser->lex->flags.noops = true;
-            if (!parser_next(parser) || parser->tok != '(') {
-                parseerror(parser, "use _(\"string\") to create a translatable string constant");
-                goto onerr;
-            }
-            parser->lex->flags.noops = false;
-            if (!parser_next(parser) || parser->tok != TOKEN_STRINGCONST) {
-                parseerror(parser, "expected a constant string in translatable-string extension");
-                goto onerr;
-            }
-            val = parser_const_string(parser, parser_tokval(parser), true);
-            wantop = true;
-            if (!val)
-                return NULL;
-            vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
-            DEBUGSHUNTDO(con_out("push string\n"));
+        parser->lex->flags.noops = true;
+        if (!parser_next(parser) || parser->tok != '(') {
+            parseerror(parser, "use _(\"string\") to create a translatable string constant");
+            return false;
+        }
+        parser->lex->flags.noops = false;
+        if (!parser_next(parser) || parser->tok != TOKEN_STRINGCONST) {
+            parseerror(parser, "expected a constant string in translatable-string extension");
+            return false;
+        }
+        val = parser_const_string(parser, parser_tokval(parser), true);
+        if (!val)
+            return false;
+        vec_push(sy->out, syexp(parser_ctx(parser), (ast_expression*)val));
 
-            if (!parser_next(parser) || parser->tok != ')') {
-                parseerror(parser, "expected closing paren after translatable string");
-                goto onerr;
-            }
+        if (!parser_next(parser) || parser->tok != ')') {
+            parseerror(parser, "expected closing paren after translatable string");
+            return false;
+        }
+        return true;
+    }
+    else if (parser->tok == TOKEN_DOTS)
+    {
+        ast_expression *va;
+        if (!OPTS_FLAG(VARIADIC_ARGS)) {
+            parseerror(parser, "cannot access varargs (try -fvariadic-args)");
+            return false;
         }
-        else if (parser->tok == TOKEN_DOTS)
+        va = parse_vararg(parser);
+        if (!va)
+            return false;
+        vec_push(sy->out, syexp(parser_ctx(parser), va));
+        return true;
+    }
+    else if (parser->tok == TOKEN_FLOATCONST) {
+        ast_value *val;
+        val = parser_const_float(parser, (parser_token(parser)->constval.f));
+        if (!val)
+            return false;
+        vec_push(sy->out, syexp(parser_ctx(parser), (ast_expression*)val));
+        return true;
+    }
+    else if (parser->tok == TOKEN_INTCONST || parser->tok == TOKEN_CHARCONST) {
+        ast_value *val;
+        val = parser_const_float(parser, (double)(parser_token(parser)->constval.i));
+        if (!val)
+            return false;
+        vec_push(sy->out, syexp(parser_ctx(parser), (ast_expression*)val));
+        return true;
+    }
+    else if (parser->tok == TOKEN_STRINGCONST) {
+        ast_value *val;
+        val = parser_const_string(parser, parser_tokval(parser), false);
+        if (!val)
+            return false;
+        vec_push(sy->out, syexp(parser_ctx(parser), (ast_expression*)val));
+        return true;
+    }
+    else if (parser->tok == TOKEN_VECTORCONST) {
+        ast_value *val;
+        val = parser_const_vector(parser, parser_token(parser)->constval.v);
+        if (!val)
+            return false;
+        vec_push(sy->out, syexp(parser_ctx(parser), (ast_expression*)val));
+        return true;
+    }
+    else if (parser->tok == TOKEN_IDENT)
+    {
+        const char     *ctoken = parser_tokval(parser);
+        ast_expression *prev = vec_size(sy->out) ? vec_last(sy->out).out : NULL;
+        ast_expression *var;
+        /* a_vector.{x,y,z} */
+        if (!vec_size(sy->ops) ||
+            !vec_last(sy->ops).etype ||
+            operators[vec_last(sy->ops).etype-1].id != opid1('.') ||
+            (prev >= intrinsic_debug_typestring &&
+             prev <= intrinsic_debug_typestring))
         {
-            ast_expression *va;
-            if (!OPTS_FLAG(VARIADIC_ARGS)) {
-                parseerror(parser, "cannot access varargs (try -fvariadic-args)");
-                goto onerr;
-            }
-            if (wantop) {
-                parseerror(parser, "expected operator or end of statement");
-                goto onerr;
-            }
-            wantop = true;
-            va = parse_vararg(parser);
-            if (!va)
-                goto onerr;
-            vec_push(sy.out, syexp(parser_ctx(parser), va));
-            DEBUGSHUNTDO(con_out("push `...`\n"));
+            /* When adding more intrinsics, fix the above condition */
+            prev = NULL;
         }
-        else if (parser->tok == TOKEN_IDENT)
+        if (prev && prev->expression.vtype == TYPE_VECTOR && ctoken[0] >= 'x' && ctoken[0] <= 'z' && !ctoken[1])
         {
-            const char     *ctoken = parser_tokval(parser);
-            ast_expression *prev = vec_size(sy.out) ? vec_last(sy.out).out : NULL;
-            ast_expression *var;
-            if (wantop) {
-                parseerror(parser, "expected operator or end of statement");
-                goto onerr;
+            var = (ast_expression*)parser->const_vec[ctoken[0]-'x'];
+        } else {
+            var = parser_find_var(parser, parser_tokval(parser));
+            if (!var)
+                var = parser_find_field(parser, parser_tokval(parser));
+        }
+        if (!var && with_labels) {
+            var = (ast_expression*)parser_find_label(parser, parser_tokval(parser));
+            if (!with_labels) {
+                ast_label *lbl = ast_label_new(parser_ctx(parser), parser_tokval(parser), true);
+                var = (ast_expression*)lbl;
+                vec_push(parser->labels, lbl);
             }
-            wantop = true;
-            /* a_vector.{x,y,z} */
-            if (!vec_size(sy.ops) ||
-                !vec_last(sy.ops).etype ||
-                operators[vec_last(sy.ops).etype-1].id != opid1('.') ||
-                (prev >= intrinsic_debug_typestring &&
-                 prev <= intrinsic_debug_typestring))
-            {
-                /* When adding more intrinsics, fix the above condition */
-                prev = NULL;
+        }
+        if (!var) {
+            /* intrinsics */
+            if (!strcmp(parser_tokval(parser), "__builtin_debug_typestring")) {
+                var = (ast_expression*)intrinsic_debug_typestring;
             }
-            if (prev && prev->expression.vtype == TYPE_VECTOR && ctoken[0] >= 'x' && ctoken[0] <= 'z' && !ctoken[1])
+            else
             {
-                var = (ast_expression*)parser->const_vec[ctoken[0]-'x'];
-            } else {
-                var = parser_find_var(parser, parser_tokval(parser));
-                if (!var)
-                    var = parser_find_field(parser, parser_tokval(parser));
-            }
-            if (!var && with_labels) {
-                var = (ast_expression*)parser_find_label(parser, parser_tokval(parser));
-                if (!with_labels) {
-                    ast_label *lbl = ast_label_new(parser_ctx(parser), parser_tokval(parser), true);
-                    var = (ast_expression*)lbl;
-                    vec_push(parser->labels, lbl);
-                }
-            }
-            if (!var) {
-                /* intrinsics */
-                if (!strcmp(parser_tokval(parser), "__builtin_debug_typestring")) {
-                    var = (ast_expression*)intrinsic_debug_typestring;
-                }
-                else
-                {
-                    char *correct = NULL;
-
-                    /*
-                     * sometimes people use preprocessing predefs without enabling them
-                     * i've done this thousands of times already myself.  Lets check for
-                     * it in the predef table.  And diagnose it better :)
-                     */
-                    if (!OPTS_FLAG(FTEPP_PREDEFS)) {
-                        for (i = 0; i < sizeof(ftepp_predefs)/sizeof(*ftepp_predefs); i++) {
-                            if (!strcmp(ftepp_predefs[i].name, parser_tokval(parser))) {
-                                parseerror(parser, "unexpected ident: %s (use -fftepp-predef to enable pre-defined macros)", parser_tokval(parser));
-                                goto onerr;
-                            }
+                char *correct = NULL;
+                size_t i;
+
+                /*
+                 * sometimes people use preprocessing predefs without enabling them
+                 * i've done this thousands of times already myself.  Lets check for
+                 * it in the predef table.  And diagnose it better :)
+                 */
+                if (!OPTS_FLAG(FTEPP_PREDEFS)) {
+                    for (i = 0; i < sizeof(ftepp_predefs)/sizeof(*ftepp_predefs); i++) {
+                        if (!strcmp(ftepp_predefs[i].name, parser_tokval(parser))) {
+                            parseerror(parser, "unexpected ident: %s (use -fftepp-predef to enable pre-defined macros)", parser_tokval(parser));
+                            return false;
                         }
                     }
+                }
 
-                    /*
-                     * TODO: determine the best score for the identifier: be it
-                     * a variable, a field.
-                     *
-                     * We should also consider adding correction tables for
-                     * other things as well.
-                     */
-                    if (opts.correction) {
-                        correction_t corr;
-                        correct_init(&corr);
-
-                        for (i = 0; i < vec_size(parser->correct_variables); i++) {
-                            correct = correct_str(&corr, parser->correct_variables[i], parser_tokval(parser));
-                            if (strcmp(correct, parser_tokval(parser))) {
-                                break;
-                            } else if (correct) {
-                                mem_d(correct);
-                                correct = NULL;
-                            }
-                        }
-                        correct_free(&corr);
-
-                        if (correct) {
-                            parseerror(parser, "unexpected ident: %s (did you mean %s?)", parser_tokval(parser), correct);
+                /*
+                 * TODO: determine the best score for the identifier: be it
+                 * a variable, a field.
+                 *
+                 * We should also consider adding correction tables for
+                 * other things as well.
+                 */
+                if (opts.correction) {
+                    correction_t corr;
+                    correct_init(&corr);
+
+                    for (i = 0; i < vec_size(parser->correct_variables); i++) {
+                        correct = correct_str(&corr, parser->correct_variables[i], parser_tokval(parser));
+                        if (strcmp(correct, parser_tokval(parser))) {
+                            break;
+                        } else if (correct) {
                             mem_d(correct);
-                            goto onerr;
+                            correct = NULL;
                         }
                     }
-                    parseerror(parser, "unexpected ident: %s", parser_tokval(parser));
-                    goto onerr;
-                }
-            }
-            else
-            {
-                if (ast_istype(var, ast_value)) {
-                    ((ast_value*)var)->uses++;
-                }
-                else if (ast_istype(var, ast_member)) {
-                    ast_member *mem = (ast_member*)var;
-                    if (ast_istype(mem->owner, ast_value))
-                        ((ast_value*)(mem->owner))->uses++;
+                    correct_free(&corr);
+
+                    if (correct) {
+                        parseerror(parser, "unexpected ident: %s (did you mean %s?)", parser_tokval(parser), correct);
+                        mem_d(correct);
+                        return false;
+                    }
                 }
+                parseerror(parser, "unexpected ident: %s", parser_tokval(parser));
+                return false;
             }
-            vec_push(sy.out, syexp(parser_ctx(parser), var));
-            DEBUGSHUNTDO(con_out("push %s\n", parser_tokval(parser)));
-        }
-        else if (parser->tok == TOKEN_FLOATCONST) {
-            ast_value *val;
-            if (wantop) {
-                parseerror(parser, "expected operator or end of statement, got constant");
-                goto onerr;
-            }
-            wantop = true;
-            val = parser_const_float(parser, (parser_token(parser)->constval.f));
-            if (!val)
-                return NULL;
-            vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
-            DEBUGSHUNTDO(con_out("push %g\n", parser_token(parser)->constval.f));
-        }
-        else if (parser->tok == TOKEN_INTCONST || parser->tok == TOKEN_CHARCONST) {
-            ast_value *val;
-            if (wantop) {
-                parseerror(parser, "expected operator or end of statement, got constant");
-                goto onerr;
-            }
-            wantop = true;
-            val = parser_const_float(parser, (double)(parser_token(parser)->constval.i));
-            if (!val)
-                return NULL;
-            vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
-            DEBUGSHUNTDO(con_out("push %i\n", parser_token(parser)->constval.i));
-        }
-        else if (parser->tok == TOKEN_STRINGCONST) {
-            ast_value *val;
-            if (wantop) {
-                parseerror(parser, "expected operator or end of statement, got constant");
-                goto onerr;
-            }
-            wantop = true;
-            val = parser_const_string(parser, parser_tokval(parser), false);
-            if (!val)
-                return NULL;
-            vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
-            DEBUGSHUNTDO(con_out("push string\n"));
-        }
-        else if (parser->tok == TOKEN_VECTORCONST) {
-            ast_value *val;
-            if (wantop) {
-                parseerror(parser, "expected operator or end of statement, got constant");
-                goto onerr;
-            }
-            wantop = true;
-            val = parser_const_vector(parser, parser_token(parser)->constval.v);
-            if (!val)
-                return NULL;
-            vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
-            DEBUGSHUNTDO(con_out("push '%g %g %g'\n",
-                                parser_token(parser)->constval.v.x,
-                                parser_token(parser)->constval.v.y,
-                                parser_token(parser)->constval.v.z));
         }
-        else if (parser->tok == '(') {
-            parseerror(parser, "internal error: '(' should be classified as operator");
-            goto onerr;
-        }
-        else if (parser->tok == '[') {
-            parseerror(parser, "internal error: '[' should be classified as operator");
-            goto onerr;
-        }
-        else if (parser->tok == ')') {
-            if (wantop) {
-                DEBUGSHUNTDO(con_out("do[op] )\n"));
-                --parens;
-                if (parens < 0)
-                    break;
-                /* we do expect an operator next */
-                /* closing an opening paren */
-                if (!parser_close_paren(parser, &sy, false))
-                    goto onerr;
-                if (vec_last(parser->pot) != POT_PAREN) {
-                    parseerror(parser, "mismatched parentheses (closing paren during ternary expression?)");
-                    goto onerr;
-                }
-                vec_pop(parser->pot);
-            } else {
-                DEBUGSHUNTDO(con_out("do[nop] )\n"));
-                --parens;
-                if (parens < 0)
-                    break;
-                /* allowed for function calls */
-                if (!parser_close_paren(parser, &sy, true))
-                    goto onerr;
-                if (vec_last(parser->pot) != POT_PAREN) {
-                    parseerror(parser, "mismatched parentheses (closing paren during ternary expression?)");
-                    goto onerr;
-                }
-                vec_pop(parser->pot);
+        else
+        {
+            if (ast_istype(var, ast_value)) {
+                ((ast_value*)var)->uses++;
             }
-            wantop = true;
-        }
-        else if (parser->tok == ']') {
-            if (!wantop)
-                parseerror(parser, "operand expected");
-            --parens;
-            if (parens < 0)
-                break;
-            if (!parser_close_paren(parser, &sy, false))
-                goto onerr;
-            if (vec_last(parser->pot) != POT_PAREN) {
-                parseerror(parser, "mismatched parentheses (closing paren during ternary expression?)");
-                goto onerr;
+            else if (ast_istype(var, ast_member)) {
+                ast_member *mem = (ast_member*)var;
+                if (ast_istype(mem->owner, ast_value))
+                    ((ast_value*)(mem->owner))->uses++;
             }
-            vec_pop(parser->pot);
-            wantop = true;
         }
-        else if (parser->tok == TOKEN_TYPENAME) {
+        vec_push(sy->out, syexp(parser_ctx(parser), var));
+        return true;
+    }
+    parseerror(parser, "unexpected token `%s`", parser_tokval(parser));
+    return false;
+}
+
+static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels)
+{
+    ast_expression *expr = NULL;
+    shunt sy;
+    size_t i;
+    bool wantop = false;
+    /* only warn once about an assignment in a truth value because the current code
+     * would trigger twice on: if(a = b && ...), once for the if-truth-value, once for the && part
+     */
+    bool warn_truthvalue = true;
+
+    /* count the parens because an if starts with one, so the
+     * end of a condition is an unmatched closing paren
+     */
+    int ternaries = 0;
+
+    memset(&sy, 0, sizeof(sy));
+
+    parser->lex->flags.noops = false;
+
+    parser_reclassify_token(parser);
+
+    while (true)
+    {
+        if (parser->tok == TOKEN_TYPENAME) {
             parseerror(parser, "unexpected typename");
             goto onerr;
         }
-        else if (parser->tok != TOKEN_OPERATOR) {
-            if (wantop) {
-                parseerror(parser, "expected operator or end of statement");
-                goto onerr;
-            }
-            break;
-        }
-        else
+
+        if (parser->tok == TOKEN_OPERATOR)
         {
             /* classify the operator */
             const oper_info *op;
@@ -2002,7 +1888,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             op = &operators[o];
 
             /* when declaring variables, a comma starts a new variable */
-            if (op->id == opid1(',') && !parens && stopatcomma) {
+            if (op->id == opid1(',') && !vec_size(sy.paren) && stopatcomma) {
                 /* fixup the token */
                 parser->tok = ',';
                 break;
@@ -2015,12 +1901,12 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             }
 
             if (op->id == opid1(',')) {
-                if (vec_size(parser->pot) && vec_last(parser->pot) == POT_TERNARY2) {
+                if (vec_size(sy.paren) && vec_last(sy.paren) == PAREN_TERNARY2) {
                     (void)!parsewarning(parser, WARN_TERNARY_PRECEDENCE, "suggesting parenthesis around ternary expression");
                 }
             }
 
-            if (vec_size(sy.ops) && !vec_last(sy.ops).paren)
+            if (vec_size(sy.ops) && !vec_last(sy.ops).isparen)
                 olast = &operators[vec_last(sy.ops).etype-1];
 
 #define IsAssignOp(x) (\
@@ -2037,7 +1923,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             if (warn_truthvalue) {
                 if ( (olast && IsAssignOp(olast->id) && (op->id == opid2('&','&') || op->id == opid2('|','|'))) ||
                      (olast && IsAssignOp(op->id) && (olast->id == opid2('&','&') || olast->id == opid2('|','|'))) ||
-                     (truthvalue && !vec_size(parser->pot) && IsAssignOp(op->id))
+                     (truthvalue && !vec_size(sy.paren) && IsAssignOp(op->id))
                    )
                 {
                     (void)!parsewarning(parser, WARN_PARENTHESIS, "suggesting parenthesis around assignment used as truth value");
@@ -2051,7 +1937,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             {
                 if (!parser_sy_apply_operator(parser, &sy))
                     goto onerr;
-                if (vec_size(sy.ops) && !vec_last(sy.ops).paren)
+                if (vec_size(sy.ops) && !vec_last(sy.ops).isparen)
                     olast = &operators[vec_last(sy.ops).etype-1];
                 else
                     olast = NULL;
@@ -2060,14 +1946,13 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             if (op->id == opid1('(')) {
                 if (wantop) {
                     size_t sycount = vec_size(sy.out);
-                    DEBUGSHUNTDO(con_out("push [op] (\n"));
-                    ++parens; vec_push(parser->pot, POT_PAREN);
                     /* we expected an operator, this is the function-call operator */
-                    vec_push(sy.ops, syparen(parser_ctx(parser), SY_PAREN_FUNC, sycount-1));
+                    vec_push(sy.paren, PAREN_FUNC);
+                    vec_push(sy.ops, syparen(parser_ctx(parser), sycount-1));
+                    vec_push(sy.argc, 0);
                 } else {
-                    ++parens; vec_push(parser->pot, POT_PAREN);
-                    vec_push(sy.ops, syparen(parser_ctx(parser), SY_PAREN_EXPR, 0));
-                    DEBUGSHUNTDO(con_out("push [nop] (\n"));
+                    vec_push(sy.paren, PAREN_EXPR);
+                    vec_push(sy.ops, syparen(parser_ctx(parser), 0));
                 }
                 wantop = false;
             } else if (op->id == opid1('[')) {
@@ -2075,42 +1960,104 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
                     parseerror(parser, "unexpected array subscript");
                     goto onerr;
                 }
-                ++parens; vec_push(parser->pot, POT_PAREN);
+                vec_push(sy.paren, PAREN_INDEX);
                 /* push both the operator and the paren, this makes life easier */
                 vec_push(sy.ops, syop(parser_ctx(parser), op));
-                vec_push(sy.ops, syparen(parser_ctx(parser), SY_PAREN_INDEX, 0));
+                vec_push(sy.ops, syparen(parser_ctx(parser), 0));
                 wantop = false;
             } else if (op->id == opid2('?',':')) {
                 vec_push(sy.ops, syop(parser_ctx(parser), op));
-                vec_push(sy.ops, syparen(parser_ctx(parser), SY_PAREN_TERNARY, 0));
+                vec_push(sy.ops, syparen(parser_ctx(parser), 0));
                 wantop = false;
                 ++ternaries;
-                vec_push(parser->pot, POT_TERNARY1);
+                vec_push(sy.paren, PAREN_TERNARY1);
             } else if (op->id == opid2(':','?')) {
-                if (!vec_size(parser->pot)) {
+                if (!vec_size(sy.paren)) {
                     parseerror(parser, "unexpected colon outside ternary expression (missing parenthesis?)");
                     goto onerr;
                 }
-                if (vec_last(parser->pot) != POT_TERNARY1) {
+                if (vec_last(sy.paren) != PAREN_TERNARY1) {
                     parseerror(parser, "unexpected colon outside ternary expression (missing parenthesis?)");
                     goto onerr;
                 }
-                if (!parser_close_paren(parser, &sy, false))
+                if (!parser_close_paren(parser, &sy))
                     goto onerr;
                 vec_push(sy.ops, syop(parser_ctx(parser), op));
                 wantop = false;
                 --ternaries;
             } else {
-                DEBUGSHUNTDO(con_out("push operator %s\n", op->op));
                 vec_push(sy.ops, syop(parser_ctx(parser), op));
                 wantop = !!(op->flags & OP_SUFFIX);
             }
         }
+        else if (parser->tok == ')') {
+            while (vec_size(sy.paren) && vec_last(sy.paren) == PAREN_TERNARY2) {
+                if (!parser_sy_apply_operator(parser, &sy))
+                    goto onerr;
+            }
+            if (!vec_size(sy.paren))
+                break;
+            if (wantop) {
+                if (vec_last(sy.paren) == PAREN_TERNARY1) {
+                    parseerror(parser, "mismatched parentheses (closing paren in ternary expression?)");
+                    goto onerr;
+                }
+                if (!parser_close_paren(parser, &sy))
+                    goto onerr;
+            } else {
+                /* must be a function call without parameters */
+                if (vec_last(sy.paren) != PAREN_FUNC) {
+                    parseerror(parser, "closing paren in invalid position");
+                    goto onerr;
+                }
+                if (!parser_close_paren(parser, &sy))
+                    goto onerr;
+            }
+            wantop = true;
+        }
+        else if (parser->tok == '(') {
+            parseerror(parser, "internal error: '(' should be classified as operator");
+            goto onerr;
+        }
+        else if (parser->tok == '[') {
+            parseerror(parser, "internal error: '[' should be classified as operator");
+            goto onerr;
+        }
+        else if (parser->tok == ']') {
+            while (vec_size(sy.paren) && vec_last(sy.paren) == PAREN_TERNARY2) {
+                if (!parser_sy_apply_operator(parser, &sy))
+                    goto onerr;
+            }
+            if (!vec_size(sy.paren))
+                break;
+            if (vec_last(sy.paren) != PAREN_INDEX) {
+                parseerror(parser, "mismatched parentheses, unexpected ']'");
+                goto onerr;
+            }
+            if (!parser_close_paren(parser, &sy))
+                goto onerr;
+            wantop = true;
+        }
+        else if (!wantop) {
+            if (!parse_sya_operand(parser, &sy, with_labels))
+                goto onerr;
+#if 0
+            if (vec_size(sy.paren) && vec_last(sy.ops).isparen && vec_last(sy.paren) == PAREN_FUNC)
+                vec_last(sy.argc)++;
+#endif
+            wantop = true;
+        }
+        else {
+            parseerror(parser, "expected operator or end of statement");
+            goto onerr;
+        }
+
         if (!parser_next(parser)) {
             goto onerr;
         }
         if (parser->tok == ';' ||
-            (!parens && (parser->tok == ']' || parser->tok == ')' || parser->tok == '}')))
+            ((!vec_size(sy.paren) || (vec_size(sy.paren) == 1 && vec_last(sy.paren) == PAREN_TERNARY2)) &&
+            (parser->tok == ']' || parser->tok == ')' || parser->tok == '}')))
         {
             break;
         }
@@ -2129,12 +2076,12 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
         expr = sy.out[0].out;
     vec_free(sy.out);
     vec_free(sy.ops);
-    DEBUGSHUNTDO(con_out("shunt done\n"));
-    if (vec_size(parser->pot)) {
-        parseerror(parser, "internal error: vec_size(parser->pot) = %lu", (unsigned long)vec_size(parser->pot));
+    if (vec_size(sy.paren)) {
+        parseerror(parser, "internal error: vec_size(sy.paren) = %lu", (unsigned long)vec_size(sy.paren));
         return NULL;
     }
-    vec_free(parser->pot);
+    vec_free(sy.paren);
+    vec_free(sy.argc);
     return expr;
 
 onerr:
@@ -2145,6 +2092,8 @@ onerr:
     }
     vec_free(sy.out);
     vec_free(sy.ops);
+    vec_free(sy.paren);
+    vec_free(sy.argc);
     return NULL;
 }
 
@@ -4065,6 +4014,8 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
             goto enderrfn;
         }
         func->varargs = varargs;
+
+        func->fixedparams = parser_const_float(parser, vec_size(var->expression.params));
     }
 
     parser->function = func;
@@ -5461,7 +5412,7 @@ skipvar:
                 }
             } else {
                 int cvq;
-                shunt sy = { NULL, NULL };
+                shunt sy = { NULL, NULL, NULL, NULL };
                 cvq = var->cvq;
                 var->cvq = CV_NONE;
                 vec_push(sy.out, syexp(ast_ctx(var), (ast_expression*)var));
diff --git a/tests/parens.qc b/tests/parens.qc
new file mode 100644 (file)
index 0000000..1ae09a0
--- /dev/null
@@ -0,0 +1,44 @@
+void(string...)   print  = #1;
+string(float)     ftos   = #2;
+
+float arr[2];
+
+string gets() { return "S\n"; }
+void main(float x) {
+    string s;
+
+    s = gets();                // 0 params
+    print(s);                  // 1 param
+    print("A ", "B\n");        // 2 params
+    print("A ", "B ", "C\n");  // more params
+    print(gets());             // 0-param call in call
+    print(gets(), "next\n");   // 0-param call and another
+    print("-> ", gets());      // param + 0-param call
+    print(ftos(x), "\n");      // param-call + another
+    print(x ? "xA\n" : "xB\n");      // ternary in PAREN_FUNC
+    print(!x ? "xA\n" : "xB\n");      // ternary in PAREN_FUNC
+    // PAREN_INDEX
+    arr[0] = 10;
+    arr[1] = 11;
+    // PAREN_TERNARY + PAREN_INDEX
+    arr[x ? 0 : 1] += 100;
+    print(ftos(arr[0]), "\n");
+    print(ftos(arr[1]), "\n");
+    print(ftos(arr[x ? 0 : 1]), "\n");
+    print(ftos(arr[!x ? 0 : 1]), "\n");
+
+    // loops with comma operators
+    float i, j;
+    for (i = 0, j = 0; i < x; ++i)
+        print("-");
+    print("\n");
+
+    // if + PAREN_TERNARY2
+    if (x ? 1 : 0)
+        print("OK\n");
+    if (x ? 0 : 1)
+        print("NO\n");
+
+    // PAREN_FUNC in PAREN_EXPR
+    print(("Is this wrong ", "now?\n"));
+}
diff --git a/tests/parens.tmpl b/tests/parens.tmpl
new file mode 100644 (file)
index 0000000..504082f
--- /dev/null
@@ -0,0 +1,22 @@
+I: parens.qc
+D: parentheses, SYA stuff
+T: -execute
+C: -std=fteqcc
+E: -float 4
+M: S
+M: A B
+M: A B C
+M: S
+M: S
+M: next
+M: -> S
+M: 4
+M: xA
+M: xB
+M: 110
+M: 11
+M: 110
+M: 11
+M: ----
+M: OK
+M: now?
index ffe7d1b6b34b152ffa9b2a12751f6302464a0f70..89cb5b8d6bf5c35781965177441ae6dca756d326 100644 (file)
@@ -9,6 +9,15 @@ void nbva(float a, string...count) {
         print("Vararg ", ftos(a), " = ", ...(a, string), "\n");
 }
 
+var void unstable(...);
+void stability(float a, float b, ...count)
+{
+    print("Got: ", ftos(count), "\n");
+}
+
 void main() {
     nbva(1, "Hello", "You", "There");
+    stability(1, 2, 3, 4, 5);
+    unstable = stability;
+    unstable(1, 2, 3, 4, 5);
 }
index d8130a83ba083644d79183d271f7e23518c16aaa..29de939ea8a4ad9ee2f16ac01ae08dbbe02a18f2 100644 (file)
@@ -8,3 +8,5 @@ M: You chose: You
 M: Vararg 0 = Hello
 M: Vararg 1 = You
 M: Vararg 2 = There
+M: Got: 3
+M: Got: 3