Commit graph

178 commits

Author SHA1 Message Date
Bill Currie
1487fa6b50 [qfcc] Implement some basics for the vector types
They're now properly part of the type system and can be used for
declaring variables, initialized (using {} block initializers), operated
on (=, *, + tested) though much work needs to be done on binary
expressions, and indexed. So far, only ivec2 has been tested.
2022-02-04 00:25:31 +09:00
Bill Currie
7e147e703c [qfcc] Copy def reg into alias def
This fixes incorrect local struct member access in Ruamoko progs.
2022-01-24 18:31:53 +09:00
Bill Currie
1f802716e1 [qfcc] Pass initialize_def the symtab to use as a parameter
This takes care of an old FIXME.
2022-01-24 12:48:02 +09:00
Bill Currie
0a5101f88c [qfcc] Specify base register index for local defs
While all base registers can be used for any purpose at any time (this
is why the with instruction has hard-absolute modes: you can never get
permanently lost), qfcc currently uses the convention of register 0 for
globals and register 1 for stack locals (params, locals, function args).
The register used to access a def is stored in the def and that is used
to set the register bits in the instruction opcode.

The def code actually doesn't know anything about any conventions: it
assumes all defs are global for non-temp defs (the function code updates
the defs before emitting code) and the current function provides the
register to use for any temp defs allocated while emitting code.

Seems to work well, but debug is utterly messed up (not surprised, that
will be tricky).
2022-01-21 20:34:43 +09:00
Bill Currie
7bc1396358 [qfcc] Split the function defspace into three spaces
Since Ruamoko now uses the stack for parameters and locals, parameters
need to come after locals in the address space (instead of before, as in
v6 progs). Thus use separate spaces for parameters and locals regardless
of the target, then stitch them together appropriately for the target.
The third space is used for allocating stack space for arguments to
called functions. It us not used for v6 progs, and comes before locals
in Ruamoko progs.

Other than the return value, and optimization (ice, not implemented)
calls in Ruamoko look like they'll work.
2022-01-21 10:20:02 +09:00
Bill Currie
afd1eb775b [gamecode] Rename ev_pointer to ev_ptr
Rather short (no worse than ev_int, though) but more consistency is
usually a good thing.
2022-01-18 14:36:06 +09:00
Bill Currie
cfe7c44df0 [gamecode] Rename ev_integer to ev_int
And other related fields so integer is now int (and uinteger is uint). I
really don't know why I went with integer in the first place, but this
will make using macros easier for dealing with types.
2022-01-18 13:27:19 +09:00
Bill Currie
23c9a317f8 [qfcc] Give alias expressions their own type
While this was a pain to get working, that pain only went to prove the
value of using proper "types" (even if only an enum) for different
expression types: just finding all the places to edit was a chore, and
easy to make mistakes (forgetting bits here and there).

Strangely enough, this exposed a pile of *type* aliasing bugs (next
commit).
2022-01-08 12:06:52 +09:00
Bill Currie
be474d9937 [gamecode] Remove the wart from def and function names
I never liked the leading s_ (though I guess it means one is supposed to
interpret the int as a string pointer, but meh).
2021-12-31 15:02:31 +09:00
Bill Currie
bdc9e9c39f [qfcc] Unalias types before checking for equality
Fixes a bogus redefinition when going from struct declaration to
typedef.
2021-12-24 06:45:13 +09:00
Bill Currie
6144100d9b [qfcc] Check init exists before checking compound
Fixes a segfault that occurred during a parse error in a def
initializer.
2021-09-24 19:44:14 +09:00
Bill Currie
342ba65f57 [qfcc] Handle aliased field types
Fixes use of structs as entity fields. The test is currently
compile-only.
2021-07-24 18:09:54 +09:00
Bill Currie
7970525ef4 [util] Make va thread-safe
It now takes a context pointer (opaque data) that holds the buffers it
uses for the temporary strings. If the context pointer is null, a static
context is used (making those uses of va NOT thread-safe). Most calls to
va use the static context, but all such calls have been formatted
consistently so they are easy to find when it comes time to do a full
audit.
2021-01-31 16:05:48 +09:00
Bill Currie
c7da999b6a [qfcc] Use local_expr only for local variables
ie, not function-scope static variables.
2021-01-13 18:08:30 +09:00
Bill Currie
6d5ffa9f8e [build] Move to non-recursive make
There's still some cleanup to do, but everything seems to be working
nicely: `make -j` works, `make distcheck` passes. There is probably
plenty of bitrot in the package directories (RPM, debian), though.

