Skip to content

Scripting language changes, cleanup and documentation#1712

Open
marauder2k7 wants to merge 1 commit intoTorqueGameEngines:developmentfrom
marauder2k9-torque:ScriptBackend-Changes-and-Cleanup
Open

Scripting language changes, cleanup and documentation#1712
marauder2k7 wants to merge 1 commit intoTorqueGameEngines:developmentfrom
marauder2k9-torque:ScriptBackend-Changes-and-Cleanup

Conversation

@marauder2k7
Copy link
Copy Markdown
Contributor

Alot of changes here so lets go through them from the ground up

Firstly the CMDGram.y and CMDscan.l (bison/flex) files have some added documentation to hopefully make it easier to make modifications in future.
Error reporting now correctly resets the line number when crossing different files in a compile chain
rwNAMESPACE and rwCLASS were declared but had no lexer rule, nor did they contribute to any grammar so they have been removed.
STMT_SEP, opMDASN, opNDASN, opNTASN were listed here but were never defined so removed them.
opSTREQ and opSTRNE where never declared which may have caused confusion due to the compiler not knowing their semantic type.
Cleaned up commented out gramar rules.

Next ConsoleValue

only cvString was heap allocated so it was the only type we were required to free, this was a confusing point during the last time we made changes in this class so to make this clearer there is now a setStringOwned function that makes this clear, setStringRef is still there as a passthrough.

Entire class has had their functions moved for improved readability of the class, getters at the top setters down below, queries below that.

new copyFrom and transferFrom functions to group that logic so it is no longer repeated throughout the class.
move constructor and assignment, this was previously being executed without a definition from a few key sites where the compiler was expecting a move. This means that this was being done by a copy before which meant the var was not being freed until it went out of scope. Potential danger point of dangling pointer so hard free with the move.

Next ASTNodes
ConstantNode was always returning the incoming ip, now it returns codestream.tell in case the compile statements expand the codestream.

propagateSwitchExpr was calling getSwitchOr which created a recursive or expression tree that O(n) deep for n cases. This had a chance of overflowing for large switch statments if there was 100+ cases the gStack would of overflown. Now this is changed to build a left associative chain instead. This avoids deep recursion and should be safer. Further expansion on this may be required.

Default Function Arguments:

The default function arguments previously were creating a ConsoleValue at compile time for each value that was presented as a default, furthermore no matter what function was being called if it had defaults or not these consolevalues were tacked on to the namespace of the function. This was prone to leaks and some dangers if not handled absolutely correctly.

The changes here now hold the default offsets and these vars are compiled during the function call. This allows more dynamic allocation of default argument for function callsits eg:

$TestString = "testing global";
function test(%var = $TestString)
{
    return %var;
}

function runTests()
{
    echo(test1());
    $TestString = "override test";
    echo(test1());
}

This is now perfectly valid and will update based on the global var. This made it so that you could also use previously defined functions as the default value eg:

function test3(%var = 1)
{
    return %var;
}

function test4(%var = test3())
{
    return %var;
}

@marauder2k7 marauder2k7 force-pushed the ScriptBackend-Changes-and-Cleanup branch from d4858db to 991b025 Compare April 12, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant