Commit Graph

778 Commits

Author SHA1 Message Date
Bill Currie 59f48e5e32 [gamecode] Add function to test if string exists
As it returns the string id, it is useful for getting an string id
without risking creating a new one.
2020-04-04 12:32:12 +09:00
Bill Currie 7bcfd2f2be [gamecode] Move file_hash into debug resources
I don't remember why I didn't do this earlier when I thread-safed progs.
2020-04-03 22:39:27 +09:00
Bill Currie fbbe144399 [gamecode] Clean up some stray "struct"
Left over from moving debug data from progs.h to pr_debug.c
2020-04-03 22:35:55 +09:00
Bill Currie c09f57c39e [gamecode] Delay .ctor calls if debugging
This allows a debugger to do any symbol lookups and other preparations
between loading progs and the first code execution. .ctors are called as
per normal if debug_handler is not set.
2020-04-02 17:39:11 +09:00
Bill Currie f90613bc3a [gamecode] Rename fields in pr_stack_t
s and f are a little too succinct.
2020-04-02 15:00:01 +09:00
Bill Currie 41184bd97d [gamecode] Document the format state machine 2020-04-01 20:50:42 +09:00
Bill Currie a36f72f7b4 [gamecode] Support variable field width and precision 2020-04-01 19:45:33 +09:00
Bill Currie 7f4d2215e2 [gamecode] Accept EOS at end of conversion specifier 2020-04-01 18:32:30 +09:00
Bill Currie 7f86fb5529 [gamecode] Rework PR_Sprintf to use a state machine
This makes it much easier to extend. There are even stubs for variable
field width and precision (not set yet).
2020-04-01 13:32:07 +09:00
Bill Currie a7956c7311 [gamecode] Move format state into a state struct
This is the first step in reworking PR_Sprintf to use a state machine.
The goal is to make it more robust against errors and easier to extend
(eg, * width and precision).
2020-04-01 11:19:56 +09:00
Bill Currie e9733416f4 [gamecode] Hide trace messages when debugger is attached 2020-04-01 00:09:34 +09:00
Bill Currie 58acc483fd [gamecode] Save new string ref in return slot
This plugs the memory leak that caused qwaq to crash after resizing the
locals window a "few" times (several seconds of playing with the size).
2020-03-31 20:38:41 +09:00
Bill Currie e2d1a0f7d2 [ruamoko] Tag object memory with the class name
This makes it a lot easier to see what's leaking.
2020-03-31 16:43:10 +09:00
Bill Currie ddec80edc1 [qfcc] Make type encoding union anonymous
I'd do more, but things get messy with direct access to unions that I
want to be anonymous.
2020-03-30 11:10:05 +09:00
Bill Currie 8b1e4eea58 [qfcc] Bring back the core of type aliasing
No aliasing is done yet, but most of the infrastructure is there again.
2020-03-27 12:27:46 +09:00
Bill Currie 1586df4dfc [gamecode] Make it possible to check string mutability 2020-03-26 16:38:09 +09:00
Bill Currie ec82d6b027 [gamecode] Add support for holding ephemeral strings
PR_HoldString converts ephemeral (temp and return) strings to dynamic
strings. This makes dealing with strings in progs a little easier.
2020-03-26 16:36:29 +09:00
Bill Currie b4874f7d9b [gamecode] Make PR_FreeString a little more forgiving
It treats only strings that are actually invalid as invalid. That is,
now it is safe to "free" a static string: it's just a no-op.
2020-03-26 15:48:04 +09:00
Bill Currie 22e2695f80 [gamecode] Add VISIBLE to some missed functions 2020-03-26 15:36:46 +09:00
Bill Currie 2d5df34234 [gamecode] Add VM enter/exit events
And rename prd_exit to prd_terminate (the idea is the host will
terminate the VM). This makes it possible for the debugger to pause the
VM before any code, even a builtin function, is executed. Breaks the
debugger source window, but only because it's not updating on file
change (I think).
2020-03-26 12:30:32 +09:00
Bill Currie 1bd8e2ee85 [gamecode] Add a param pointer to debug_handler
I decided I want events for VM enter/exit but enter needs to somehow
pass the function which will be executed (even if a builtin). A generic
void * param seemed the best idea, which meant the error string could be
passed via the param instead of a "global" string in the progs struct.
2020-03-26 11:44:02 +09:00
Bill Currie 4cef9792f4 [util] Make hash-tables semi-thread-safe
They take a pointer to a free-list used for hashlinks so the hashlink
pools can be per-thread. However, hash tables that are not updated are
always thread-safe, so this affects only updates. progs_t has been set
up such that it is easy for multiple progs within one thread can share
hashlinks.
2020-03-25 15:43:16 +09:00
Bill Currie c945c42989 [gamecode] Fix some silly errors
I forgot to compile-test :(
2020-03-24 23:16:25 +09:00
Bill Currie d867a1a9f1 [gamecode] Allow watch-point to be updated
With the watch-point address cached in a local var, it was not possible
to update the watch-point while the progs were executing.
2020-03-24 19:45:39 +09:00
Bill Currie 713150b41a [gamecode] Add debug hooks to the VM engine
While there was a breakpoint hook, it was for only breakpoints and more
was needed. Now there's a generic hook that is called for tracing,
breakpoints, watch points, runtime errors and VM errors, with the
"event" type passed as the first parameter and a data pointer in the
second.
2020-03-24 19:45:10 +09:00
Bill Currie 1d6843d7f0 [gamecode] Improve watchpoint handling a little
Mostly just update the old value if the condition didn't trigger.
2020-03-24 13:26:35 +09:00
Bill Currie 753d183d82 [gamecode] Be more informative with function calls
PR_EnterFunction and PR_LeaveFunction now print the
entered/left/returned function when tracing. Makes debugging obj code
much easier.
2020-03-24 13:24:55 +09:00
Bill Currie b544a052bf [gamecode] Bail if PR_SearchDefs is given 0 defs
Fixes the hang when searching for a field in progs that don't have any.
2020-03-16 14:24:48 +09:00
Bill Currie e3a1413ad3 [gamecode] Tweak output for lea 2020-03-15 10:06:37 +09:00
Bill Currie 99f89840f9 [gamecode] Show containing def and relative offset
No more guessing when accessing structure field members. Next is ivars,
I guess.
2020-03-15 02:51:29 +09:00
Bill Currie 3d62a7f253 [gamecode] Use fuzzy bsearch to find defs by address
The idea is to find th def that contains the address. Had to write my
own bsearch (well... lifted from wikipedia) because libc's is exact. The
defs are assumed to be sorted (which qfcc now ensures when it writes
progs and sym files).
2020-03-15 02:48:13 +09:00
Bill Currie 2f9f6d3aa9 [gamecode] Relocate aux function return types
They are written with offsets relative to the type encodings base.
2020-03-14 23:39:14 +09:00
Bill Currie 9492f08536 [gamecode] Print structs as well as unions
Much better :)
2020-03-14 21:03:01 +09:00
Bill Currie fea6381574 [gamecode] Rework debug type handling a little
Type encodings are used whenever they are available. For now, if they
are not, then everything is treated as void (which prints <void>, not
very useful). Most return statements and references to .return are now
very readable (excluding structs), and only params going through "..."
are a messy union.
2020-03-14 20:44:43 +09:00
Bill Currie a069fad41e [gamecode] Print only entity address when no edicts
If the edicts pointer is null, it's not possible to convert the entity
address to an index.
2020-03-13 20:16:06 +09:00
Bill Currie a0d85e33c2 [gamecode] Rework implementation of memset*
The memset instructions now match the move* instructions other than the
first operand (always int). Probably breaks much, but fixed in next few
commits.
2020-03-13 17:50:57 +09:00
Bill Currie 087cee06be [gamecode] Use full precision for floating point values 2020-03-13 14:57:33 +09:00
Bill Currie 6dfe37635d [gamecode] Dump union contents
The output is messy, but better than <union>
2020-03-13 14:56:56 +09:00
Bill Currie 6ca85d770d [gamecode] Add memset instructions 2020-03-11 22:48:55 +09:00
Bill Currie 023a920a51 [gamecode] Replace lost parameter auto-reset
rcallN messes with the progs parameter pointers and not resetting them
can cause incorrect data to be copied into the called function.
2020-03-11 19:38:50 +09:00
Bill Currie 6c56e93fc8 [gamecode] Be more careful with temp strings
If a temp string is found in the return slot, PR_FreeTempStrings won't
delete the string. However, PR_PopFrame was blindly stomping on the
possibly surviving temp string with the push strings, which would cause
a leak.
2020-03-10 03:24:31 +09:00
Bill Currie f290b115a5 [gamecode] Add function PR_PushTempString
This "pushes" a temp string onto the callee's stack frame after removing
it from the caller's stack frame. This is so builtins can pass
auto-freed memory to called progs code. No checking is done, but mayhem
is likely to ensue if a string is pushed that was allocated in an
earlier frame.
2020-03-09 23:36:09 +09:00
Bill Currie 7d43bd5c66 [gamecode] Add function PR_AllocTempBlock()
PR_AllocTempBlock() works the same way as PR_SetTempString(), except
that it takes a size parameter and always allocates (never tries to
merge). This is, in a way, abusing the string system, but I needed a way
to allocate a block of progs memory that would be automatically freed
when the current frame ended. The biggest abuse is the need to cast away
the const of PR_GetString()'s return value.
2020-03-09 22:16:19 +09:00
Bill Currie 5f299cbac7 [gamecode] Ensure static string refs are initialized
That was a fun one to track down :P
2020-03-08 21:29:31 +09:00
Bill Currie c726d77e7d [gamecode] Respect the @float_promoted@ magic string
Rather than relying on progs code version, use the string to determine
whether PR_Sprintf should behave as if floats have been promoted through
... I imagine I'll get to the rest of the server code at some stage.

