Commit graph

13357 commits

Author SHA1 Message Date
Bill Currie
dbd3d6502a Nuke qboolean from orbit
I never liked it, but with C2x coming out, it's best to handle bools
properly. I haven't gone through all the uses of int as bool (I'll leave
that for fixing when I encounter them), but this gets QF working with
both c2x (really, gnu2x because of raw strings).
2023-06-13 18:06:11 +09:00
Bill Currie
9871b44d68 [build] Fix a warning in attribute const check
The warning flag check worked too well: it enabled the warning and
autoconf's default main wanted the const attribute. The bug has been
floating around for a while, it seems.
2023-06-13 13:08:38 +09:00
Bill Currie
331f3320e2 [gatest] Rearrange the 2d PGA groups
Following the suggestions of Hamish Todd, group 0 forms the planar
quaternions (with the "complex number" in the first two components) and
transflections in group 1.
2023-06-08 22:46:02 +09:00
Bill Currie
0fbcd90e37 [gatest] Fix up layout issues for null vectors
e0 is created only if there are null vectors in the algebra, and the 3d
and 2d basis groups have been rearranged to compensate in the changed
ordering in the basis blade array.
2023-06-08 22:13:23 +09:00
Bill Currie
a40fee2513 [gatest] Calculate correct sign for duals
I was aware in the beginning that the signs were probably incorrect, but
I had left them as I wasn't sure how they worked.  Thanks to enki
(bivector community), I was pointed in the right direction for getting
the calculations right: the product of a basis blade with its dual
(x !x) must product the positive pseudo-scalar.
2023-06-08 13:02:13 +09:00
Bill Currie
2858870153 [gatest] Fix use of uninitialized multivector components
I guess I had forgotten that new_mv() does *NOT* initialize the
components. Things just happened to work (usually) because memory was
not getting recycled.
2023-06-08 13:00:32 +09:00
Bill Currie
68ca8c7016 [gatest] Switch to using e0 for the null vector
According to enki (bivector community) when there are more than one null
vector in a geometry, usually all vectors are null, and it was what to
do with multiple null vectors that caused me to balk at using e0 for the
null vector. However, using e0 for the null vector makes life much
easier, especially as that's what most of the literature does. There
are plenty of places, particularly in layout handling, that still need
adjustment for the change, but things seem to work (minus duals, but
they were broken in the first place, thus the discussion with enki).
2023-06-08 12:56:23 +09:00
Bill Currie
fe045f75fb [qfcc] Force live vars used by function statements
This uses ud-chains for function statements (call/return) to force their
arguments to be live (in particular, indirect references via pointers)
this fixes the arraylife test.
2023-06-05 17:20:12 +09:00
Bill Currie
fb1b3e0869 [qfcc] Use ud- and du-chains for block live analysis
The ud- and du-chains include known side-effects of the instructions and
thus depict a more accurate view of what operands an instruction uses or
defines. Fixes the arraylife2 test.
2023-06-05 11:03:44 +09:00
Bill Currie
a5ed154cfe [qfcc] Add a second failing array lifetime test
This one covers regular array references across function call.
2023-06-05 10:58:02 +09:00
Bill Currie
38fd09573f [qfcc] Avoid defining whole temp via alias
Like defs, a partial write should not define the whole temp. Thus, copy
the "don't visit main" behavior recently added to def_visit_all. Fixes
missing ud-chains for component-by-component assignments to temporary
vectors.
2023-06-05 09:42:33 +09:00
Bill Currie
8f6e145257 [qfcc] Don't add target def for store statements
Store statements dereference the pointer in target and thus don't modify
target itself.
2023-06-04 11:45:35 +09:00
Bill Currie
e2c1da9b6a [qfcc] Create du-chains from ud-chains
I'm not certain this is correct, but it seems to me that du-chains are
the same information as ud-chains, but from the defining statement's
point of view instead of that of the using statement.
2023-06-04 11:24:52 +09:00
Bill Currie
7149a092f6 [qfcc] Create ud-chains more aggressively
As certain statements (in particular, function calls) can use additional
variables via pointer parameters, it's necessary to iterate ud-chain
building until the count stabilizes. This should make live variable
analysis much easier.
2023-06-04 01:47:30 +09:00
Bill Currie
d0e2c0a9d9 [gatest] Allow specifying the algebra on the command line
Saves having to recompile for a different algebra. Right now, just
`-a p,m,z` is supported.
2023-05-29 15:14:59 +09:00
Bill Currie
65764a06c0 [gatest] Don't lex . as a single character
Lexing . as a single character makes it impossible to enter fractions.
Unfortunately, this means that . as dot product requires white space on
either side.
2023-05-29 15:13:27 +09:00
Bill Currie
6bd9aceb28 [ruamoko] Correct signatures of strtol and strtoul
I had forgotten the base parameter in the ruamoko definitions (verified
there in the C wrapper).
2023-05-29 15:12:20 +09:00
Bill Currie
681629a5d1 [gatest] Parse division and dual operations 2023-05-29 09:52:10 +09:00
Bill Currie
4e441d359a [gatest] Write a simple parser for playing with GA
Currently only PGA(3) is supported, but that's because the parser is
rather simple (recursive descent with a lame lexer), but it works well
enough for playing with geometric algebra without having to recompile
every time.
2023-05-27 12:47:33 +09:00
Bill Currie
582423a019 [ruamoko] Extend the string api
Wrap the strtod, strtof, strtol, strtoul functions, supporting the end
pointer as well (if not nil, the int offset of the end pointer relative
to the string start is returned).

