Commit graph

85 commits

Author SHA1 Message Date
Christoph Oelckers
66b1f36e56 - actually evaluate the default parameters and store them in the VMFunction.
- disabled the assert in PType::GetRegType. This assert blocks any use to check for types that are incompatible with function parameters.
- pass the default parameter constants to the native functions. At the moment this is not used yet.
- use the function defaults to complete argument lists to script functions.
- fixed all default values that got flagged by the expression evaluator as non-constant. Most were state labels and colors which were defaulted to "". The proper value is null for states and 0 for colors.
- also replaced all "" defaults for names with "none".
2016-10-27 01:30:34 +02:00
Christoph Oelckers
d32d52c0b9 - scriptified a_spidermaster.cpp.
- fixed bad assert in XOR_RK instruction.
2016-10-26 17:21:25 +02:00
Christoph Oelckers
a166183ab4 -fixed type handling for varargs (i.e. A_Jump.) 2016-10-26 14:15:11 +02:00
Christoph Oelckers
7c759f9fcf - removed the FxDamageValue hack and implemented it properly using FxReturnStatement.
- added handling of damage functions for ZScript.
2016-10-26 14:04:49 +02:00
Christoph Oelckers
e50315bd31 - fixed: Deprecation messages should never appear in DECORATE.
- removed some console message spam.
2016-10-26 13:22:36 +02:00
Christoph Oelckers
823c52aeb2 - scriptified the functions in a_possessed.cpp and added the needed exports and constants.
- fixed: Script functions did not receive the function name when being created.
- relaxed the asserts for PARAM_STATE, because the VM knows nothing about ATAG_STATE. Any state variable's content (e.g. Actor.SeeState) will receive ATAG_GENERIC, rather than ATAG_STATE.
- added a 'NeedResult' flag so that certain operations can create shorter code if the result of the expression is not needed. So far only used for postdecrement/increment statements on local variables (which is the most frequent case where this matters.)
- fixed postincrement and decrement for local variables. Due to the result preservation semantics it created faulty code.
2016-10-26 11:30:30 +02:00
Christoph Oelckers
33d00070b5 - made some variables signed that should not be unsigned. 2016-10-25 17:07:19 +02:00
Edoardo Prezioso
be4ce05aee - Fixed Clang compiler errors and some warnings. 2016-10-25 16:53:14 +02:00
Christoph Oelckers
142278a818 - fixed incomplete commit for bounce flags
- fixed flag clearing in new function.
2016-10-25 13:29:58 +02:00
Christoph Oelckers
ae728cc61a - made the count flags and NOBLOCKMAP and NOSECTOR read-only. These require special treatment to work which can only be done by a setter function. 2016-10-25 09:55:13 +02:00
Christoph Oelckers
f810b98167 - implement flag variables with the VM's sbit and lbit instructions.
- synthesize PField entries from the flag list for AActor. This intentionally excludes the bounce flags for now.
- allow deprecated flags that do not call the deprecated flag handler.
- disallow constructs like (a = b) = c by not allowing an address request on an assignment operation.
- restrict modify/assign on boolean variables to the bit operators. Everything else needs to promote the result to an integer to make sense so it should be disallowed.
2016-10-24 17:18:20 +02:00
Christoph Oelckers
808188ff18 - added handling for structs. When defined inside classes or other structs the double member access will be merged, so there is no performance hit by using structs to group data. 2016-10-24 13:18:13 +02:00
Christoph Oelckers
3f1673f34f - scriptified A_HeadAttack, A_CyberAttack and A_Hoof. 2016-10-24 00:50:28 +02:00
Christoph Oelckers
9f8a5dae21 - scriptified A_BruisAttack.
- removed 'self' as a dedicated token. Internally this gets handled as a normal but implicitly named variable so the token just gets in the way of proper processing.
- removed P_ prefix from SpawnMissile export.
- fixed a crash with misnamed function exports.
2016-10-23 17:15:24 +02:00
Christoph Oelckers
da56e5908d - added an optimization to FxBoolCast that it doesn't force the source value to a 0/1 integer if not explicitly needed. When doing comparisons we do not care about actual values, we only want to know if it is 0 or not.
- added the above for the 'if' condition. It works for integers, floats and pointers and will save 3 instructions if the condition is a non-boolean that can be implicitly casted to bool.
2016-10-23 15:30:58 +02:00
Christoph Oelckers
5b952b116a - named class functions are working. Yay!!
- converted A_BspiAttack and A_BabyMetal to script functions to test the implementation.
2016-10-23 14:26:33 +02:00
Christoph Oelckers
a2116fc7bf - created an export for P_SpawnMissile so that I can do some tests with functions.
- allow class extensions.