With these two changes, nq-x11 works again (teleporters were the
symptom).
2020-03-08 19:19:15 +09:00
Bill Currie 68fc11857a [gamecode] Fix a string splitting error 2020-03-04 21:10:23 +09:00
Bill Currie c214797e97 [gamecode] Fix some curly space
and add some comments. took a bit to figure out what i was doing
2020-03-04 21:09:36 +09:00
Bill Currie 4e4b553cc3 [gamecode] Take care of missed type alias stuff 2020-03-01 16:20:23 +09:00
Bill Currie 789f263855 Use get_strref() correctly
I had forgotten that it works only for dynamic strings.
2020-02-27 02:07:53 +09:00
Bill Currie c9186c8296 Clear the statement line buffer
The problem with moving to a cached buffer is it needs to be cleared.
Fixes the weird output of qfprogs and tracing (not missing local defs,
though).
2020-02-27 01:25:41 +09:00
Bill Currie 62b541793d [gamecode] Remove all use of va
With this, the VA is very close to being safe to use in a threaded
environment (so long as each VM is used by only one thread). Just the
debug file hash and source paths to sort out.
2020-02-26 19:30:10 +09:00
Bill Currie 36bc139b27 Avoid use of va in PR_Sprintf
With this, progs strings are thread safe so long as only one thread
tries to use the VM.
2020-02-26 18:35:19 +09:00
Bill Currie 0f4d89a832 Move free_fmt_items into strings resources
This will make it per-thread.
2020-02-26 18:19:21 +09:00
Bill Currie 225a375ab9 Extend the lifetime of return-strings
This is done by putting the most recently used return-string at the end
of the queue for recycling.
2020-02-26 13:43:03 +09:00
Bill Currie aa02069dd1 Add a breakpoint flag to opcodes
The progs execution code will call a breakpoint handler just before
executing an instruction with the flag set. This means there's no need
for the breakpoint handler to mess with execution state or even the
instruction in order to continue past the breakpoint.

