Commit graph

14480 commits

Author SHA1 Message Date
Bill Currie
f335540e99 [qfcc] Handle glsl version and extension directives
The version directive really does only some error checking, and
only GL_EXT_multiview and GL_GOOGLE_include_directive are supported for
extensions, but enable/disable work (but not yet warn for multiview).
2024-09-01 17:01:05 +09:00
Bill Currie
cba28e9421 [qfcc] Use correct flags for in and uniform
They're not actually constant (in the usual sense), just read-only.
Fixes an internal error when accessing an unsigned array.
2024-09-01 16:40:47 +09:00
Bill Currie
a24d1d799f [qfcc] Use a stack for cpp_quote_start
Using set_line_file sort of worked with its stack, but line directives
embedded in the source (which glsl's initialization code uses) messed up
the start path for quoted include searches.
2024-08-31 13:01:26 +09:00
Bill Currie
9b2b841a55 [qfcc] Redo interface blocks as namespaces
There's no direct support for namespaces in Ruamoko yet, nor even in
qfcc, but glsl's blocks bring in a bit of foundation for them, even the
concept of "using" (for blocks with no instance name).

The members don't get locations allocated to them yet, but
fstrianglest.vert compiles and links correctly otherwise.

Also, there's no error checking yet.
2024-08-31 10:32:00 +09:00
Bill Currie
291898b46f [qfcc] Properly dup symbol for declaration
The unification of qc and c function symbol handling made it important
that the new symbol was a proper duplicate (minus being in a table) of
the old symbol. This fixes redeclared prototypes (especially for
qc-style functions, not encountered for c-style). Complete with unit
test :)
2024-08-30 21:45:37 +09:00
Bill Currie
ee6e38e2f9 [qfcc] Implement glsl's contructors for math types
I don't think this includes bools yet, and matrices aren't supported
yet, but float vectors work quite nicely.
2024-08-30 13:54:33 +09:00
Bill Currie
d0064c6c46 [qfcc] Implement a lot of glsl semantics
Other than contructors (and problems with the `out` block) qfcc can
compile fstrianglest.vert to what looks like working ruamoko code.
There's still a lot of work to do, though.
2024-08-30 13:51:31 +09:00
Bill Currie
4b369be8c1 [qfcc] Report correct type in enum/struct redefinitions
Enums are neither unions or structs.
2024-08-30 13:47:36 +09:00
Bill Currie
6d9e2bd926 [qfcc] Allow a single void typed parameter
It makes dealing with `foo(void)` a little easier in glsl's parser.
2024-08-30 13:32:32 +09:00
Bill Currie
1510d21cde [qfcc] Implement is_matrix correctly
There was a FIXME from before I'd figured out how I wanted to deal with
them. Now is_matrix returns true only if there's at least 2 columns.
2024-08-30 13:17:43 +09:00
Bill Currie
bca4d0e794 [qfcc] Implement location printing for the parsers
It's pretty bare-bones, but it's at least consistent across all the
parsers, and it's currently used only by the parser debug support.
2024-08-30 13:13:13 +09:00
Bill Currie
daaaeb9aed [qfcc] Abort qfo loading if file is too small
Or really, if Qfilesize thinks it's too small. Trying to allocate -1
bytes (due to trying to open / as a qfo) didn't end well.
2024-08-29 01:04:52 +09:00
Bill Currie
b302ce1095 [qfcc] Hook up glsl builtin variables
They get parsed, but nothing gets defined yet, but this proved to be a
good test for rua_parse_string().
2024-08-28 13:53:30 +09:00
Bill Currie
de6a3c5702 [qfcc] Support parsing Ruamoko from strings
Handy for parsing builtin symbols for things like glsl.
2024-08-28 13:50:36 +09:00
Bill Currie
4be1384701 [qfcc] Improve language selection
Using a struct with function pointers instead of switching on an enum
makes it much easier to add languages and, more importantly,
sub-languages like glsl's shader stage variants.
2024-08-28 10:18:21 +09:00
Bill Currie
bbb90ce27a [qfcc] Clone metafunc for generated generic symbols
Simply referencing the original metafunc resulted in only the first
variant getting a def. Now my little test generates defs for all called
variants of a generic function.

However, I'm still not sure this is quite the direction I want to go
with making calls to generic functions, but I still need to figure out
defining them. I think making progress with the glsl front-end will
help.
2024-08-28 09:03:56 +09:00
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
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