These are separate blocks in different files that get concatenated to one class body for processing. The reason is to allow spreading the many functions in Actor over multiple files, so that they remain manageable. For example, all the Doom action functions should be in their respective files, but their symbols need to be in Actor. To extend a class, both files need to be in the same translation unit, so it won't allow user-side extension of internal classes.
2016-10-23 12:57:21 +02:00
Christoph Oelckers
f9cd2c9af7 - added switch/case processing. Right now it is just a sequence of test/jmp instructions. It may make sense to add a special opcode that can perform the comparisons natively but that's an option for later.
- added a TESTN instruction. This is like TEST but negates the operand. This was added to avoid flooding the constant table with too many case labels. With TEST and TESTN combined, all numbers between -65535 and 65535 can be kept entirely inside the instruction. Numbers outside this range still use a BEQ instruction.
2016-10-23 12:00:25 +02:00
Christoph Oelckers
ccabb6f9bd - Gave FxExpression a type identifier field so that certain combinations that are easy to optimize can be detected. 2016-10-23 01:14:49 +02:00
Christoph Oelckers
32d33618ea - better fix for the class type problem: We already know the wanted type so let's use that instead of trying to determine it from the actual name. 2016-10-22 19:51:24 +02:00
Christoph Oelckers
c2b37aeeea - fixed a conversion warning with the pointer-type AActor fields.
- added master and tracer to the list of exported variables.
- fixed: 'none' as class type must map to the real null pointer so that it won't get rejected by the stricter type checks.
- added handling for member function calls to zcc_compile.cpp.
- fixed: FxMemberFunctionCall may not delete the self expression if it gets passed on to the actual function call.
2016-10-22 19:43:53 +02:00
Christoph Oelckers
37914223f0 - reviewed all places where VARF_Action and NAP were used and fixed what was still wrong. 2016-10-22 18:24:47 +02:00
Christoph Oelckers
371712c53a - turned everything I could into non-action functions.
- fixed emission of the self pointer in FxVMFunctionCall. I did not realize that the self expression only sets up a register for the value, not pushing it onto the stack.
2016-10-22 17:49:08 +02:00
Christoph Oelckers
d714670acc - allow calling non-action functions directly from a state.
Ironically this only requires a very minor change in the calling code and an added member for the VMFunction to tell that code how many parameters to pass.
This change will allow to turn the vast majority of action functions into regular members, the only ones that still need to be an action function are the few that actually use the pointers.
2016-10-22 16:35:48 +02:00
Christoph Oelckers
d6047ae651 - added the required code genration nodes for member function calls.
This is not testable right now because finally the action function mess has come full circle. The current setup makes it impossible to call action functions from non-action functions because the needed info is local to the functions.
Long avoided, this needs to be refactored now so that the different semantics for action functions are no longer needed.
2016-10-22 12:10:19 +02:00
Christoph Oelckers
43aec68559 - implemented ~== operator.
Turned out this was really simple because the functionality was already there.
2016-10-22 09:31:37 +02:00
Marisa Heit
09b82b8a3a Merge branch 'master' into zscript 2016-10-21 22:13:24 -05:00
Christoph Oelckers
1e11042de0 - changed VM_EPSILON from 1/1024 to 1/65536 so that the ~== operator can actually be used.
1/1024 is far too coarse for ZDoom's purposes, this needs to be at least fixed point precision.
2016-10-22 02:52:28 +02:00
Christoph Oelckers
4b41e735f1 - added null pointer.
- fixed: FxMemberIdentifier checked for ClassPointers instead of object pointers to resolve the left hand side of the expression.
- allow comparison of pointers.
2016-10-22 00:50:04 +02:00
Christoph Oelckers
3b0b0baf05 Merge branch 'master' of https://github.com/rheit/zdoom into zscript
# Conflicts:
#	wadsrc/static/actors/shared/player.txt
2016-10-21 19:31:08 +02:00
Christoph Oelckers
89416835a8 - preparations for null pointer support.
- add pointer support to FxAssign.
2016-10-21 19:18:39 +02:00
Christoph Oelckers
5bed0a2b39 - implemented class member access for variables. (Struct members and functions not done yet.) 2016-10-21 17:41:39 +02:00
Christoph Oelckers
f5e4c4b109 - implemented the '<>=' operator - more as a VM coding exercise than for its usefulness, though. 2016-10-21 16:35:07 +02:00
Christoph Oelckers
9f260983c7 - implemented all assign/modify operators.
- use a table to translate from PEX to tokens to make the code easier to read.
2016-10-21 14:18:31 +02:00
Christoph Oelckers
3e995d7aac - changed assignment operators to be expressions, like they are in C and DECORATE.
This also means that for now Lua-style multi-assignments are disabled, those should be easy to enable by making some changes to the assignment_statement grammar so that it doesn't recognize single assignments, but for now this is low priority because it adds a significant amount of complexity to do this right with functions that have multiple return values.
2016-10-21 12:22:42 +02:00
Christoph Oelckers
1450c3dffb - tested and fixed the regular assignment statement for both local and member variables.
The generated object code can definitely use an optimization pass but that's something left for later when more things are working. Right now it creates one opcode more than necessary for all member accesses (instead of using the offset in the store command it calculates an actual address of the variable in another address register) and can create one too many for non-constant expressions being assigned to local variables (a move between two registers because the emitted expression on the right hand side does not know that it can emit to the actual variable's register.)
2016-10-21 10:09:01 +02:00
Christoph Oelckers
9f99ca4788 - process most of the remaining statement types.
- extend assignment operations to handle local variables (untested.)
- make the implicit function arguments read only.
2016-10-21 01:12:54 +02:00
Christoph Oelckers
24394dfc92 - tested and fixed FxLocalVariableDeclaration.
- create proper variable data from the function prototype instead of assuming that there's just 3 pointers.
- added a printable name to VMScriptFunction for error output during gameplay in case something goes wrong.
2016-10-20 16:55:12 +02:00
Christoph Oelckers
ffc38d422e - split up FxCompoundStatement into the old FxSequence and a new subclass. FxSequence is just a sequence of expressions, while FxCompoundStatement is the one that actually implements handling of local variables. The split was done so that ZCCCompiler::ConvertNode can return multiple statements as one object and for that FxCompoundStatement is not suitable.
- added conversion of local variable declarations. This is still untested
2016-10-20 01:09:35 +02:00
Christoph Oelckers
2d85efce2a - added processing of compound statements to the compiler. This means that anonymous functions without control statements are generating code now.
- added local variable declarations to the code generator. This is not tested yet, that will come with the next commit.
2016-10-19 19:05:48 +02:00
Christoph Oelckers
8a6230d64a - Renamed FxSequence to FxCompoundStatement.
- fixed: The state parser was unable to accept empty anonymous functions, which should be treated as if there is none at all.
2016-10-19 16:15:02 +02:00
Christoph Oelckers
458c68775f - fixed handling of loop statements.
All break and continue statements were collected in one list, and each loop statement taking hold of that entire list, including the breaks and continues from previous outer loops.
Changed it so that loop statements contain the jump addresses themselves and set a pointer in FCompileContext, so that the jump point can be set directly in the loop statement - and an error printed if there is none in the resolving stage, not the emitting one.
Consolidated the identical backpatching code of the three loop statement nodes into a subfunction.
2016-10-19 14:36:54 +02:00
Christoph Oelckers
cfbcfc440d - 'fixed' local variable declrations to work like C, not like some Lua-inspired nightmare. Also added proper initialization syntax for arrays. 2016-10-19 13:07:44 +02:00
Christoph Oelckers
33567741f5 - fixed: The parser was not generating a compound statement node for anonymous action functions. 2016-10-19 10:38:25 +02:00
Christoph Oelckers
665d752686 - added 'null' token to the ZScript parser which is needed for null pointers.
- removed function declaration parser from DECORATE because it is not needed anymore.
- fixed: comparison operators could not handle names.
2016-10-19 00:35:34 +02:00
Christoph Oelckers
bef71f29e2 - make generation of the AST dump a command line parameter instead of having it depend on running a debug build.
- disable generation of the parser's trace file in debug builds.

This increases parsing time by a factor of 15 and is only needed when debugging a problem in the grammar.
2016-10-18 10:17:09 +02:00
Christoph Oelckers
61cc7dbb29 - another batch of Hexen items converted.
- fixed parsing of named damage types and pain chances.
2016-10-18 10:09:02 +02:00
Marisa Heit
1652c02a08 Add unsigned division opcodes to the VM 2016-10-17 22:37:49 -05:00
Christoph Oelckers
646f9b21c7 Merge branch 'master' of https://github.com/rheit/zdoom into zscript
# Conflicts:
#	src/scripting/codegeneration/codegen.cpp
2016-10-18 00:55:56 +02:00
Christoph Oelckers
1c21dbc44c - handle trinary conditional statement. 2016-10-17 21:43:14 +02:00