Commit graph

14501 commits

Author SHA1 Message Date
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
0424e9b798 [gamecode] Fix a silly typo in a macro
It doesn't really affect anything since it's just the parameter name in
an empty function-type macro, but "event" instead of "type" isn't
particularly conducive to self-documenting code.
2024-08-17 15:22:09 +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
295d463607 [io_qfmap] File off a pile of bitrot
While much is broken, especially textures, e4m8.map successfully imports
into blender 4.2-ish, and even the entity relation lines seem to work
(which surprised me as those were the first sign of trouble).
2024-08-11 20:46:55 +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
4fd3d972af [gatest] Correct and clean up Hodge calculation
I had a few signs flipped, I think, but this version is much easier to
read.
2024-06-23 13:25:27 +09:00
Bill Currie
5771cfb2ff [gatest] Use correct layout for multivector reverse
This fixes a bit of fun with reversing directly specified blades.
2024-06-23 13:19:16 +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
2b70eaa85e [build] Fix some config errors found by gcc 14
Or more realistically, attempting to use gcc 14 (it ICEs, so can't be
used yet).
2024-05-26 15:06:03 +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
Bill Currie
28bba12e87 [qfcc] Rename some functions
One a typo, the other for better consistency.
2024-05-04 10:50:08 +09:00
Bill Currie
1567f29668 [qfcc] Handle type expressions when merging specifiers
The type expressions no longer get lost along the way to the function
return type and parameter types.
2024-05-03 19:43:58 +09:00
Bill Currie
aff70aa243 [qfcc] Support static type expressions in declarations
This allows types in declarations to be based on other types:

    int foo[3];
    @vector(float,sizeof(foo)) bar;
2024-05-03 19:37:11 +09:00
Bill Currie
fed1bce12a [qfcc] Add a function to check for error expressions
I haven't gone through and replaced all the existing tests, but hiding
the details makes sense and fits with many of the other check functions.
2024-04-30 11:16:27 +09:00
Bill Currie
f7bf77c2b7 [qfcc] Support type expressions in dot output
The graph isn't great, but it's better than invalid expression nodes.
2024-04-30 11:16:27 +09:00
Bill Currie
60730a5b12 [qfcc] Prevent dags in type expressions
While they might be ok, I expect them to cause some issues when doing
compile-time evaluations of type expressions, so use of dags seems to be
a premature optimization. However, as the "no dags" flag is propagated
to parent expression nodes, it may prove useful in other contexts.
2024-04-30 10:58:51 +09:00
Bill Currie
966275c294 [qfcc] Remove symbol field from param_t
I have no idea what it was for as nothing actually uses it.
2024-04-26 23:24:32 +09:00
Bill Currie
e8da9924c0 [qfcc] Rework type expression handling
The expression grammar has been tidied up and some basic checks are made
of parameters to the type functions. Also, type parameters are looked up
so parsing now works properly. However, the type parameters are not used
correctly, so function generation doesn't work.
2024-04-26 23:24:32 +09:00