Also, str_unmutable creates a return string from a mutable string
(copying it).
2023-05-27 12:47:33 +09:00
Bill Currie
a22c2224e0 [ruamoko] Fortify and extend the script api
Meaning some leaks have been plugged, and some useful functions added:
loading a file (avoids polluting progs memory), setting the single
character lexeme string, and getting the line number.
2023-05-27 12:47:33 +09:00
Bill Currie
ac42bca98b [ruamoko] Support nil object in obj_error
Segfaulting when trying to produce an error message doesn't help get the
message out. Sure, `obj_error (nil...)` is a bit of an abuse, but it
shouldn't segfault the engine.
2023-05-27 12:47:33 +09:00
Bill Currie
5d9823af30 [qfcc] Implement designated initializers
Conforms fairly closely to GCC's C implementation.
2023-05-27 12:47:33 +09:00
Bill Currie
04e26a7b9f [set] Check for 0 count correctly
I don't know what I was thinking when I checked for 0 count for resizing
the set. Attempting to add/remove 0 elements results in adding/removing
4G elements. Oops.
2023-05-27 00:55:22 +09:00
Bill Currie
09a3e257e8 [qfcc] Fully initialize local structural defs
I think the current build_element_chain implementation does a reasonable
job, but I'm in the process of getting designated initializers working,
thus it will become important to ensure uninitialized members get
initialized.
2023-05-26 21:56:19 +09:00
Bill Currie
d5156a2320 [set] Add an edge detection iterator
set_while checks the iterator's current element membership and skips to
the first element with different membership. ie, if the current element
is in the set, then set_while returns the next element *not* in the set,
but if the current is not in the set, then set_while returns the next
element that *is* in the set. Rather handy for dealing with clusters of
set elements.
2023-05-26 21:46:34 +09:00
Bill Currie
89e60bd521 [set] Add functions to add and remove ranges
It is often necessary to add or remove whole ranges of elements, but
doing so one at a time can be quite inefficient.
2023-05-26 16:55:07 +09:00
Bill Currie
d001473536 [qfcc] Make is_struct struct-only
And add is_union to handle unions. Sometimes it's necessary to check
between the two.
2023-05-25 21:23:27 +09:00
Bill Currie
6d5e8922a5 [qfcc] Add a handle type for engine resources
I never liked the various hacks I had come up with for representing
resource handles in Ruamoko. Structs with an int were awkward to test,
pointers and ints could be modified, etc etc. The new @handle keyword (@
used to keep handle free for use) works just like struct, union and
enum in syntax, but creates an opaque type suitable for a 32-bit handle.
The backing type is a function so v6 progs can use it without (all the
necessary opcodes exist) and no modifications were needed for
type-checking in binary expressions, but only assignment and comparisons
are supported, and (of course) nil. Tested using cbuf_t and QFile: seems
to work as desired.