The flag being set in a progs file is invalid.
2020-02-26 13:40:26 +09:00
Bill Currie d60291a73e Clean up a lot of va usage
va is not thread-safe (it's not save even without threads), and I want
to be able to run progs in threads.
2020-02-26 09:46:59 +09:00
Bill Currie 42713cad8b Make script much friendlier to use
It now simply sets an error message pointer and returns false if there's
an error.
2020-02-26 09:39:03 +09:00
Bill Currie 4c1b6ce76c Make pr_parse thread safe
Or at least, conversion to property list is thread safe.
2020-02-26 01:55:56 +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 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 e3953be8f8 Ensure execution state is initialized on progs load 2020-02-25 15:25:10 +09:00
Bill Currie 61d7f4f9c4 Dump locals stack when dumping main stack
Any shutdown functions in progs will need locals too.
2020-02-25 15:18:15 +09:00
Bill Currie 6a4ef598ab Allow progs num_edicts and reserved_edicts to be null
Really, while there are edict related instructions, edict support should
probably not be in the VM itself.
2020-02-25 15:00:33 +09:00
Bill Currie 6e56c9a4aa Ensure edict_parse is reset on progs load
A server switching from a game that sets edict_parse to one that does
not could go badly when it comes time to loading a level.
2020-02-25 14:40:03 +09:00
Bill Currie 9bb68f2d8c Allow nested use of PR_SaveParams()
PR_SaveParams() is required for implementing the +initialize diversion
used by Objective-QuakeC because builtins do not have local def spaces
(of course, a normal stack calling convention would help). However, it
is entirely possible for a call to +initialize to trigger another call
to +initialize, thus the need for stacking parameter stashes. As a
bonus, this implementation cleans up some fields in progs_t.
2020-02-25 14:30:26 +09:00
Bill Currie 99c818adcc Ensure progs zone is always set on load 2020-02-25 00:25:24 +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 7406e0308e Fix some warnings picked up in an optimized build 2020-02-24 11:28:43 +09:00
Bill Currie dda045bf96 Do lazy computation of def sizes from type encodings
The size is calculated when needed and cached.
2020-02-23 23:29:58 +09:00
Bill Currie 23573953a7 Change pr_type_size to pr_ushort_t 2020-02-23 22:25:08 +09:00
Bill Currie d0dc0e15fb Handle alias types in debug prints 2020-02-23 19:02:16 +09:00
Bill Currie b173c35eb4 Rework progs debug to use the type encodings
It's only a start: the output is, if anything, slightly worse than
before, but it does have the basics going.
2020-02-23 19:01:59 +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 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 c296514b95 Make pr.load_file 'return' the file size 2020-02-21 21:17:28 +09:00
Bill Currie ed283a9e7f Copy only the necessary number of vararg parameters 2020-02-16 18:00:29 +09:00
Bill Currie 12d2a0ff75 Copy the correct number of words for rcall 2020-02-16 17:58:36 +09:00
Bill Currie f5741a979e Implement parameter alignment in the engine
The engine now requires non-v6 progs to store the log2 alignment for the
param struct in .param_alignment.

PR_EnterFunction is clearer and possibly more efficient.
2020-02-16 17:13:45 +09:00
Bill Currie 32c21ec559 Make gcc accept the bitwise-boolean magic
Forgot to compile check...
2020-02-16 12:08:08 +09:00
Bill Currie b4fd804e4e Implement true modulo in the engine 2020-02-16 11:53:56 +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 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 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 f68129dc0f Try to use type encodings for function return type
Now return statements in traces make much more sense.
2019-06-09 18:11:56 +09:00
Bill Currie 0f5f2a125a Use a reliable reference for calculating progs offsets.
Now that pr->zone can be null, it cannot be used as a reference. Fixes
random crashes when using qfprogs (random due to heap randomization).
2018-10-13 23:23:45 +09:00
Bill Currie b7aa5bb8fe Fix an oops messing up edict size. 2018-10-12 14:33:26 +09:00
Bill Currie 33cbc500e8 Fix a segfault when setting up the stack.
Yup, putting {}s around even single statements under flow control (if, etc)
is a good idea. Wonder if there's a gcc warning for that...
2018-10-11 13:34:08 +09:00
Bill Currie 6252faa069 Fix a size error in OP_LOAD_Q.
C&P from OP_LOAD_V :/
2018-10-11 13:25:32 +09:00
Bill Currie 364c2d2c2b Add a stack and push and pop instructions.
The stack is for data, not return addresses.
2018-10-11 13:24:03 +09:00
Bill Currie 61185813fa Cleaner handling of zone_size/zone. 2018-10-11 10:22:10 +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 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 59e85b7d5e Fix a pile of dead assignments.
Some were actual bugs!
2018-09-08 22:23:57 +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 0de0eb2fc7 Fix a bunch of bit-rot. 2018-06-08 13:21:30 +09:00
Bill Currie 546e333a3c Allow Sys_Error to be hooked.
This makes debugging builtins that wrap normal functions a little easier by
giving a progs dump when such an error occurs.
2016-01-03 23:04:00 +09:00
Bill Currie 7b350b2a1b Indicate calls to builtins when tracing.
This makes following progs traces a little easier.
2016-01-03 16:13:59 +09:00
Bill Currie 3efb0c538f Separate file search from loading.
QFS_LoadFile (and its wrappers) now  take a file handle rather than a
path. This will make vpath usage a little cleaner to implement.
2014-01-28 16:22:05 +09:00
Bill Currie 4c6478c77f Strip trailing spaces from field names.
A certain mod (glare at rogue) has a space at the end of a field name in
the bsp entity data causing a crash. Thanks to ccr for the report.
2013-11-26 14:27:49 +09:00
Bill Currie f5501fbf24 Fix a pile of automake deprecation warnings.
s/INCLUDES/AM_CPPFLAGS/g

I <3 sed :)
2013-11-24 13:11:50 +09:00
Bill Currie 99a8e8f228 Fix the jump instruction.
The offset to compensate for st++ was missing.