The vc project files have been removed since those versions are way out
of date and quakeforge is pretty much dependent on gcc now anyway.

Most of the old Makefile.am files  are now Makemodule.am.  This should
allow for new Makefile.am files that allow local building (to be added
on an as-needed bases).  The current remaining Makefile.am files are for
standalone sub-projects.a

The installable bins are currently built in the top-level build
directory. This may change if the clutter gets to be too much.

While this does make a noticeable difference in build times, the main
reason for the switch was to take care of the growing dependency issues:
now it's possible to build tools for code generation (eg, using qfcc and
ruamoko programs for code-gen).
2020-06-25 11:35:37 +09:00
Bill Currie
0de9b02726 [qfcc] Catch declarations of arrays of class
They're still static instances.
2020-03-30 19:02:41 +09:00
Bill Currie
ab3d91f0c3 [qfcc] Clean up simple type checking
All simple type checks are now done using is_* helper functions. This
will help hide the implementation details of the type system from the
rest of the compiler (especially the changes needed for type aliasing).
2020-03-27 15:16:41 +09:00
Bill Currie
0d784d9ef4 [qfcc] Rework address expr calculation
This removes a bogus lea from the instruction stream (and there can be
many such).
2020-03-17 12:13:09 +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
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
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
b6439e8dc1 [qfcc] Support compound init in assignment and params
foo({...}) and bar = {...}
2020-03-11 19:48:25 +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
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
de06efa604 [qfcc] Fix handling of nil for static initializers
nil is most definitely constant.
2020-03-06 20:38:40 +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
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
b186332da0 [qfcc] Make initialization of external vars an error 2020-03-03 17:33:56 +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
b4aebc120e [qfcc] Treat { } as nil for initializing compound types 2020-02-27 20:30:39 +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
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
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
6ce99afa5b Catch double demotion in global initializers
Local initializers are handled by regular assignments
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
a4a57b6ffd Implement aligned allocations 2020-02-15 23:49:12 +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
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
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
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
78e0a8dc52 Support assigning non-constant vector expressions. 2018-10-12 22:05:17 +09:00
Bill Currie
3295370328 Expose and use field_expr().
This may cause problems later on, but it is needed for the binary_expr()
cleanup.
2013-09-27 23:15:57 +09:00
Bill Currie
ca0b03687f Change the naming of ALLOC's free-list.
Rather than prefixing free_ to the supplied name, suffix _freelist to the
supplied name. The biggest advantage of this is it allows the free-list to
be a structure member. It also cleans up the name-space a little.
2013-03-08 22:16:31 +09:00
Bill Currie
3af031c33d Move the rest of the obj specific stuff into class.c.
This gives better hiding of implementation details.
2012-12-20 10:10:41 +09:00
Bill Currie
45c753f639 Catch attempts to create a static instance of a class.
It is actually an error to create a static instance of a class.
2012-12-20 10:10:41 +09:00
Bill Currie
463e41082a Support struct style initializers for vectors and quaternions.
The current implementation probably needs more work, but for the case where
I needed it, it does the job.
grid.r💯     vector      size = {range, range, 0};
0115 store.f range, size
0116 store.f range, [$2ac]
0117 store.f .zero, [$2ad]
2012-12-16 14:24:19 +09:00
Bill Currie
2dc60d4f9a Allow tests for full overlap of defs.
Not actually used yet, but I imagine I'll want it.
2012-12-13 14:42:51 +09:00