Commit Graph

3561 Commits

Author SHA1 Message Date
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 67e183c8b6 Put the guts of qwaq's reflection code into ruamoko 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 9d09d65d9a Clean up some export stuff
While it's not there yet, the eventual goal is to support multiple
models in the one blend file, so per-object settings is a requirement.
2019-08-20 16:52:43 +09:00
Bill Currie c14e5623ad Get the mdl frames script property working
Maybe late 2.78+, blender added the ability to use any ID type in
PointerProperty, which is just what I wanted for the frames script.
2019-08-16 22:34:45 +09:00
Bill Currie 839d90981d Clean up a few last things for blender 2.80
Many many thanks to Aleksander Marhall for the initial work.
2019-08-16 22:32:37 +09:00
khreathor 008b5a4d2c Import/Export fixes after some Blender 2.8 API changes 2019-08-16 21:38:29 +09:00
khreathor 11e5f39fdc Fix for the export error when there is no Shape Keys available 2019-08-16 21:38:29 +09:00
khreathor 36da80c0d0 Export proper frame names 2019-08-16 21:38:29 +09:00
khreathor 33d114c09e Set playback/animation range to start from frame 1 2019-08-16 21:38:29 +09:00
khreathor ff5f9f1831 Add "empty" skin during export for models with no materials or texture nodes 2019-08-16 21:38:29 +09:00
khreathor 3913febace MDL properties in object panel are back 2019-08-16 21:38:29 +09:00
khreathor 31fa7a81ef Fix for single skin being marked as skingroup 2019-08-16 21:38:29 +09:00
khreathor 94c3c8c2cb Skingroup image export order based on texture node position (height) in shader editor. Nodes with higher position are exported first. 2019-08-16 21:38:29 +09:00
khreathor 4f29f57e77 Proper node positioning after import 2019-08-16 21:38:29 +09:00
khreathor a13c382969 Skingroup images import order fix 2019-08-16 21:38:29 +09:00
khreathor 4d1f05186b Skingroups export added 2019-08-16 21:38:29 +09:00
khreathor 17e76149a1 Adjust playback range on import, to fit mdl's animation length 2019-08-16 21:38:29 +09:00
khreathor 66fe862a87 Import skingroups as separate materials with skins as textures 2019-08-16 21:38:29 +09:00
khreathor ae86790e6c Initial Blender 2.8 changes - it works, now it's time for improvements 2019-08-16 21:38:29 +09:00
khreathor 8112c4e8b6 Moved MDL settings from Object tab to export options/presets 2019-08-16 21:38:29 +09:00
khreathor 90a707f7f9 Export animation range selected with start/end playback range in Timeline Editor 2019-08-16 21:38:29 +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