Obviously, the code has never been tested.  Found while looking at the
jump code and thinking about using 32-bit addresses for the jump tables.
2013-06-26 09:59:19 +09:00
Bill Currie 7c1d9d2b84 Make the angle and light hacks optional.
I'd forgotten that ED_ConvertToPlist mangled light into light_lev and
single component angle values into a vector. This fixes much of the
breakage in qflight (but not the light levels)
2013-03-07 09:11:23 +09:00
Bill Currie 675db274a6 Use Sys_Error instead of PR_Error in ED_ConvertToPlist.
ED_ConvertToPlist is now independent of the progs engine as its only use
for the progs_t * param was for PR_Error.
2013-03-07 09:11:22 +09:00
Bill Currie 7d2e938d37 Correct some error messages.
ED_ParseEntity has been ED_ConvertToPlist for a long time now.
2013-03-07 09:11:22 +09:00
Bill Currie e27d7cbd2d Handle alloca "correctly".
Use AC_FUNC_ALLOCA and the #ifdef mess suggested by the autoconf docs
(hidden in qfalloca.h).
2013-01-22 21:02:50 +09:00
Bill Currie 6b05a7e964 Add (%Ec) to OP_ADDRESS's format specifier.
This makes OP_ADDRESS and OP_LOAD_* consistent.
2013-01-17 16:43:54 +09:00
Bill Currie c25e68ecaf Use hex output for %E opcode format specifier.
This makes %E's addresses consistent with other address output.
2013-01-17 16:42:28 +09:00
Bill Currie 3c67e8f020 Fix the vector/quaternion scaling instructions.
It was pointed out by Blub\w (gmqcc) that OP_MUL_FV and friends were buggy
when the operands overlapped (eg, x = x.x * x) as the result would become
'x.x*x.x x.y*x.x*x.x x.z*x.x*x.x' (note the x.x squared for y and z). On
testing, sure enough the bug was present (and is a nice demonstration that
QF's VM does NOT have strict-aliasing bugs). As a very nice benefit: the
code produced by the fixes is actually faster than the broken version :).

