Bill Currie
b1459ac816
[qfcc] Move return save temp into call block
...
This fixes func-expr after the assignment rewrite. Now all tests pass
when not optimizing (something not quite right in assignchain when
optimizing).
2020-03-14 01:24:13 +09:00
Bill Currie
57134e01cd
[qfcc] Handle l-value pointer dereferences again
...
While I still hate ".=", at least it's more hidden, and the new
implementation is a fair bit cleaner (hah, goto a label in an if (0) {}
block).
Most importantly, the expression tree code knows nothing about it. Now
just to figure out what broke func-epxr. A bit of whack-a-mole, but yay
for automated tests.
2020-03-14 01:04:05 +09:00
Bill Currie
d150210888
[qfcc] Nuke PAS from orbit
...
And there was much rejoicing. I hated having to create that opcode.
2020-03-13 21:03:48 +09:00
Bill Currie
de89f2f31f
[qfcc] Fix a test that wasn't failing when it should
2020-03-13 20:47:57 +09:00
Bill Currie
f738639d68
Revert "[qfcc} Mark some more functions as pure"
...
This reverts commit 65b48c734c
.
I forgot that get_type calls convert_name, which most definitely is not
pure. Fixes the segfault in scheme.
2020-03-13 19:58:34 +09:00
Bill Currie
e22579d70e
[qfcc] Analyze memset target pointer
...
This fixes the false uninitialized warnings cause by nil migration.
2020-03-13 18:28:54 +09:00
Bill Currie
3d88c3845f
[qfcc] Move struct copy/set into statement emission
...
Doing it in the expression trees was a big mistake for a several
reasons. For one, expression trees are meant to be target-agnostic, so
they're the wrong place for selecting instruction types. Also, the move
and memset expressions broke "a = b = c;" type expression chains.
This fixes most things (including the assignchain test) with -Werror
turned off (some issues in flow analysis uncovered by the nil
migration: memset target not extracted).
2020-03-13 18:20:38 +09:00
Bill Currie
c04f1c0156
[qfcc] Really delay the conversion of nil
...
Now convert_nil only assigns the nil expression a type, and nil makes
its way down to the statement emission code (where it belongs, really).
Breaks even more things :)
2020-03-13 18:19:43 +09:00
Bill Currie
19002116c2
[qfcc] Fix missing expression types from dot_expr
2020-03-13 17:56:07 +09:00
Bill Currie
2c9c15f4c8
[qfcc] Add a type check helper for structural types
...
ie, struct/union/array. I finally though up a decent name (didn't want
to use record as that's a pascal type).
2020-03-13 17:54:05 +09:00
Bill Currie
8d10b0f4aa
[qfcc] Support compound initializers for return
2020-03-13 09:58:52 +09:00
Bill Currie
047131a737
[qfcc] Check for compound init in message args
...
I had forgotten message sending did its own type checking and thus
needed to be updated for compound initializers in message parameters.
2020-03-13 09:46:36 +09:00
Bill Currie
9c06b22719
[qfcc] Fix segfault when assigning {}
2020-03-13 01:59:35 +09:00
Bill Currie
9c5fac2226
[qfcc] Catch another assignment chain failure
2020-03-12 19:53:15 +09:00
Bill Currie
f454842361
[qfcc] Add breaking assignment chain test
...
This bug drove me nuts for several hours until I figured out what was
going on.
The assignment sub-tree is being generated, then lost. It works for
simple assignments because a = b = c -> (= a (= b c)), but for complex
assignments (those that require move or memset), a = b = c -> (b = c) (a
= c) but nothing points to (b = c). The cause is using binary
expressions to store assignments.
2020-03-12 19:47:09 +09:00
Bill Currie
4c2a6c9eb2
[qfcc] Allow implicit demotion in initializer elements
...
Notably, implicit double constants (no adorning d) being used to
initialize float struct members.
2020-03-12 19:40:17 +09:00
Bill Currie
65b48c734c
[qfcc} Mark some more functions as pure
...
I guess gcc doesn't consider recursive functions as pure, but marking
get_type as pure had a slight ripple effect.
2020-03-12 19:40:17 +09:00
Bill Currie
c743583003
[qfcc] Fix a comment
2020-03-12 19:40:17 +09:00
Bill Currie
bbfd498b74
[qfcc] Handle compound and memset dot nodes
...
compound is currently not very informative, but it's better than "bad
expression type"
2020-03-12 19:40:17 +09:00
Bill Currie
21a8559674
[qfcc] Improve handling of nil assignments
...
Especially when they result in using memset.
2020-03-12 19:40:17 +09:00
Bill Currie
e4caf50ee1
[qfcc] Update switch tables for compound initializers
...
Forgot to do a full test build (Machine.r found it)
2020-03-11 23:52:12 +09:00
Bill Currie
5d349efe78
[qfcc] Delay conversion of nil in assignments
...
It's not possible to take the address of constants (at this stage) and
trying to use a move instruction with .zero as source would result in
the VM complaining about null pointer access when bounds checking is on.
Thus, don't convert a nil source expression until it is known to be
safe, and use memset when it is not.
2020-03-11 22:57:48 +09:00
Bill Currie
be5f11f33a
[qfcc] Support the new memset instructions
2020-03-11 22:57:20 +09:00
Bill Currie
d418be31e6
[qfcc] Tweak ivar test to check old bug
...
It turns out that assigning nil to an ivar struct does not work (should,
of course).
2020-03-11 20:55:21 +09:00
Bill Currie
48a256efaa
[qfcc] Fix segfault when assigning {}
...
I had intended to check, but forgot.
2020-03-11 20:45:25 +09:00
Bill Currie
b6439e8dc1
[qfcc] Support compound init in assignment and params
...
foo({...}) and bar = {...}
2020-03-11 19:48:25 +09:00
Bill Currie
afd31ed292
[qfcc] Rename cexpr to comma_expr
...
It took me too long to figure out what cexpr was for.
2020-03-11 16:07:58 +09:00
Bill Currie
d1e83b9d48
[qfcc] Create a compound initializer expression type
...
This fixes the problem of using the return value of a function as an
element in a compound initializer. The cause of the problem is that
compound initializers were represented by block expressions, but
function calls are contained within block expressions, so def
initialization saw the block expression and thought it was a nested
compound initializer.
Technically, it was a bug in the nested element parsing code in that it
wasn't checking the result value of the block expression, but using a
whole new expression type makes things much cleaner and the work done
paves the way for labeled initializers and compound assignments.
2020-03-11 15:46:57 +09:00
Bill Currie
f10f9e157d
[qfcc] Warn about unused labels
2020-03-11 13:33:06 +09:00
Bill Currie
393e540ffa
[qfcc] Print the source name of an undefined label
...
Undefined labels generated by the compiler indicate severe trouble.
2020-03-11 13:31:12 +09:00
Bill Currie
813319efc2
[qfcc] Implement goto
...
It's just too useful when used correctly.
2020-03-11 12:53:40 +09:00
Bill Currie
4a8854d9ed
[qfcc] Add expression tracking to operands
...
Not much uses it yet, but it will make for better diagnostics.
2020-03-11 12:51:34 +09:00
Bill Currie
1cd5ea5732
[qfcc] Add support for named labels in statements
...
Yeah, I've finally decided to implement goto. Limited to function scope
of course.
2020-03-11 12:49:10 +09:00
Bill Currie
d5560434c0
[qfcc] Rename label to bool_label for clarity
...
And also so I can use `label' for source labels.
2020-03-11 11:06:09 +09:00
Bill Currie
3061f7e30e
[qfcc] Update sendv test for corrected implementation
2020-03-11 11:04:49 +09:00
Bill Currie
826f066e00
[qfcc] Be more consistent with string saving
...
Not that it really makes any difference for labels since they're
guaranteed unique, but it does remove the question of "why nva instead
of save_string?". Looking at history, save_string came after I changed
it from strdup (va()) to nva(), and then either didn't think to look for
nva or thought it wasn't worth changing.
2020-03-11 10:50:15 +09:00
Bill Currie
5535a6a509
[qfcc] Fix missing words in a comment
2020-03-11 10:49:49 +09:00
Bill Currie
9acfdea8b5
[qfcc] Improve line number binding for function calls
...
Multi-line calls (especially messages) got rather confusing to read as
the lines jumped back and forth. Now the binding is better but the dags
code is reordering the parameters sometimes.
2020-03-11 01:52:45 +09:00
Bill Currie
a013714bd0
[qfcc] Add missing header file changes
...
Oops
2020-03-08 20:11:21 +09:00
Bill Currie
89ec86f77f
[qfcc] Add option to promote of float through ...
...
The server code is not yet ready for doubles, especially in its varargs
builtins: they expect only floats. When float promotion is enabled
(default for advanced code, disabled for traditional or v6only),
"@float_promoted@" is written to the prog's strings.
2020-03-08 19:13:57 +09:00
Bill Currie
bcf75b541a
[qfcc] Build movep dest pointer correctly
...
This fixes the mangled pointer in struct-init-param.r.
2020-03-08 17:40:38 +09:00
Bill Currie
5020966be3
[qfcc] Fix ud-chain alias handling
...
That was a fair bit trickier than I thought, but now .return and .paramN
are handled correctly, too, especially taking call instructions into
account (they can "kill" all 9 defs).
2020-03-08 16:57:12 +09:00
Bill Currie
3d9410c66d
[qfcc] Force overlap to 0 for non-alias def/temops
...
Make the code behave as intended: visiting all aliases when starting
with the real def/tempop regardless of the overlap setting.
2020-03-08 16:53:28 +09:00
Bill Currie
035da472ec
[qfcc] Offset alias tempop offsets
...
Alias tempop offsets are relative to the real tempop. This fixes alias
tempops never overlapping the real tempop.
2020-03-08 16:51:01 +09:00
Bill Currie
695b3ba0d0
[qfcc] Rearrange vecexpr.r for easier debugging
...
Putting the most likely function to have problems at the top reduces
break-point shenanigans.
2020-03-08 16:50:39 +09:00
Bill Currie
d9d321f65b
[qfcc] Check for previous errors in vector exprs
...
Fixes a segfault when one of the expressions used to construct the
vector was the result of an error.
2020-03-08 15:40:07 +09:00
Bill Currie
b81d58c795
Revert "[qfcc] Correct a comment"
...
This reverts commit a2f203c840
.
There is indeed a world of difference between "any" and "only", and it
helps if I read the rest of the docs AND the code :P.
2020-03-08 14:58:57 +09:00
Bill Currie
8696e76a25
[qfcc] Handle aliases when setting use and def
...
As expected, this does not fix the mangled pointer problem in
struct-init-param.r, but it does improve the ud-chains. There's still a
problem with .return, but it's handling in flow_analyze_statement is a
bit "special" :P.
2020-03-08 12:17:56 +09:00
Bill Currie
a2f203c840
[qfcc] Correct a comment
...
There's a world of difference between "any" and "only".
2020-03-08 12:10:12 +09:00
Bill Currie
b2faca16a7
[qfcc] Rename the kill alias functions
...
Having "visit" in the name felt redundant in the end.
2020-03-08 12:08:56 +09:00
Bill Currie
c2ed6d41bd
[qfcc] Finish struct-init-param test
...
When the bug is fixed, it will pass now (does without optimization).
2020-03-08 03:55:08 +09:00
Bill Currie
e4c87091a3
[qfcc] Lots of flow analysis docs
...
And some function shuffling for grouping. I'm not satisfied with the
docs, but they're a lot more helpful than they were.
2020-03-08 03:53:53 +09:00
Bill Currie
809c103fd1
[qfcc] Shuffle some code around to be clearer
...
Doing the same thing at the end of two branches of an if/else seems off.
And doing an associative(?) set operation every time through a loop is
wasteful.
2020-03-08 03:46:52 +09:00
Bill Currie
7338689146
[qfcc] Treat offset real tempops as an error
...
tempops always have an offset field, but only those that are aliases
should ever have a non-zero offset.
2020-03-08 03:42:18 +09:00
Bill Currie
d44d956038
[qfcc] Remove a long dead function
2020-03-08 03:39:24 +09:00
Bill Currie
f56de00c21
[qfcc] Rename a field
...
depth_first is much clearer than dfo. I had to check what dfo meant too
many times in one night.
2020-03-08 03:38:45 +09:00
Bill Currie
2b15e61b28
[qfcc] Remove obsolete structure fields
...
init_vars hasn't been used for a long time.
2020-03-08 03:33:01 +09:00
Bill Currie
e524db1fc1
[qfcc] Set op type when aliasing a value
...
This fixes the ICE when attempting to compile address-cast without
optimization (just realized why, too: the assignment was optimized out
of existence).
2020-03-08 03:11:46 +09:00
Bill Currie
6ada20f685
[qfcc] Show offset for op_x_def_ofs relocs
2020-03-07 02:06:33 +09:00
Bill Currie
48514ba2f3
[qfcc] Create alias def for defs accessed via pointer
...
This the fixes the incorrect flow analysis caused by the def being seen
to have the wrong size (structure field of structure def seen through a
constant pointer). Fixes the ICE, but the pointer constant is broken
somewhere in dags, presumably.
2020-03-07 01:30:36 +09:00
Bill Currie
faa6eabfbe
[qfcc] Add a failing test for struct init to param
...
This actually took a bit to reproduce.
2020-03-06 22:28:04 +09:00
Bill Currie
f7757cf894
[qfcc] Add filename to dot output
...
It makes things so much easier when viewing the graphs
2020-03-06 21:05:53 +09:00
Bill Currie
de06efa604
[qfcc] Fix handling of nil for static initializers
...
nil is most definitely constant.
2020-03-06 20:38:40 +09:00
Bill Currie
9dbc81432a
[qfcc] Use full type for differentiating values
...
This fixes the problem of using nil for two different compound types
within the one expression. The problem is all compound types have the
same low-level type (ev_invalid) and this caused the two different nils
to have the same type when taken back up to expression level.
2020-03-06 20:33:47 +09:00
Bill Currie
07e6baf32f
[qfcc] Support { } as nil in nested initializers
...
Did top-level earlier, but forgot to add support for deeper nestings.
2020-03-06 20:32:37 +09:00
Bill Currie
9b269c2f8e
[qfcc] Fix mangled method parameters
...
Method parameters (ie, extra parameters without selector names) were
getting reversed during function type construction.
2020-03-06 17:37:58 +09:00
Bill Currie
a2cebe3cac
[qfcc] Add failing test for method parameters
2020-03-06 17:36:23 +09:00
Bill Currie
94e35b5f57
[qfcc] Clean up error messages around superclass
2020-03-05 21:10:15 +09:00
Bill Currie
66b8ab6890
[qfcc] Rework method ivar access
...
While expression symbols worked for what they are, they weren't so good
for ivar access because every ivar of a class (and its super classes)
would be accessed at method scope creation, generating spurious access
errors if any were private. That is, when the access checks worked at
all.
2020-03-05 18:45:47 +09:00
Bill Currie
5200c3f518
[qfcc] Update chewed-alias test for new warnings
2020-03-05 18:26:11 +09:00
Bill Currie
1bf56b28ac
[qfcc] Warn when messaging a forward-declared class
...
But only once.
2020-03-05 15:39:34 +09:00
Bill Currie
59db90d177
[qfcc] Fix method not found warnings
...
It turns out they should not be optional, but do need to be smarter
about when and which. So another two FIXMEs gone :)
2020-03-05 14:48:53 +09:00
Bill Currie
669c8f43d8
whitespace
2020-03-05 14:48:49 +09:00
Bill Currie
ccaa4ad3d2
[qfcc] Catch assignment of void* to class pointers
...
id and other class pointers imply that the object can receive messages,
but void * has no such implication, so treat it as a mismatch.
2020-03-05 14:14:20 +09:00
Bill Currie
65a5e4f2a4
[qfcc] Allow inherited methods to satisfy protocols
...
I suspect that the current state of things will produce problems later
on, but this works for now.
2020-03-05 12:52:37 +09:00
Bill Currie
1459361cbd
[qfcc] Set builtin function def flags
...
This fixes the missing redefinition error when a builtin is defined
twice (and thus corrupting the function chain).
2020-03-05 11:48:15 +09:00
Bill Currie
9ccfe8aefc
[qfcc] Rewrite init_elements
...
The end goal was to fix erroneous non-constant initializer errors for
the following (ie, nested initializer blocks):
typedef struct { int x; int y; } Point;
typedef struct { int width; int height; } Extent;
typedef struct Rect_s { Point offset; Extent extent; } Rect;
Rect makeRect (int xpos, int ypos, int xlen, int ylen)
{
Rect rect = {{xpos, ypos}, {xlen, ylen}};
return rect;
}
However, it turned out that nested initializer blocks for local
variables did not work at all in that the relocations were lost because
fake defs were being created for the generated instructions.
Thus, instead of creating fake defs, simply record the offset relative
to the base def, the type, and the basic type initializer expression,
then generate instructions that all refer to the correct def but with a
relative offset.
Other than using the new element system, static initializers are largely
unaffected.
2020-03-05 11:05:13 +09:00
Bill Currie
1b2a806f28
[qfcc] Fix test that failed due to improved warnings
2020-03-05 11:04:22 +09:00
Bill Currie
78b71c28fe
[qfcc] Make reloc functions const-correct
2020-03-05 11:03:23 +09:00
Bill Currie
efcbbbb641
[qfcc] Catch use of missing superclass interfaces
2020-03-05 08:50:29 +09:00
Bill Currie
896c14f33a
[qfcc] Support anonymous structs in ivars
...
Missed this earlier.
2020-03-05 08:47:21 +09:00
Bill Currie
0bb4279a9f
[qfcc] Handle bitwise not of enums
...
It looks like I need to handle other unary expressions too, but another
time.
2020-03-05 01:45:38 +09:00
Bill Currie
269a8a558a
[qfcc] Allow bare enum and named struct declarations
...
Got a little overzealous there
2020-03-04 18:39:41 +09:00
Bill Currie
f532780dbe
[qfcc] Treat opaque structs as not anonymous
...
I don't know why the segfault happened where it did, but
forward-declared structs certainly can't be used as anonymous structs.
2020-03-04 18:38:04 +09:00
Bill Currie
7a2335e9f4
[qfcc] Catch useless specifiers in function scope
2020-03-04 18:07:10 +09:00
Bill Currie
4c82114547
[qfcc] Catch several useless specifier expressions
2020-03-04 17:40:49 +09:00
Bill Currie
597890dda1
[qfcc] Catch duplicate field definitions
2020-03-04 16:32:04 +09:00
Bill Currie
e298904dc0
[qfcc] Implement anonymous structs and unions
...
For struct/union scope
2020-03-04 16:31:28 +09:00
Bill Currie
4fa203852a
[qfcc] Use offset alias offset when creating alias of offset alias
...
Yes, that's correct. It happens when casting the address of a structure
field (for the test case this fixes, vector field).
2020-03-04 00:55:31 +09:00
Bill Currie
57b2751732
[qfcc] Add failing vector element address test
...
It's an evil thing to do, but it should at least work.
2020-03-04 00:37:10 +09:00
Bill Currie
b186332da0
[qfcc] Make initialization of external vars an error
2020-03-03 17:33:56 +09:00
Bill Currie
6def1fc01c
[qfcc] Fix a bootstrap warning
2020-03-03 15:26:33 +09:00
Bill Currie
b8984e5f66
[qfcc] Fix another infinite loop in the linker
...
I think this should be it for infinite loops caused by undefined
symbols. I don't know why I didn't remove this continue when I removed
the other.
2020-03-03 13:39:24 +09:00
Bill Currie
c7cde5f409
[qfcc] Pass gcc's purity test
...
*sigh*
2020-03-03 10:59:01 +09:00
Bill Currie
16223098e5
[qfcc] Fix ivar visibility
...
It was broken by the big rewrite and I forgot to fix it.
2020-03-03 10:42:05 +09:00
Bill Currie
ed04e6fc23
[qfcc] Merge method lists instead of copying
...
This is for adding methods to classes and protocols via their interface,
not for adding methods by adding protocols (they still get copied).
Slightly more memory efficient.
2020-03-03 00:11:54 +09:00
Bill Currie
f025bd96d4
[qfcc] Copy self param when copying methods
...
Copying methods is done when adding protocols to classes (the current
use for adding regular methods is an incorrect solution to a different
problem). However, when a method is added to a class, the type of its
self parameter is set to be a pointer to the class. Thus, not only does
the method need to be copied, the self parameter does too, otherwise
the self parameter of methods added via protocols will have their type
set to be a pointer to the last class seen adding the protocol.
That is, if, while compiling the implementation for class A, but the
interface for class B is comes after the interface for class A, and both
A and B add protocol P, then all methods in protocol P will have self
pointing to B rather than A.
@protocol P
-method;
@end
@interface A <P>
@end
@interface B <P>
@end
@implementation A
-method {} // self is B, not A!
@end
2020-03-02 23:46:26 +09:00
Bill Currie
8a4de6fea6
[qfcc] Fix segmentation fault for parameter errors
2020-03-02 22:38:12 +09:00
Bill Currie
f6d650d473
[qfcc] Merge duplicate methods in interfaces
...
Duplicate methods in an interface (especially across protocols and
between protocols and the interface) are both harmless and even to be
expected. They certainly should not cause the compiler to demand
duplicate method implementations :)
2020-03-02 21:15:21 +09:00
Bill Currie
e33d83fc9e
[qfcc] Accept "struct foo; struct foo { ... };"
...
That is, do not treat structure definition after declaration to be a
redefinition.
2020-03-02 20:16:29 +09:00
Bill Currie
5893bd7501
[qfcc] Catch erroneous negative builtin numbers
...
Setting a builtin number negative makes it a non-builtin function, but
possibly in the middle of another function. Not good.
2020-03-02 13:47:46 +09:00
Bill Currie
0db617719e
[qfcc] Improve error messages for bad qc builtins
...
While global quakec functions could not be initialized to another
function, the error messages were rather obscure.
2020-03-02 13:47:46 +09:00
Bill Currie
9ccff74fcf
[qfcc] Emit only one instance per protocol per module
...
This is actually a double issue: when a class implementing a protocol
used the protocol in @protocol(), not only would the protocol get
emitted as part of the class data specifying that the class conforms to
the protocol, a second instance would be emitted again when @protocol()
was used. On top of that, only the instance referenced by @protocol()
would be initialized. Now, both class emission and @protocol() get their
protocol def from the same place and thus only one, properly
initialized, protocol instance is emitted.
2020-03-02 10:55:46 +09:00
Bill Currie
8021613b79
[qfcc] Fix missing protocol method lists
...
The problem was an erroneous assumption that the methods had to be
defined. Any class implementing a protocol must implement (and thus
define) the methods, but a protocol declaration cannot: it merely
declares the methods, and it's entirely possible for a module to see
only the protocol definition and not any classes implementing the
protocol.
2020-03-02 10:52:09 +09:00
Bill Currie
b6b7f9675f
[qfcc] Emit static instance lists
...
For now, only protocols are in the list (gcc adds only static string
objects and qfcc doesn't do those yet, so not so far behind). qfprogs
dumps them.
2020-03-02 10:48:51 +09:00
Bill Currie
544d7de1ec
[qfcc] Implement @protocol(foo)
...
Unlike gcc, qfcc requires foo to be defined, not just declared (I
suspect this is a bug in gcc, or even the ObjC spec), because allowing
forward declarations causes an empty (no methods) protocol to be
emitted, and then when the protocol is actually defined, one with
methods, resulting in two different versions of the same protocol, which
comments in the gnu objc runtime specifically state is a problem but is
not checked because it "never happens in practice" (found while
investigating gcc's behavior with @protocol and just what some of the
comments about static instance lists meant).
2020-03-02 10:42:26 +09:00
Bill Currie
254bf29bd4
[qfcc] Handle protocol forward declarations
2020-03-01 19:37:40 +09:00
Bill Currie
80d9401eee
[qfcc] Report errors for objects in function decls
...
The number of time's I've forgotten the * in a declaration in objective
code (probably thanks to C#'s lack of them).
2020-03-01 17:44:13 +09:00
Bill Currie
b544321609
[qfcc] Catch deferences to incomplete types
...
Reporting an error is so much more helpful than segmentation fault.
2020-03-01 17:43:28 +09:00
Bill Currie
277c64a460
[qfcc] Correct a typo
2020-03-01 17:28:51 +09:00
Bill Currie
caa297b756
[qfcc] Remove type alias encoding
...
It proved to be too fragile in its current implementation. It broke
pointers to incomplete structs and switch enum checking, and getting it
to work for other things was overly invasive. I still want the encoding,
but need to come up with something more robust.a
2020-03-01 16:13:18 +09:00
Bill Currie
1033716b2b
[qfcc] Fix some curly space
2020-03-01 13:53:18 +09:00
Bill Currie
271d836cd2
[qfcc] Catch static class instances in structs
2020-02-29 21:09:24 +09:00
Bill Currie
e93ca9d828
[qfcc] Fix infinite loop in linker
2020-02-29 20:13:25 +09:00
Bill Currie
b4aebc120e
[qfcc] Treat { } as nil for initializing compound types
2020-02-27 20:30:39 +09:00
Bill Currie
7c9072aebf
[qfcc] Create struct fields for "type typename"
...
Such declarations were being lost, thus in the following, the id field
never got added:
typedef struct qwaq_mevent_s {
int id;
int x, y, z;
int buttons;
} qwaq_mevent_t;
2020-02-27 17:50:11 +09:00
Bill Currie
dbbb8a1396
[qfcc] Fix syntax error for id as a field name
...
event.e.mouse.id produced a syntax error, which is contrary to
Objective-C.
2020-02-27 17:43:39 +09:00
Bill Currie
4cec3bbff6
Unalias types when checking cast-compatibility
...
This fixes the problem with passing typedefs to function parameters.
2020-02-26 17:49:09 +09:00
Bill Currie
69b5029de5
Throw away function parameter type alias info
...
typedef is meant to create a simple renaming of a potentially complex
type, not create a new type. Keeping the parameter type alias info makes
the types effectively different when it comes to overloaded function
resolution, which is quite contrary to the goal. Does expose some
breakage elsewhere, though.
2020-02-26 17:46:53 +09:00
Bill Currie
9528c1176e
Rename cast_expr's type vars for better clarity
2020-02-26 17:45:08 +09:00
Bill Currie
5c36c60005
Use type check helpers some more
2020-02-26 17:41:45 +09:00
Bill Currie
5d302ff6f4
Fix incorrect usage of signed verbosity
2020-02-26 17:15:52 +09:00
Bill Currie
35c9d6ee38
Make pr_obcode.c mostly thread safe
...
Its public data is all read-only, and once set up, its private data is
too (just don't call init in multiple threads).
2020-02-26 01:20:28 +09:00
Bill Currie
66dd3ef070
Make a bunch of count things positive-only
...
This fixes a pile of FIXMEs, because some things should never be
negative.
2020-02-25 21:23:13 +09:00
Bill Currie
282132958f
Relocate local def type encodings in debug load
...
For technical reasons (programmer laziness), qfcc does not fix up local
def type encodings when writing the debug symbols file (type encoding
location not readily accessible).
2020-02-25 20:46:01 +09:00
Bill Currie
89e83d7d73
Move the debug info out of progs_t
...
The debug subsystem now uses the resources system to ensure it cleans
up, and its data is now semi-private. Unfortunately, PR_LoadDebug had to
remain public for qfprogs because using PR_RunLoadFuncs would cause
builtin resolution to complain.
2020-02-25 20:07:29 +09:00
Bill Currie
ca6fe0730b
Fix qfcc test harness tracing
...
Just a consequence of progs execution state being initialized properly.
2020-02-25 19:02:24 +09:00
Bill Currie
a55b9544ac
Improve handling of pr_argc
...
It is now set to 0 when progs are loaded and every time
PR_ExecuteProgram() returns. This takes care of the default case, but
when setting parameters, pr_argc needs to be set correctly in case a
vararg function is called.
2020-02-25 17:36:29 +09:00
Bill Currie
256dee98a1
Make progs string resources management private
...
Strangely enough, using the progs resources system. This is a step
towards having progs that can be reset properly, or even dynamically
created VMs.
2020-02-25 00:23:08 +09:00
Bill Currie
1cfac0f11a
Resolve local def type encodings
...
They need to be resolved at load-time.
2020-02-25 00:12:02 +09:00
Bill Currie
c51c9edd9d
Fix incorrect encoding of local defs
2020-02-25 00:11:01 +09:00
Bill Currie
7406e0308e
Fix some warnings picked up in an optimized build
2020-02-24 11:28:43 +09:00
Bill Currie
c43b9681eb
Keep structure members aligned
2020-02-24 08:43:32 +09:00
Bill Currie
2adcad7c84
Allow non-short-circuited logic to work
2020-02-24 02:25:28 +09:00
Bill Currie
ac32bbca40
Improve code for short-circuited float logic
2020-02-24 02:14:44 +09:00
Bill Currie
9c26d12f95
Cast rather than alias for testing constants
...
Fixes ICE in do { ... } while (1);
2020-02-24 02:13:23 +09:00
Bill Currie
55e53211e2
Generate default type expressions for folded booleans
2020-02-24 02:11:31 +09:00
Bill Currie
d6752c254c
Move short-circuit boolean code to its own file
2020-02-24 01:20:24 +09:00
Bill Currie
0bf7ec07b7
Make debug output verbosity 2
...
and internal diagnostic sources level 1.
2020-02-24 00:22:13 +09:00
Bill Currie
11365024d2
Fix writing of frames files when not requested
...
I forgot to check for the option for separate compilation.
2020-02-24 00:07:48 +09:00
Bill Currie
27ae5ccfce
Fix ICE after incomplete type error
...
Attempting to define a variable with an incomplete type is an error, and
results in a default size 1 of allocated, but I forgot to set default
alignment when implementing alignment.
2020-02-24 00:07:39 +09:00
Bill Currie
f387b9aa47
Propagate implicit for negating double constants
2020-02-23 23:41:12 +09:00
Bill Currie
5374798ef9
Fix order of operations for implicit casts
2020-02-23 23:18:31 +09:00
Bill Currie
05f6ddbb13
Print promoted warnings as errors
...
This makes it much easier to see why a compilation failed when only
warnings are visible.
2020-02-23 23:10:56 +09:00
Bill Currie
526c27cf03
Handle implicit casts for double/float comparisons
2020-02-23 23:10:10 +09:00
Bill Currie
607fd2e30e
Allow constant initialized globals in advanced code
...
Use -C const-initializers to enable (or no-const-initializers to disable
in traditional/extended code).
2020-02-23 22:51:00 +09:00
Bill Currie
e23aa40994
Implicitly cast unadorned floating point constants
...
Floating point constants without f or d adornments will automatically
cast, without warnings, to the type appropriate to the rest of the
expression.
2020-02-23 22:28:54 +09:00
Bill Currie
14cde99d6e
White space
...
of the worst sort.
2020-02-23 22:27:07 +09:00
Bill Currie
ea3af84baa
Fix ICE when const-folding doubles
...
I really need to rework that system.
2020-02-23 20:49:56 +09:00
Bill Currie
2a39208069
Set void alignment to 1
...
qcc allowed void variables.
2020-02-23 20:48:43 +09:00
Bill Currie
c9fca9c98a
Fix another inside-out type utility function
2020-02-23 20:48:12 +09:00
Bill Currie
4b7ecdf74a
Make PR_Init take an instance to initialize
...
This allows internal sub-systems to do per-instance initializations
without other engine systems having to know about them.
2020-02-23 18:32:16 +09:00
Bill Currie
6009d1d023
Fix qfo strings dumping
2020-02-23 15:08:31 +09:00
Bill Currie
b0157e5095
Fix qfo field dumping
2020-02-23 14:56:50 +09:00
Bill Currie
81293d98dd
Fix qfo line info dumping
...
The addition of xdef data has made qfo_to_progs unusable in qfprogs,
resulting in various invalid memory accesses. It always was an ugly hack
anyway, so this is the first step to proper qfo support in qfprogs.
2020-02-23 14:44:25 +09:00
Bill Currie
155a633ebe
Include extended defs data in the size report
2020-02-23 11:53:57 +09:00
Bill Currie
6c6433dea5
Fetch the def name only once when scanning
...
Not that speed is critical at this point, but it feels better.
2020-02-23 11:52:35 +09:00
Bill Currie
52d54f98bf
Fix some issues in the typedef test
...
It wasn't being strict enough in the test (but was good enough to catch
the relocation error, at least) and was printing the alias name
incorrectly.
2020-02-22 23:41:09 +09:00
Bill Currie
3aabfa71d9
Find lost type encoding relocations
...
I have no idea why I thought it was a good idea to delete those lines.
Yay for regression tests, though.
2020-02-22 23:33:56 +09:00
Bill Currie
806af85447
Remove reference to ddef_t from progs.h
...
This cleans up some horrible names and redundant fields that were a
result of the transition to pr_def_t
2020-02-22 22:44:08 +09:00
Bill Currie
81083698a8
Move to using an in-memory form of ddef_t
...
This allows the VM to work with extended ddefs transparently. It seems
to have uncovered a typedef alias relocation bug, though.
2020-02-22 22:33:44 +09:00
Bill Currie
4df926e531
Write extended ddef information to progs far data
...
I was originally going to put it in the debug syms file, but I realized
that the data persistence code would need access to both def type and
certainly correct def offsets for defs in far data.
2020-02-22 14:11:15 +09:00
Bill Currie
e7b4eedc07
Fix segfault in dereferencing undefined field containers
2020-02-22 14:04:10 +09:00
Bill Currie
c296514b95
Make pr.load_file 'return' the file size
2020-02-21 21:17:28 +09:00
Bill Currie
7e76a96f7d
Fix a missed ty_none
2020-02-21 21:13:18 +09:00
Bill Currie
fe796eee68
Move the meta type enum ino pr_type.h
2020-02-21 17:58:19 +09:00
Bill Currie
8b225dbfc1
Ensure .ctor functions do not reset tracing
2020-02-21 17:53:27 +09:00
Bill Currie
caf78b5422
Rename ty_none to ty_basic
...
This far better reflects the actual meaning. It is very likely that
ty_none is a holdover from long before there was full type encoding and
it meant that the union in qfcc's type_t had no data. This is still
true for basic types, but only if not a function, field or pointer type.
If the type was function, field or pointer, it was not true, so it was
misnamed pretty much from the start.
2020-02-21 17:52:00 +09:00
Bill Currie
1b43046c8a
Handle aliased types when building function calls
2020-02-19 21:41:46 +09:00
Bill Currie
fd2b7ee6f9
Use more type checking helper functions
2020-02-19 21:41:46 +09:00
Bill Currie
a6003ed08a
Walk qfo alias chain for type size and alignment
...
While the basic type is stored in the alias type record, it's no good
for size or alignment as it will give incorrect results for complex
types.
2020-02-19 21:41:46 +09:00
Bill Currie
a0914e1ec8
Fix the typedef test case to actually work
2020-02-19 21:41:46 +09:00
Bill Currie
6a70d2e362
Give alias types a unique encoding
...
The encoding is used as the def name and it needs to be different than
the alias target or the linker throws it away as an external def.
2020-02-19 21:41:46 +09:00
Bill Currie
6bc803c72d
Use correct encoding for alias types
...
I got confused which field was which.
2020-02-19 21:41:46 +09:00
Bill Currie
6bcc2c49ab
Use helper functions for type checks
...
They hide the evil details of aliased types. More to come :/
2020-02-19 21:41:46 +09:00
Bill Currie
9610788dea
Fix some more type aliasing issues
...
Getting there... (I knew this would be a big job)
2020-02-19 21:41:46 +09:00
Bill Currie
d50a27a045
Race down the alias chain before checking types
...
This takes care of some of the type aliasing issues.
2020-02-19 21:41:46 +09:00
Bill Currie
a5aba6c8ac
Implement type aliasing
...
The separate types are in the file, but there are multiple issues
2020-02-19 21:41:46 +09:00
Bill Currie
2f18364364
Start work on encoding typedef chains
2020-02-19 21:41:46 +09:00
Bill Currie
adb7f5d601
Quieten the test script build rules
2020-02-19 21:41:46 +09:00
Bill Currie
b00c866c4e
Allow casting between string and pointer types
2020-02-19 21:41:46 +09:00
Bill Currie
7a315b4a89
Fix storage class for for-loop declarations
...
Getting "i redeclared" when i was declared in a for loop in two
different functions was a tad unexpected.
2020-02-19 21:41:46 +09:00
Bill Currie
4c40928112
Remove what appears to be a redundant check
...
It was long wrong anyway as it checked past the end of the function's
parameters, which caused a segfault when calling varargs functions with
no formal parameters.
2020-02-19 02:53:38 +09:00
Bill Currie
a65d6bce09
Fix a warning that got through
...
I forgot to compile test in optimized...
2020-02-19 02:43:27 +09:00
Bill Currie
bd6dcafdc8
Replace system defines/includes with qfcc's
...
Right now, it probably works only with modern gcc.
2020-02-19 02:35:09 +09:00
Bill Currie
2d52da9c0d
Fix segfault in unlimited params
2020-02-19 02:35:09 +09:00
Bill Currie
c61d0b6ff0
Allow unlimited parameters in function declarations
...
However, definitions are still limited to 8 parameters. This allows
processing of C headers for type information.
2020-02-19 02:35:09 +09:00
Bill Currie
ee228504aa
Fix self-referenced enum declarations
...
eg:
typedef enum foo {
bar = 1,
baz = bar,
} foo;
2020-02-19 02:35:09 +09:00
Bill Currie
7a399c956b
Encode function parameter alignment
...
The encoding is 3:5 giving 3 bits for alignment (log2) and 5 bits for
size, with alignment in the 3 most significant bits. This keeps the
format backwards compatible as until doubles were added, all types were
aligned to 1 word which gets encoded as 0, and the size is unaffected.
2020-02-16 17:10:43 +09:00
Bill Currie
1bc08c59f6
Add tests for %%
...
double fails due to qfcc aligning double param locals, but the engine
not doing so.
2020-02-16 17:02:38 +09:00
Bill Currie
1a9510834a
Add a missed opcode conversion for %%
2020-02-16 12:10:09 +09:00
Bill Currie
9d2d33fa50
Implement %% (true modulo) support in qfcc
...
However, it's not quite working yet
2020-02-16 11:57:58 +09:00
Bill Currie
4269c8cb07
Rename the mod instruction to rem
...
Because % really implements remainder rather than true modulo, and I
plan on adding %% to implement true modulo.
2020-02-16 11:04:30 +09:00
Bill Currie
db9996023f
Add some tests for double comparison
...
More testing the engine than the compiler, but hey :)
2020-02-15 23:49:12 +09:00
Bill Currie
14acfad7c4
Fix incorrect placement of far data
...
All the care in aligning things was undone by not updating the
calculations of the pointers.
2020-02-15 23:49:12 +09:00
Bill Currie
1985b6d4fd
Avoid creating a struct temp for ivar struct return
...
This fixed the uninitialized temp warning in HUD.r. The problem was
caused by the flow analyzer not being able to detect that the struct
temp was being initialized by the move statement due to the address of
the temp being in a pointer temp. While it would be good to use a
constant pointer for the address of the struct temp or improving the
flow analyzer to track actual data, avoiding the temp in the first place
results in nicer code as it removes a move statement.
2020-02-15 23:49:12 +09:00
Bill Currie
9c996df7b4
Add a test case for the uninit temp in HUD.r
2020-02-15 23:49:12 +09:00
Bill Currie
7bfa0f7a92
Allow pragmas to have arguments
...
It does mean only one pragma per line, but that's not such a big deal.
2020-02-15 23:49:12 +09:00
Bill Currie
91f5023681
Promote bugs to internal errors
...
Mostly so I can catch them in test cases
2020-02-15 23:49:12 +09:00
Bill Currie
344d429134
Test array initializer double demotions
...
Turns out array inits are very strict about types (bug?).
2020-02-15 23:49:12 +09:00
Bill Currie
6ce99afa5b
Catch double demotion in global initializers
...
Local initializers are handled by regular assignments
2020-02-15 23:49:12 +09:00
Bill Currie
c5ce18591f
Catch and warn demotion of double in assignments
2020-02-15 23:49:12 +09:00
Bill Currie
08ca59d0df
Add tests for double demotion
2020-02-15 23:49:12 +09:00
Bill Currie
4bf37b274b
Ensure double is not in zero or param structs for v6
2020-02-15 23:49:12 +09:00
Bill Currie
be30a0eb19
Fix missing alignment init on zero and param types
2020-02-15 23:49:12 +09:00
Bill Currie
3e651b43f8
Handle aliased values when emitting statements
...
With this, cast address initializers work. I have to wonder if the alias
value short-circuit was legacy from long before the rewrite, as it was
quite trivial to handle in the back-end.
2020-02-15 23:49:12 +09:00
Bill Currie
e4eb793fb3
Treat aliased values as constant
...
One step closer to cast address initializers working.
2020-02-15 23:49:12 +09:00
Bill Currie
ce9902baed
Don't short-circuit aliased values
...
Not sure why I thought it was a good idea as it turns out this is why
cast pointer initializers were being lost.
2020-02-15 23:49:12 +09:00
Bill Currie
3257e7145b
Add failing global init test too
2020-02-15 23:49:12 +09:00
Bill Currie
4caa875442
Finish up alignment tests and add address cast
...
It turns out that initializing a local int with a pointer cast doesn't
work.
2020-02-15 23:49:12 +09:00
Bill Currie
a4a57b6ffd
Implement aligned allocations
2020-02-15 23:49:12 +09:00
Bill Currie
293f10211a
Start on alignment test
...
Currently fails (deliberately, WIP)
2020-02-15 23:49:12 +09:00
Bill Currie
0542daacdf
Create more double related tests
...
Including catching warnings :) (yay -Werror)
2020-02-15 23:49:12 +09:00
Bill Currie
7e09a94469
Fix "casts" between signed and unsigned int
2020-02-15 23:49:12 +09:00
Bill Currie
5d8d805b60
Fix test for single overload functions
...
All functions are stored in the overload functions table, even those
that are never explicitly overloaded, but only explicitly overloaded
functions (those with @overload) use the type-qualified naming.
2020-02-15 23:49:12 +09:00
Bill Currie
533fb8acc9
Implement double constants
2020-02-15 23:49:12 +09:00
Bill Currie
2cd62fe01b
Fix several double-related bug
...
float is promoted to double through ... for non-v6 code.
PR_Sprintf has custom param access via P_*, messed up doubles.
2020-02-15 23:49:12 +09:00
Bill Currie
eb7f825158
Test for full-float %
2020-02-15 23:49:12 +09:00
Bill Currie
8920c59515
Find @override functions even when there's only one
2020-02-15 23:49:12 +09:00
Bill Currie
df7c08a010
Add support for doubles to Ruamoko
...
Only as scalars, I still need to think about what to do for vectors and
quaternions due to param size issues. Also, doubles are not yet
guaranteed to be correctly aligned.
2020-02-15 23:49:12 +09:00
Bill Currie
13b608f40c
Don't truncat float % float
...
This allows full usage, eg, x % pi, but otherwise maintains
compatibility with integer %
2020-02-15 23:49:12 +09:00
Bill Currie
16f8dca72e
Align local and far data spaces
...
I plan on adding doubles, and so it's necessary to ensure that attempts
to align doubles in local or far data spaces remain aligned after final
linking.
2020-02-15 23:49:12 +09:00
Bill Currie
197f856a30
Fix incorrect scalar/quaternion division
...
It's just not possible.
2020-02-15 23:49:12 +09:00
Bill Currie
9248e8cf01
Update for doxygen 1.8.16
2020-02-11 15:22:42 +09:00
Bill Currie
c3fa78ef4d
Include test for 2d vector expressions
2019-07-06 14:49:28 +09:00
Bill Currie
8caf2eb584
Mark some new functions as pure
2019-06-27 21:37:48 +09:00
Bill Currie
a5ee58cebb
Support 2d vector expressions
...
[x, y] expands to [x, y, 0] (for now, might add a 2d vector type).
2019-06-18 11:54:45 +09:00
Bill Currie
83fac13a0c
Fix debug line numbers for vector expressions
2019-06-18 11:53:58 +09:00
Bill Currie
b37c331e76
Catch taking size of null type
...
This should help catch similar errors in the future.
2019-06-18 10:39:17 +09:00
Bill Currie
0f1f477e64
Set up temp aliases correctly
...
Fixes vector expressions as sub-expresses. I really don't know why I did
the temp alias setup that way.
2019-06-18 10:38:19 +09:00
Bill Currie
fc50376297
Fix a minor error check mistake
2019-06-18 08:54:18 +09:00
Bill Currie
fe73547f43
Update alias type sameness check
...
This one seems to be fairly robust. Fixes alias being used to cast
pointers (maybe a better way, but this works for now).
2019-06-18 08:53:05 +09:00
Bill Currie
f7825fe7cf
Print types properly in pointer value expressions
2019-06-18 00:22:24 +09:00
Bill Currie
b996fb7aa4
Make operand->type actual type instead of low-level
...
And clean up the resulting mess. This fixes struct copy, but uncovers
another bug :/
2019-06-17 23:38:34 +09:00
Bill Currie
e0c8285f07
Extend nested struct test to cover struct copy
...
Fails :P
2019-06-17 22:57:40 +09:00
Bill Currie
dd52b7fea1
Merge aliased alias expressions
...
This comes up when accessing struct fields nested in another struct.
Fixes the nested struct fields test.
2019-06-17 22:48:42 +09:00
Bill Currie
e9c24dbf1c
Test case for accessing nested struct fields
...
Currently fails.
2019-06-17 22:47:44 +09:00
Bill Currie
ec128ffeee
Leave a FIXME for daglabel_t.live
2019-06-16 19:24:19 +09:00
Bill Currie
d6d3027411
Mark the correct operand as live
...
This fixes vecexpr (and possibly other cases).
2019-06-16 19:21:02 +09:00
Bill Currie
6e21c3ae2e
Treat func statements similarly to flow statements
...
func statements need their operands marked live like flow statements do
because usage is more indirect.
2019-06-16 19:20:21 +09:00
Bill Currie
db4a7a139e
Use the alias code when making vars live
...
Not sure the live forcing flag is needed anymore (need to test).
2019-06-16 19:17:45 +09:00
Bill Currie
2977c145d0
Clean up dag live alias code a little
...
Mainly, this makes it possible to reuse the alias code.
2019-06-16 19:17:01 +09:00
Bill Currie
82b334e919
Number dot dumps to help identify order
2019-06-16 19:12:18 +09:00
Bill Currie
c40f4194e9
Use tempop_visit_all for flow and dags
...
Fixes t3 of vecexpr, but t2 is broken (lost first assignment).
2019-06-16 16:56:39 +09:00
Bill Currie
3c4903245a
Fix some curly space
2019-06-16 16:55:54 +09:00
Bill Currie
bc271d8a02
Add tempop_visit_all
...
Works the same as def_visit_all, but for temp operands.
2019-06-16 16:52:49 +09:00
Bill Currie
fa69aeef0f
Improve handling of temp aliases
...
This makes all tests pass when not optimizing. More work needs to be
done in dags.
2019-06-12 00:37:02 +09:00
Bill Currie
b18a744288
Use offset alias expressions
...
They are not quite working yet as the operand generator does not use the
offset yet.
2019-06-10 23:55:16 +09:00
Bill Currie
cc27949a34
Ensure pointer values always have a type
...
The dags generator was creating a pointer value with no type which
caused print_statement to segfault.
2019-06-10 23:52:39 +09:00
Bill Currie
ee1f5f9478
Add support for binary alias expressions
...
Doesn't quite work yet.
2019-06-10 23:48:58 +09:00
Bill Currie
913b9f52e0
Add an offset alias expression
...
This should make dealing with def elements (vector etc) easier.
2019-06-10 18:13:28 +09:00
Bill Currie
efdfc7436f
Move ev_types into types.[ch]
...
No wonder I couldn't find it the other day...
2019-06-10 18:04:25 +09:00
Bill Currie
08ab42fc15
Handle vector expressions as sub-expressions
...
Now my little game builds again :)
2019-06-10 15:50:35 +09:00
Bill Currie
49ed4310fd
Fix assigning int to enum or enum to int
...
Or float, for v6 progs.
2019-06-10 08:46:40 +09:00
Bill Currie
83fb588727
Support vector/quaternion division by float
...
Implemented via v*(1/f) or q*(1/f) to give CSE a chance to optimize the
division if necessary as otherwise the engine would have to divide every
time.
2019-06-10 08:44:36 +09:00
Bill Currie
7dc1a0640a
Delay creating actual enum symbols
...
In order to keep enumerator type and enum type the same, the values need
to have their type set after the enum type is finalized, and then the
appropriate symbols created in the parent scope. This fixes the infinite
recursion when assigning an enum value to its own type.
2019-06-10 07:44:23 +09:00
Bill Currie
f81484a068
Test compiling enums
...
It turns out the enumerator type and enum type wind up with different
instances of the same type (due to the way type chaining works). This
results in infinite recursion in assign_expr and check_types_compatible.
2019-06-10 07:17:41 +09:00
Bill Currie
ef4ad52239
Make binary_expr fold constants
...
This is where constant folding should have happened all along. While
unary_expr should fold constants too, it seems to already try to do so
and it's a bit much of a mess to clean up right now.
2019-06-10 00:36:13 +09:00
Bill Currie
bf0543f7fb
Be paranoid about temp var sizes
...
Prevents array index errors.
2019-06-10 00:19:48 +09:00
Bill Currie
28a2b96800
Implement automatic array sizing from initializer
2019-06-09 23:11:38 +09:00
Bill Currie
00f12263ca
Fix casting arrays to pointers
2019-06-09 22:55:38 +09:00
Bill Currie
3196bcc851
Allow fold_constants to handle some math identities
...
Such as x*0 -> 0, x*1 -> x, x+0 ->x, etc.
2019-06-09 22:34:23 +09:00
Bill Currie
c98d1ff08c
Document some problems with nil
...
While he's a pretty cool character in HZD, he seems to have some
identity problems when in a compiler.
2019-06-09 22:29:51 +09:00
Bill Currie
439cd15620
Do type promotion for short
...
fold_constants used to do this when it was overly aggressive. Fixes the
ICE when accessing an array in a struct via a pointer.
2019-06-09 22:27:53 +09:00
Bill Currie
227ac46ffe
Clean up array expression processing
...
And make sure constants are folded since fold_constants is no longer
recursive.
2019-06-09 22:25:55 +09:00
Bill Currie
f70801fa52
Add a test for accessing an array in a struct
...
That's accessed via a pointer. Whee. However, at this stage, the problem
is really a promotion issue for short -> integer.
2019-06-09 21:44:58 +09:00
Bill Currie
e46a44d9c6
Update TODO
2019-06-09 21:37:46 +09:00
Bill Currie
6253623e9b
Remove some weird dereference code
...
It appears to have been an attempt at optimizing dereferences, but it
instead just utterly mangled them.
2019-06-09 21:37:46 +09:00
Bill Currie
f49303e774
Emit code for address expressions
...
It helps if the necessary code is actually emitted in the first place.
2019-06-09 21:37:46 +09:00
Bill Currie
8cef85e5de
Cast scalar types when necessary on assignment
...
This fixes type promotion errors that broke some tests.
2019-06-09 20:12:50 +09:00
Bill Currie
e849c2d1ce
Mark block expr result as rvalue when used as one
...
At least for return. There may be other cases that need it, but this
fixes comma-expr.r (minus int->float promotion issues).
2019-06-09 19:29:21 +09:00
Bill Currie
d9c9686288
Make initialized globals non-constant
...
This is for modern code. Traditional code still treats initialized
globals as constant and nosave. This will make a bit of a mess of
modern code that expects traditional behavior.
2019-06-09 19:23:23 +09:00
Bill Currie
b7b6a89b91
Simplify fold_constants
...
While this does break automatic type promotion, it does stop
fold_constants recursing through complex expressions: only the top level
expression needs to be folded, and then only if both sides are actually
constant.
2019-06-09 19:20:35 +09:00
Bill Currie
2ee36e8b99
Rename qfot_type_t.ty to meta
...
When I did up a ruamoko implementation of a type encoding dumper, I
named the field meta, which feels much better than ty.
2019-06-09 18:10:07 +09:00
Bill Currie
f093516962
Move qfo type encoding structs
...
This makes them available to the gamecode VM, and thus the debugger.
2019-06-09 18:07:58 +09:00
Bill Currie
7fce68649a
Implement comma expressions
...
Doesn't quite work (attempt to suppress warning for return a = 3, 5;
failed).
2019-06-09 16:56:20 +09:00
Bill Currie
689d1ad3ec
Remove some debug prints
2019-06-09 16:45:01 +09:00
Bill Currie
33c2eb430f
Stop bison complaining about %expect
...
And make sure warnings get fixed.
2019-06-09 16:19:27 +09:00
Bill Currie
1db600548e
Fix for decl test scope issue
2019-06-09 13:55:07 +09:00
Bill Currie
ec89149b29
Build for loop decl inits correctly
...
The multiple expressions are chained together and evaluate in left to
right order.
2019-06-09 13:54:03 +09:00
Bill Currie
d29ea55826
Add a test for for loop declarations
...
I think the compiler segfaulting indicates a test failure.
2019-06-09 13:02:36 +09:00
Bill Currie
625e767684
Update qf dependency stuff for recent automake
...
Not sure just what version of automake broke things, but I do remember
having a bad time getting the dependencies to work in the first place.
At least now they should be more reliable (until automake changes
things).
2019-06-09 13:00:55 +09:00
Bill Currie
5bd3c8c985
Allow variable declarations in for loops
...
Matches C, C++ and C#
2019-06-08 21:52:17 +09:00
Bill Currie
be4c3a82a2
Detect redefinitions of structs and unions
...
While the redefinition was being detected, it was misreported as the tag
being wrong, and on the wrong line, too.
2019-06-08 19:25:25 +09:00
Bill Currie
f2102187b9
Clean up emit_protocol_list
...
Now it uses emit_structure, which will make it easier should things go
wrong.
2019-06-08 19:23:49 +09:00
Bill Currie
6acbdcb3e5
Correct a typo
2019-06-08 19:23:10 +09:00
Bill Currie
df0316bb13
Clean up some comment FIXMEs
2019-06-08 19:22:29 +09:00
Bill Currie
e217bdd55f
Assign vector expressions to a temp for return
...
Rather than direct to .return, allowing return of vector expressions
with function calls without trashing the vector.
2019-06-08 13:36:03 +09:00
Bill Currie
ebab6574b9
Allow taking the address of a temporary variable
2019-06-08 13:35:47 +09:00
Bill Currie
e27da9c7db
Avoid folding constants in assign_expr
...
This prevents fold_constants from complaining about attempts to take
the address of a vector.
2019-06-08 13:31:30 +09:00
Bill Currie
398e1cf83a
Use output file as base for dot files
...
Ensures the output goes not go into the source directory when using a
separate build tree.
2019-06-08 13:30:06 +09:00
Bill Currie
3327127e36
Fix a typo in a comment
2019-06-08 13:28:29 +09:00
Bill Currie
4ef4a7e955
Start work on simple names in symbol tables
...
I don't remember what the goal was (stopped working on it eight months
ago), but some possibilities include:
- better handling of nil (have trouble with assigning into struts)
- automatic forward declarations ala C# and jai (I was watching vids
about jai at the time)
- something for pascal
- simply that the default symbol type should not be var (in which case,
goal accomplished)
2019-06-06 07:01:44 +09:00
Bill Currie
7e31704ebe
Be more informative for pass by value size errors
2019-06-06 06:46:38 +09:00
Bill Currie
a5da8da1dc
Be more informative for symbol type internal errors
2019-06-06 06:45:48 +09:00
Bill Currie
d00a2ef82d
Convert constant vector expressions in binary expressions
...
Fixes not being able to compare with eg [1, 2, 3]
2019-06-06 06:44:19 +09:00
Bill Currie
319ecfbbfa
Create a usable dot for vector expressions
...
It leaves a lot to be desired, but it beats "FIXME".
2019-06-06 06:42:31 +09:00
Bill Currie
607ec3124e
More dead code removal.
...
I have no idea why this hung around. It appears to be old array/struct
initialization.
2018-10-15 22:12:40 +09:00
Bill Currie
ff5c1cd4c2
Clean up redundant type parameter to initialize_def.
2018-10-15 22:11:20 +09:00
Bill Currie
1746ce3af5
Make int type name reflect its keyword.
...
Makes qc error messages make more sense.
2018-10-15 20:54:05 +09:00
Bill Currie
302934a1e4
Remove some dead code.
2018-10-15 20:52:46 +09:00
Bill Currie
2a2754e581
More ways to break qfcc :/
2018-10-15 19:48:19 +09:00
Bill Currie
6c53be928b
Support returning vector expressions.
...
Currently fails due to a scheduling problem when the vector expression
contains functions.
2018-10-13 23:32:53 +09:00
Bill Currie
aaab18c9a7
Nuke a dead field.
...
It looks like ex_temp_t.expr was never really used, and I have no idea
what I had intended (not surprising after ~17 years).
2018-10-13 12:07:50 +09:00
Bill Currie
2f2edae43b
Make error, warning and notice give compiler file/line too.
...
But only when verbosity > 1 (-vv).
2018-10-13 09:31:00 +09:00
Bill Currie
4828934e50
Fix a equality check typo.
...
Fixes bad code generation when assigning to vector.x in a function with no
parameters and the vector is the first local var.
2018-10-12 23:39:05 +09:00
Bill Currie
78e0a8dc52
Support assigning non-constant vector expressions.
2018-10-12 22:05:17 +09:00
Bill Currie
e03dfa29b4
Clean up the module .ctor construction a little.
2018-10-12 21:09:36 +09:00
Bill Currie
f56d25cda6
Don't double print messages.
2018-10-12 20:46:45 +09:00
Bill Currie
668896aa82
More diagnostic improvements.
2018-10-12 16:01:11 +09:00
Bill Currie
71b3d30aa1
Make the ice a little more informative.
2018-10-12 14:51:39 +09:00
Bill Currie
f58c2fef5a
Switch QF's quaterions from wxyz to xyzw.
...
After messing with SIMD stuff for a little, I think I now understand why
the industry went with xyzw instead of the mathematical wxyz. Anyway, this
will make for less pain in the future (assuming I got everything).
2018-10-12 14:33:55 +09:00
Bill Currie
b7aa5bb8fe
Fix an oops messing up edict size.
2018-10-12 14:33:26 +09:00
Bill Currie
f8606ebab8
Fix a object file segfault when spaces have no data.
...
ie, don't attempt to copy memory from a null pointer (just copy the null
pointer).
2018-10-12 14:00:34 +09:00
Bill Currie
3bd9f96b07
Make internal error messages a little more helpful.
...
They now include the file and line of the compiler as well.
2018-10-12 13:57:59 +09:00
Bill Currie
3656cb966c
Fix some bison deprecation warnings.
2018-10-12 09:32:49 +09:00
Bill Currie
3bc664811e
Fix lost error count tracking.
2018-10-11 22:03:14 +09:00
Bill Currie
a096babb1f
Duplicate memory when creating a qfo from progs.
...
Fixes some double-free bugs when linking after compiling.
2018-10-11 21:37:01 +09:00
Bill Currie
82809eb856
Simplify the call to PR_LoadProgsFile.
...
I've decided that setting pr.max_edicts and pr.zone_size as part of the
local progs initialization rather than in PR_LoadProgsFile makes more
sense. For one, it is unlikely for the limits to change every time progs is
reloaded. Also, they seem to be a property of the VM rather than the progs.
However, there is nothing stopping the caller from updating max_edicts and
zone_size every call.
2018-10-11 10:06:48 +09:00
Bill Currie
673b45be05
Add diagnostic hooks.
2018-10-09 12:46:13 +09:00
Bill Currie
d95c01be1a
More defspace tests.
2018-10-09 12:45:26 +09:00
Bill Currie
34bcf7faab
Do a pure/const/noreturn/format attribute pass.
...
I always wanted these, but as gcc now provides warnings for functions that
could do with such attributes, finding all the functions is much easier.
2018-10-09 12:42:21 +09:00
Bill Currie
05fd2d8cdd
Start work on a unit test for defspace.
2018-09-09 22:37:09 +09:00
Bill Currie
3a4667318c
Fix the qfcc test autodependencies.
2018-09-09 22:36:20 +09:00
Bill Currie
d1cb15664f
Fix some spelling issues in a comment.
2018-09-09 22:34:24 +09:00
Bill Currie
71569b45c9
Pre-format diagnostic messages.
...
This will make it easier to hook diagnostics enabling unit tests.
2018-09-09 18:09:32 +09:00
Bill Currie
113e0d82ba
Fix a signed comparison error.
...
Not sure how this fix got lost.
2018-09-09 16:48:19 +09:00
Bill Currie
59e85b7d5e
Fix a pile of dead assignments.
...
Some were actual bugs!
2018-09-08 22:23:57 +09:00
Bill Currie
59b04dbcca
Make many qfo int fields unsigned.
...
I don't remember why I thought signed was a good idea, but unsigned does
make more sense for most fields.
2018-09-08 19:45:19 +09:00
Bill Currie
f75ff2d269
Fix some null argument issues.
2018-09-07 22:30:44 +09:00
Bill Currie
8f028b8a0d
Fix some double frees.
2018-09-07 20:03:19 +09:00
Bill Currie
8fd5be0ee0
Fix a pile of sizeof goofs.
...
While scan-build wasn't what I was looking for, it has proven useful
anyway: many of the sizeof errors were just noise, but a few were actual
bugs (allocating too much or too little memory).
2018-09-07 20:00:57 +09:00
Bill Currie
b37b0180cb
Actually do a test for triangle.r.
...
If the kahan triangle area method breaks, I did something wrong with qfcc's
handling of parentheses (ie, floating point math is not truly associative).
2018-08-23 20:52:32 +09:00
Bill Currie
1b9149ef31
Fix an argument passing error in test-harness.
...
It failed to pass the last argument to the ruamoko program being run.
2018-08-23 20:22:29 +09:00
Bill Currie
2fcda44ab0
Kill dag leaf nodes on assignment.
...
Fixes the failing swap test caused by a's original value being used (via t)
after being written.
2018-08-23 20:07:22 +09:00
Bill Currie
cb366dd825
Better flow dot dump "scripting".
...
Not sure I want to keep the statements in the live dump, but the system
is more flexible now.
2018-08-23 20:07:11 +09:00
Bill Currie
cdbdf3f0eb
Make print_operand global.
2018-08-23 20:05:16 +09:00
Bill Currie
8b8b42bde2
Fix a typo in a comment.
2018-08-23 20:04:51 +09:00
Bill Currie
f250065003
Add tests for swapping vars and triangle area.
...
Triangle area was meant just to check Kahan's equation, but it found a
problem with swapping vars. swap.r currently fails.
2018-08-21 16:27:22 +09:00
Bill Currie
0f279cd3f0
Add a comment about fake statement numbers.
...
I had forgotten how they worked (not surprising after 6 years).
2018-08-21 15:57:51 +09:00
Bill Currie
1b84ea747c
Dump statements during flow analysis.
2018-08-21 15:56:39 +09:00
Bill Currie
5ba13d759b
Fix a FIXME.
...
Set of everything got added shortly after that FIXME was added, but I
forgot to fix it.
2018-08-21 15:56:03 +09:00
Bill Currie
fbdf560a7a
Rename print_extra_live to print_flow_vars.
2018-08-21 15:55:11 +09:00
Bill Currie
5dbb7b6d4d
Handle all modelgen commands.
...
Just in case someone ever adds models.qc to progs.src.
2018-08-20 00:11:02 +09:00
Bill Currie
027e76b4c9
Add a doc block to parse_cpp_line.
...
It took me too long to figure it out :P
2018-08-20 00:09:20 +09:00
Bill Currie
b795beb520
Add support for \? to qc strings.
...
And fix up the man page a bit.
2018-08-19 19:31:52 +09:00
Bill Currie
0de0eb2fc7
Fix a bunch of bit-rot.
2018-06-08 13:21:30 +09:00
Bill Currie
2329fb1885
Fix some warnings and bitrot.
2016-10-25 00:10:30 +09:00
Bill Currie
932647bad3
Fix a segfault with switch on an undefined symbol.
...
Forgot to check if the test expression was not an error.
2016-01-10 13:41:49 +09:00
Bill Currie
bf40f0126e
Convert vector expressions when passing parameters.
...
Calling a function with [vector stuff] caused an ICE.
2016-01-08 21:16:37 +09:00