Commit graph

3432 commits

Author SHA1 Message Date
Bill Currie
4f5fcbd819 [qfcc] Check all generic function variants for dups
Checking only the last function to be added results in false negatives
and thus duplicates when defining a generic function. eg:

    genFType radians (genFType degrees);
    genDType radians (genDType degrees);
    genFType radians (genFType degrees) = #0;
    genDType radians (genDType degrees) = #0;
2024-08-27 14:41:38 +09:00
Bill Currie
c236129bbe [qfcc] Parse generic functions early
Detecting generic functions needs to be done before finalizing the
function type for non-generic functions, otherwise the resulting
function type winds up being incorrect due to bogus resolution of the
return type (and probably a few other factors).
This takes care of handling the return type in function definitions as
well as declarations as
2024-08-27 14:37:18 +09:00
Bill Currie
27286389d1 [qfcc] Isolate functions from symbols
Symbols now use metafunc_t to reference functions, which should make
working with generic and overloaded functions easier.
2024-08-26 15:50:27 +09:00
Bill Currie
8eae02209e [qfcc] Unify qc and c function symbol handling
This gets all the function symbol type handling into the one place,
which will make dealing with generic functions much easier.
2024-08-26 12:58:39 +09:00
Bill Currie
80df79a62f [qfcc] Be more clear about the builtin id parameter
While `expr` is better than `$n`, `bi_val` seems even better at
conveying meaning.
2024-08-26 10:31:57 +09:00
Bill Currie
3abf69cb36 [qfcc] Report errors accessing source files
This got lost in the switch to internal preprocessing as cpp used to do
the job for us.
2024-08-21 16:12:52 +09:00
Bill Currie
6a70ecda9d [qfcc] Make default_type take const symbol_t
It doesn't need to modify sym, and being const makes it more clear that
it doesn't (despite some of the other type functions breaking that rule,
ugh).
2024-08-21 08:30:15 +09:00
Bill Currie
43f83fc0eb [qfcc] Clean up some redundancy in methodproto
I don't know why I didn't apply the same ideas as in methoddef, maybe I
just forgot. I'm pretty sure I did methodproto first, or maybe cleaned
up methoddef much later then didn't think of methodproto. Still, the
grammar is much nicer to read now.
2024-08-21 08:26:31 +09:00
Bill Currie
a00b17bf71 [qfcc] Check declarator type chains
Arrays of functions or functions that return arrays or functions aren't
valid. While working on how to get generics in properly, I finally
understood what's going on with function types in the specifier, and I
think I'll be able to sort out function pointers vs prototypes, too.
2024-08-21 08:23:12 +09:00
Bill Currie
856761c4a9 [qfcc] Add to a FIXME comment 2024-08-20 20:20:05 +09:00
Bill Currie
5e6832294e [qfcc] Handle parsing generic builtin functions
Generic qc-style prototypes don't work but both c and qc style
definitions get as far as trying to build the builtin function. It
starting to look like I need to rework function handling, which isn't
all that surprising as it hasn't changed much over 22 years.
2024-08-20 15:19:31 +09:00
Bill Currie
219f2f26da [qfcc] Add is_double_val check
I wound up not using it, but I'll probably want it eventually..
2024-08-20 15:16:25 +09:00
Bill Currie
b8fe10f8a5 [qfcc] Limit builtin numbers to ints
Or whole-number floats for v6 progs.
2024-08-20 15:13:57 +09:00
Bill Currie
7f021b074c [qfcc] Treat fp constants as float for v6 progs
v6 progs don't support doubles, so demote double suffices to float, and
treat implicit fp constants as float.
2024-08-20 14:49:24 +09:00
Bill Currie
d9e2108b91 [qfcc] Return a metafunc for generic functions
One step closer to getting this idea to work.
2024-08-20 12:43:17 +09:00
Bill Currie
67c380e98d [qfcc] Clean up function.h a little
And even remove a dead function.
2024-08-20 09:26:24 +09:00
Bill Currie
0aab95eefe [qfcc] Rename overloaded_function_t to metafunc_t
I never did like overloaded_function_t as a name, and with the
introduction of generic functions (or templates, I guess?) meta-function
makes more sense to me.
2024-08-19 18:29:44 +09:00
Bill Currie
34b79ce783 [qfcc] Clean up some unnecessary type const casts
Most of them were noise from the type const correctness pass, but the
qc field function handling was always dubious (though in practice safe
due to how the type was built, but...). The remaining casts outside of
type.c need some thought.
2024-08-19 13:04:19 +09:00
Bill Currie
cdf49bb6b7 [qfprogs] Use a backup type array for qcc progs
I was investigating how qcc dealt with field fields and got segfaults
from qfprogs due to the lack of type encodings. While the resulting
output is not guaranteed to be correct (especially if trying to dump
progs compiled by some other extended compiler), at least it's better
than segfaulting or any other UB.
2024-08-17 15:16:09 +09:00
Bill Currie
9eb6aba02c [qfcc] Make the immediate union anonymous
Yay, no more annoying tags that served no real purpose (though they did
make some things a little easier, there's generally a better way).
2024-08-16 17:30:02 +09:00
Bill Currie
561f4c2ea0 [qfcc] Make the type union anonymous
This one has bothered me for a long time. I don't remember why it was
difficult at one stage, maybe I had some poor name choices.
2024-08-16 17:23:29 +09:00
Bill Currie
e5bd2591c2 [qfcc] Make the value union anonymous
Another little tag bites the dust.
2024-08-16 17:12:26 +09:00
Bill Currie
ce8c72c323 [qfcc] Make the symbol union anonymous
And now that little s. goes away. Yay, one bit less noise when reading
code.
2024-08-16 16:48:11 +09:00
Bill Currie
6bd26a0f61 [qfcc] Add some TODO items
They came up when talking about math with Darian
2024-08-12 08:51:39 +09:00
Bill Currie
e13dce882a [qfcc] Produce working calls to generic functions
There's still the problem of defining implementations, but this gets a
lot of things working so long as the return type is one of the parameter
types rather than computed.
2024-08-11 22:40:21 +09:00
Bill Currie
2cfc7a342d [qfcc] Update doc for recent lyx
And document type expressions to a certain extent. A lot of work needs
to be done as there's a lot of bitrot in the information in the doc (eg,
integer is now int, array declarations, etc).
2024-08-11 20:46:55 +09:00
Bill Currie
79c4eb531e [qfcc] Implement generic function resolution
A working call isn't produced yet, but the generic function does seem to
be selected correctly preferring a minimum of type promotions, though I
suspect I'll need to do more work on the selection process.
2024-08-11 20:46:55 +09:00
Bill Currie
cd973c6809 [qfcc] Tighten up type_promotes
Mainly to prevent promotion between different vector and matrix sizes,
but also to be consistent in that double doesn't promote to itself (same
as other scalar types). Also fix up type_rows and type_cols for matrices
and make type_assignable, type_promotes, and type_compatible null-safe
(always false if either src or dst is null).
2024-08-11 20:46:55 +09:00
Bill Currie
d0a9e1f54f [qfcc] Clean up function search a little
Still some ways to go, but this will help with implementing generic
function calls.
2024-08-11 20:46:55 +09:00
Bill Currie
66866f79b6 [qfcc] Expand @vector and @matrix type expressions
With this, genFType and genDType functions are now treated separately
and expanding to all components (single row or column matrices are not
supported (at this stage, anyway) for generic parameters).
2024-08-11 20:46:55 +09:00
Bill Currie
58bf1ee64e [qfcc] Support generic scope blocks
That is, `@generic(...) { ... };`, which is handy for bulk declarations
(such as for glsl). This proved to be a lot harder than expected, I
suspect handling of specifiers needs a lot of work.
2024-08-11 20:46:55 +09:00
Bill Currie
0d063c3290 [qfcc] Clean up specifier creation
I never did like all those cryptic parameters, especially when they were
just 0 and 1. Now the individual specifier creation functions take only
those parameters they need (if any) and there's no possibility of
conflicting parameters. Also, it's clearer what the new specifier does.
2024-08-11 20:46:55 +09:00
Bill Currie
fa3c872970 [qfcc] Add some comments about bvect and bvecp
I really need to come up with something better, but for now, just having
the terms recorded somewhere helps.
2024-08-11 20:46:55 +09:00
Bill Currie
f1afa1caf0 [qfcc] Parse generic function declarations
It doesn't properly differentiate between (treats genDType as being the
same as genFType):

    @generic(genFType=@vector(float)) genFType radians(genFType degrees);
    @generic(genDType=@vector(double)) genDType radians(genDType degrees);