The ruamoko code used for testing:
void (string fmt, ...) printf = #0;

vector foo (vector x)
{
    x = x * x.x;
    return x;
}

vector bar (vector x)
{
    x = x.x * x;
    return x;
}

int main ()
{
    vector x = '2 3 4';
    vector y = foo (x);
    vector z = bar (x);
    printf ("x=%v y=%v z=%v 2*x=%v\n", x, y, z, 2*x);
    return 0;
}
2013-01-17 10:23:02 +09:00
Bill Currie 6b97967a68 Use g instead of e for the fp values.
Need to up the precision by one due to the difference between g and e, but
much prettier. Might need to rename that function :P I wish I'd thought to
check if g would work, but thanks to divVerent for the suggestion.
2013-01-08 20:15:24 +09:00
Bill Currie b096a0242e Write fp values to saved games with enough precision.
That is, enough precision to uniquely identify the fp values. No drifts!
2013-01-08 18:50:44 +09:00
Bill Currie 9155338404 Add support for int and quaternion values in saved games. 2013-01-08 18:09:22 +09:00
Bill Currie 3e2a40684c Use dstring in PR_UglyValueString().
I should have done this a long time ago:P. This removes the really silly
255 char limit from strings in saved games (and thus fixes books in ITS).
2013-01-08 17:20:58 +09:00
Bill Currie e0e69ac71a Fix some signed/unsigned comparison warnings.
It seems mingw's gcc treats pointer subtraction differently to how linux's
gcc does.
2013-01-05 17:52:48 +09:00
Bill Currie 3b63c31b5d Use pr_return for the null pointer check.
The params come after the return slot :P. Getting a null pointer exception
for movep from .return wasn't very funny.
2012-12-26 11:47:53 +09:00
Bill Currie 1fdc32bb39 Check for null VM pointer accesses.
Currently only four words of "null pointer protection" are available, but
it's a start.
2012-12-22 14:24:11 +09:00
Bill Currie 6eb6b6c0ba Change pointer_t to unsigned and clean up the mess.
It doesn't make sense to have negative pointers. The size of the commit is
from enabling gcc's -Wtype-limits warning and cleaning up that mess too.
2012-12-21 21:53:13 +09:00
Bill Currie 11b991cf9d Print the error message before the state dump.
Normally, the order doesn't matter, but when tracing code, it becomes very
difficult to tell where the trace ends and the dump begins. Printing the
message first puts the message between the trace and the dump: much easier
:)
2012-12-16 12:27:15 +09:00
Bill Currie 34e3ac1468 Fix jumpb's operand types.
Aliasing the jump table to an integer broke statement_get_targetlist with
the new alias def handling, and was really wrong anyway. I probably did
that due to being fed up with things and wanting to get qfcc working again
rather than spending time getting jumpb right.
2012-12-05 22:20:55 +09:00
Bill Currie 49ad301d3d Add improved memory checking to progs.
With pr_boundscheck >= 2, pointer access will be checked against allocated
blocks (qfvalgrind?:). Currently extremely basic, but it seems to work.
2012-11-19 20:03:21 +09:00
Bill Currie b8b626ee81 Change the int<->float conversion opcode string.
Using "=" was rather confusing, so changing it to "<CONV>" seems to be a
good idea. As the string is used only for selecting opcodes at compile
time, only qfcc is affected.
2012-11-16 14:45:11 +09:00
Bill Currie 1f9735d0cb Correct the dump format for conj.q. 2012-10-27 11:45:10 +09:00
Bill Currie ec42bde527 Make hash tables more const correct.
And clean up the resulting mess :/
2012-10-27 11:44:31 +09:00
Bill Currie cc35209f86 Yet more char index issues :P 2012-08-18 12:20:08 +09:00
Bill Currie 106257d6e9 Allow reconstructed builtins to be found by name.
Certain versions of qcc (fteqcc comes to mind :P) strip the names from
builtin functions. This breaks saved games that happen to have a builtin
function in a saved function variable. The earlier builtin name
reconstruction patch happened to fix the writing of save games for such
progs, and this one fixes the reading.
2012-07-20 16:17:26 +09:00
Bill Currie d73b5045d8 Do not do any contents evaluation if not printing contents.
Fixes a segfault when tracing progs caused by the recent entity number
change.
2012-07-18 10:46:59 +09:00
Bill Currie 8691a2fbd1 Dump a stack trace when running out of edicts. 2012-07-18 10:30:58 +09:00
Bill Currie a9adc94aa8 Force builtin function descriptors to have a name.
That is, the descriptors loaded from the progs file. Some compilers (eg,
fteqcc :P) strip builtin names from the progs, which makes debugging
difficult.
2012-07-13 10:22:25 +09:00
Bill Currie 6e0907a6b1 Delay the "too many entities" check.
Rather than checking the raw edict count in the entities file against the
progs' max_edicts, check the allocated entity's number. This allows loading
of sophisticated maps (eg, digs04) that prune many of their entities.
2012-07-09 15:07:34 +09:00
Bill Currie ce16750b04 Cache the max_edicts value in the progs struct.
Makes checks a little easier.
2012-07-09 15:06:42 +09:00
Bill Currie e91b06a144 Better name for the edict count parameter to PR_LoadProgsFile. 2012-07-09 15:02:49 +09:00
Bill Currie ac1bf2a158 Don't save unnamed fields.
There will normally be only one unnamed field (if any), and it's always the
null field. This will put an eventual end to the "'' is not a field"
messages.
2012-06-10 20:56:22 +09:00
Bill Currie 23a38738fc Massive whitespace cleanup.
Lots of trailing whitespace and otherwise blank lines.
2012-05-22 08:23:22 +09:00
Bill Currie 0036a5e113 Ensure edict_size is never 0.
Avoids division by / in NUM_FOR_EDICT
2012-05-06 21:35:42 +09:00
Bill Currie 1a0ccf6a92 Add vec = quat * vec to the progs engine. 2012-04-26 11:58:20 +09:00
Bill Currie 0a22a98b60 Fix some mis-versioned opcodes.
Many of the quaternion opcodes were marked as being available for id progs.
oops
2012-04-26 10:26:43 +09:00
Bill Currie bc1b483525 Nuke the rcsid stuff.
It's pretty useless in git.
2012-04-22 10:56:32 +09:00
Bill Currie 3cb4cb59b5 Link QFgamecode directly into QFruamoko.
First step in the library "merge down".

