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