I had considered 64-bit handles, but really, if more than 4G resource
objects are needed, I'm not sure QF can handle the game. However, that
limit is per resource manager, not total.
2023-05-25 10:41:28 +09:00
Bill Currie
d07bd20552 [gib] Correct the header in gib.h 2023-05-24 21:04:24 +09:00
Bill Currie
db9a6a9a5c [ruamoko] Make cbuf functions take a cbuf param
A nil param refers to the default cbuf if it has been set by the engine,
otherwise it is invalid. This is the first step to fleshing out the cbuf
API.
2023-05-24 21:01:07 +09:00
Bill Currie
b9cff7aae0 [gatest] Implement and use multi-vector reverse
This gives the resultant point the correct sign.  Though the projective
divide would take care of the sign, this makes reading the point a
little less confusing (still need to sort out automatic blade reversals
for the likes of e31).
2023-05-24 18:25:47 +09:00
Bill Currie
42b0608e65 [qwaq] Get the console working for qwaq-x11
And other graphics versions too, of course. A lot of it feels rather
like a hack, but I think the entire canvas/console setup and console
related event handling may need a rethink (it's not horribly wrong, but
it doesn't feel right), particularly the initial sizing and binding for
toggling the console.
2023-05-24 12:44:16 +09:00
Bill Currie
7c9b6aa0cc [gatest] Use the metric when computing the dot product
As the dot product is a metric product, using the metric is vital to
getting the correct results. This fixes the calculation of the closest
point on a line to a point other than the origin (and a whole pile of
other issues, I imagine).
2023-05-22 13:03:35 +09:00
Bill Currie
d01fc27dd5 [gatest] Remove the workarounds for array lifetime
Now that arrays work well enough for this case, no point in having the
workarounds (other than they're actually faster, but I'd like to
optimize *that* sometime).
2023-05-21 22:20:38 +09:00
Bill Currie
7b6b25a751 [qfcc] Find variables referenced by function arguments
This takes advantage of the ud-chains to follow the trail of pointer
assignments looking for an address. This gets array element assignments
surviving across blocks when the array itself is passed to a function.
It doesn't help when the address of the element is taken though. I think
that's a dags problem and probably needs du-chains. Also, the ud-chain
creation should probably be done in two passes so the newly found
information can be recorded.
2023-05-21 22:11:46 +09:00
Bill Currie
a5943c8a3b [qfcc] Use statement use chain for v6 calls
Def and kill are still handled in flow_analyze_statement, but this makes
call meta data more consistent between v6 and ruamoko progs, allowing
the statement use chain to be used for call argument analysis. It even
found a bug in the extraction of param counts from the call instruction.
2023-05-21 10:23:03 +09:00
Bill Currie
208359edc6 [qfcc] Ensure all operands are cleared before flow
I had missed the flowvar clearing for auxiliary use/def/kill operands.
It's possible it wasn't necessary at the time since the operands were
added just for dealloc checking, but there's every reason it could
become necessary.
2023-05-20 13:54:40 +09:00
Bill Currie
b5a57cd15c [qfcc] Use assign_statement for v6p call arguments
I had written assign_statement a while after the call handling code and
didn't think to modify the call code. This makes for more consistent
code.
2023-05-20 13:52:24 +09:00
Bill Currie
9247ab91fd [qfcc] Calculate ud-chains
The first use will be pointer analysis for function arguments where the
argument points to an array to mark the array as live, but I'm sure
there'll be plenty of other uses.
2023-05-20 08:49:51 +09:00
Bill Currie
4b3b6d516a [qfcc] Use available functions for dealloc use/def
I had written those use/def sets before creating the functions, and it
turns out I had goofed slightly with the def chaining.
2023-05-19 19:41:34 +09:00
Bill Currie
0c116b8ff0 [qfcc] Record actual statements in a function
This is to help with building ud-chains as I suspect I won't be all that
interested in defs from the dummy blocks.
2023-05-19 17:50:19 +09:00
Bill Currie
74e15fc582 [qfcc] Show var use in flow vars 2023-05-19 17:48:47 +09:00
Bill Currie
95dd63cd68 [qfcc] Avoid defining whole def via alias
A partial write to a def should not define the whole def, thus
def_visit_all's overlap parameter now has a flag that prevents a visit
to the main def when accessing the def from an alias def. This prevents
a lot of spurious kills and defines in flow analysis.
2023-05-19 16:42:13 +09:00
Bill Currie
008a64ee9b [gatest] Add multivector constructors to Algebra
This makes it much easier to create vectors of a specific grade or
grouping. It even found some mistakes in the multivector product
implementations.
2023-05-19 11:15:29 +09:00
Bill Currie
c1c77bd64a [gatest] Add basic geometric algebra test
This is for developing methods of implementing geometric algebra and
eventually playing with it visually.
2023-05-19 00:34:05 +09:00
Bill Currie
3a9148a3e0 [ruamoko] Return nil for %@ printf format
Fixes a segfault when attempting to print a nil object.
2023-05-18 20:53:04 +09:00
Bill Currie
5f75616655 [ruamoko] Implement -describe for Set
Being able to use printf directly is nice :)
2023-05-17 21:09:00 +09:00
Bill Currie
8d4602ec61 [qfcc] Fix indexed pointer vector indexing
The array access code was loading the vector, modifying the element,
then forgetting to write the modified vector back to whence it came.
However, that would be rather sub-optimal, so now when the vector is
accessed by a pointer, the array code switches to field access to get at
the vector element thus avoiding the need to copy the whole vector.
2023-05-17 01:09:31 +09:00
Bill Currie
0d78a865c6 [qfcc] Show flow vars and statements for reaching dot
A bunch of nodes with a pile of numbers doesn't mean much without the
context.
2023-05-15 11:08:23 +09:00