QFgamecode is now a convenience library. The only things that mention it
directly now are ruamoko and qfcc.
2012-02-13 15:05:31 +09:00
Bill Currie 9fbff2f4d5 Do an audit of the Makefile.am files.
o All instances of LIBADD/LDADD have a corresponding DEPENDENCIES
    specificatiion.
  o libraries now use a lib_ldflags macro to keep things consistent
  o duplication of source/lib names has been minimized (particularly in
    the libraries; more work needs to be done for the executables)
  o automake spec blocks have been organized (again, more work needs to be
    done for the executables)
2012-02-07 16:04:19 +09:00
Bill Currie b5019c8e33 Nuke the engine dicrectory from gamecode.
Not the contents, of course :) Anyway, finally, that totally useless
directory is gone.
2012-02-06 23:44:52 +09:00
Bill Currie be9f05ea14 Catch progs zone errors and give a stack dump. 2012-02-06 12:48:22 +09:00
Bill Currie cc5140e3a1 Move min/max/bound and field_offset into better locations.
min/max bound into mathlib.h (they /are/ math functions, after all) and
field_offset into qtypes.h.
2011-12-24 10:04:33 +09:00
Bill Currie 581539f7af Make debug printing a little smarter.
When a field or global name is used, the printed value reflects the type
of that variable.
2011-09-07 09:41:06 +09:00
Bill Currie 91f6b7f555 Better use of Sys_Printf. 2011-09-07 09:41:06 +09:00
Bill Currie f75b0a611b Some compile fixes for OpenBSD 2011-08-25 22:35:20 +09:00
Bill Currie bb065bd233 Be a little leniant with vector param stores.
qcc always used vector stores to load values into the function parameters,
but if the location of the value is too close to the end of the global data
block (the vector spans the end of the block), it would trigger the bounds
check code. Thus, allow such instructions without a murmer, so long as it
actually is a parameter write.
2011-08-16 12:10:05 +09:00
Bill Currie d3c2afc5d7 Handle old global vector compontents.
In the original save gave format, global vectors were saved as individual
components rather than as a single vector, using the _x/_y/_z tags on the
vector name. However, recent qfcc completely dumped vector components as
separate defs, so old save games would have trouble loading with progs
built with a recent qfcc. Thus, do the component translation if necessary.
2011-08-11 15:36:51 +09:00
Antti Harri 358a844a42 Implement --version-info configure switch to override QuakeForge
library versioning. From Lasse Collin, thanks!
2011-07-09 01:23:36 +03:00
Bill Currie 74a7e07dfc Use AM_CFLAGS instead of CFLAGS.
CFLAGS is meant to be reserved for the user.
2011-05-10 12:44:44 +09:00
Bill Currie d3771dfeba Resolve some inlining issues in recent gcc. 2011-05-04 09:31:18 +09:00
Bill Currie 2a2a431431 Register a complaint when the map has too many entities.
I was wondering why that parrot was dead.