but this is due to problems with how the type is built from
@vector(float) and @vector(double). However, I thought it was about time
I got some of this into git.

Also, `@generic(...) { ... };` blocks don't work properly (they lose the
generic info): need to get a little smarter about handling generic scope
in `external_def_list`.
2024-08-11 20:46:55 +09:00
Bill Currie
4c424fcb61 [qfcc] Add a check for bool types
And us it in matrix_type. Although there are no bool matrices even in
glsl, there are bool vectors and vector_type uses matrix_type.
2024-08-10 14:22:20 +09:00
Bill Currie
8fe23a29b3 [qfcc] Clean up some double semicolons
None of them really affected anything, but I have seen them cause
problems in the past.
2024-08-10 14:19:07 +09:00
Bill Currie
80e493e588 [qfcc] Parse generic function declaration
The parsed generic function declaration is for ease of matching call
signatures with the appropriate implementation.
2024-07-07 21:42:52 +09:00
Bill Currie
f2609b1a9b [qfcc] Make save_string null-safe
It simply returns nullptr when the saved string is null.
2024-07-07 15:18:51 +09:00
Bill Currie
628e3d2aed [qfcc] Make function type return type more clear
No more guessing if that's the functions return type or something else.
2024-07-07 15:17:06 +09:00
Bill Currie
c681d3ee28 [qfcc] Tidy up the doc structure a little
Talking about variables in the types section didn't make much sense.
2024-07-04 23:53:04 +09:00
Bill Currie
97e0427565 [qfcc] Ensure type expressions are resolved
Type expressions should be usable anywhere regular types can be used.
2024-07-04 23:44:07 +09:00
Bill Currie
f11f0c5477 [qfcc] Return an error expression for undefined symbols
Fixes some of the error spam that resulted from the expression
const-correctness pass a while back.
2024-07-04 23:23:06 +09:00
Bill Currie
b3fed7282e [qfcc] Make @function a type function
This fits in nicely with the rest of the generic type system and makes
it a little more useful. The idea is it will take a return type (already
does since type functions always require a parameter at this stage) and
a parameter list (not implemented yet). It currently resolves to the
basic void (...) function type for QC.
2024-05-31 16:39:50 +09:00
Bill Currie
a655e6cef3 [qfcc] Deal with generic types in prototypes
Mostly avoiding segfaults or mistreating type expressions as the default
type.
2024-05-31 13:51:38 +09:00
Bill Currie
8da8bd9917 [qfcc] Pass full specifier to function_symbol
With generic types, is_overload is no longer enough as the type
expression needs to be parsed in order to create the symbol.
2024-05-31 13:44:52 +09:00
Bill Currie
38b1d2d238 [qfcc] Clean up some bool types
It's true that true is more meaningful than 1.
2024-05-15 00:22:12 +09:00
Bill Currie
e295a62050 [qfcc] Clean up function code a little
Replace struct forward declarations and some non-locally (to use)
declared locals.
2024-05-12 12:48:50 +09:00
Bill Currie
99caaaa010 [qfcc] Remove redundant parameter
It turns out function_symbol was never called without allowing creation
of the symbol, so no need for the parameter.
2024-05-12 12:24:50 +09:00
Bill Currie
f7720a4e44 [qfcc] Preserve current function across function blocks
I'm not sure if I want to support nested functions in Ruamoko, but
handling them without segfaulting is far more important.
2024-05-05 16:46:53 +09:00
Bill Currie
b935540d19 [qfcc] Remove qc special function symbol functions
It turns out they're not needed as the difficulty of quakec function
declarations (function fields) is taken care of by qc_function_spec.
Also, they made it difficult to think about function declarations.
2024-05-04 22:08:38 +09:00