Not realizing that negke's coag3 map had too many entities really ruined
the pleasure of playing it, so it's best to treat such situations as an
error (max_edicts can be bumped up to 32000 if need be, but 2048 is plenty
for his map).
2011-04-17 20:06:20 +09:00
Bill Currie 55cc0f9206 Bring back the unsigned type (PROGS version bump)
This is only low-level support (the unsigned keyword still does not work),
but sufficient to make switch statements using jump tables work.
2011-04-09 10:07:47 +09:00
Bill Currie b0d1e782ee Treat allocating less than 1 byte as an error. 2011-03-24 11:10:08 +09:00
Bill Currie 025c39cc02 Ensure stdout is flushed in the progs signal_hook() 2011-03-20 13:35:59 +09:00
Bill Currie 104c29e4da Avoid a segfault when the called function is invalid.
This is most likely to occur when dumping code from qfo files with external
functions.
2011-03-20 13:35:12 +09:00
Bill Currie f20424afe5 Make "bad type" output more useful.
Print the four (assumes non-v6) values in hex rather than "bad type".
2011-03-17 20:35:14 +09:00
Bill Currie ebfbd7c358 Disable the unsigned comparison instructions.
They need unsigned support, or special treatment, so they have to wait.
2011-03-17 20:33:38 +09:00
Bill Currie bce3935ea6 Add a void address instruction. 2011-03-10 19:28:03 +09:00
Bill Currie 90de6b0499 Add a movepi instruction to support indirect moves of fixed size. 2011-03-09 10:29:24 +09:00
Bill Currie 18005cc80d Rename move to movei. 2011-03-09 10:28:40 +09:00
Bill Currie 6c4563b21d Change movep's name from <MOVE> to <MOVEP>. 2011-03-09 10:25:20 +09:00
Bill Currie 4432bc0bef Make the offset in zone dumps more useful. 2011-03-08 22:44:56 +09:00
Bill Currie 5b8345eecb Do not try to print values from null entities. 2011-03-07 08:28:20 +09:00
Bill Currie 3b8a3f8302 Remove the vector component skip code from param searches.
Local defs no longer contain the vector comonents.
2011-03-06 21:02:29 +09:00
Bill Currie 4794d66f42 Change jumpb's opa type to integer.
I'm not 100% certain this is correct...
2011-03-03 19:06:17 +09:00
Bill Currie 57f735c99c Avoid another segfault when debugging. 2011-02-15 15:33:18 +09:00
Bill Currie 52010b8f7b Do not segfault with bogus debug info. 2011-02-14 23:10:45 +09:00
Bill Currie 55b7f6eee4 Avoid another segfault when debugging. 2011-02-09 10:13:08 +09:00
Bill Currie de33cd6017 Ensure auxfunction_map is properly initialized. 2011-02-09 08:28:20 +09:00
Bill Currie f72d6d6a27 Fix a typo in the opname for integer modulo. 2011-01-27 21:03:11 +09:00
Bill Currie 3c9991364b Add a "void return" instruction.
I got fed up with always having to explicty return something.
2011-01-13 00:29:56 +09:00
Bill Currie 6650b35201 Make PR_Get_Param_Def aware of @args. 2011-01-10 12:25:31 +09:00
Bill Currie 75ec6bf244 Clean out some unnecessary types from the progs engine and clean up the mess.
This is a nasty commit, sorry, but 99% of the commit is interdependent.
2011-01-10 12:25:31 +09:00
Bill Currie a85c0713aa Nuke libQFbuiltins.
The gib and "common" builtins are now part of libQFruamoko.
2011-01-04 21:21:19 +09:00
Bill Currie 8e557e81b6 Break out the guts of Ed_LoadFromFile into ED_Parse.
ED_Parse does not support progs privided parsing (at this stage, anyway),
but this will allow clients to easily get at the entities in a map.
2010-12-10 17:17:29 +09:00
Bill Currie 8c4fe2f844 Rename Sys_DPrintf to Sys_MaskPrintf.
We now have finer runtime control over what gets printed. Need to do a
SYS_DEV audit, creating new masks as apropriate.
2010-11-26 16:19:26 +09:00
Bill Currie fc2a6e0fb7 Don't be so spammy with file errors.
Record a file even if it could not be found. This way, the error message
gets printed once per file rather than every time.
2010-11-24 17:01:18 +09:00
Bill Currie 3309f483b6 Don't require pr_boundscheck for quoth.
I don't know about other FTEqcc compiled progs, but quoth doesn't try to do
anything clever (all its denormals are either vars of the wrong type, or
-0.0).
2010-11-20 14:12:40 +09:00
Bill Currie 9d6fd32206 Ensure the the progs data is aligned.
Some QuakeC compilers (eg, FTE) insert a data chunk between the progs
header and the rest of the progs data. Unfortunately, FTE does not maintain
the assumed 32-bit alignment.
2010-11-20 09:02:56 +09:00
Bill Currie 2f504709dd Print data being loaded from an entity. 2010-11-20 00:31:34 +09:00
Bill Currie f63e505c92 Don't realloc the string pointer table.
This causes a bit of memory waste, but avoids breaking the pointers in the
string hash table.
2010-11-14 19:21:16 +09:00
Bill Currie e6b783a616 Don't touch the watchpoint conditional when printing. 2010-11-13 14:36:33 +09:00
Bill Currie 0dfff8fd58 ignore stuff 2010-08-07 10:42:09 +00:00
Bill Currie c1b12ed6ec fix a couple of gcc 4.5 issues that Despair pointed out (I don't have it yet) 2010-05-27 12:21:50 +00:00
Bill Currie 7827086b54 make sure we actually have a stack frame 2010-01-13 06:42:59 +00:00
Bill Currie 997102fea8 audit the usage of "only"
There are still a few iffy places (notably around certain prepositions), but
the relevant sentences are now much easier to read.
2010-01-13 06:42:26 +00:00
Bill Currie 0a203c0ab5 qccx (etc) "integer" autodetection.
Check for usage of denormal floats and if found, either bail with a
descriptive error message or give a mild warning that things will probably
break. This avoids the possibility of things like RuneQuake getting "lucky"
and doing real harm, and certainly avoids the segfaults.
2010-01-13 06:36:54 +00:00
Bill Currie 00e590f5f5 Really nail down the args param in rua_obj_msg_sendv(). 2010-01-13 06:36:16 +00:00
Bill Currie 5c788d8d44 state.f is not an id instruction 2010-01-13 06:30:07 +00:00
Bill Currie e0d669590c plug a memory leak
the progs memory was never being freed between maps because the pointer was
being cleared at the start of PR_LoadProgsFile.
2010-01-13 06:27:19 +00:00
Bill Currie 5d6977288f implement bounds checking on all opcodes 2010-01-13 06:19:50 +00:00
Bill Currie 4a7b8f8246 don't look up aux function info when we don't have it 2009-12-21 14:07:43 +00:00
Bill Currie fe95805d86 various gcc 4.3 fixes 2008-07-19 05:40:57 +00:00
Bill Currie 2b81eaea6c console.h include cleanup 2007-11-06 12:40:38 +00:00
Bill Currie c04d9ef8c2 plug a potential (though unlikely) memory leak 2007-10-13 11:32:10 +00:00