-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor how builtin AST nodes are created.
Having custom C++ to create built-in symbols introduced a lot of weird complexity around scopes and source locations. It was also a cludge, because it meant the compiler could rely on idiosyncracies that are not exposed to the language itself (eg, INVALID_FUNCTION was a type completely inaccessible to scripts). It also posed another problem. For historical reasons the compiler still separates the concept of "AST Node" and "Symbol", and trying to merge them is proving very difficult to do in small steps. Builtin symbols make it even more difficult because they didn't have corresponding AST nodes. The new mechanism for builtins is to embed SourcePawn-language scripts into C++ code as strings, and then inject those strings into the parser. This is very easy to do thanks to all of our recent refactorings. And, again thanks to recent refactorings, we even get correct file/line information if these builtins happen to have an error. There are some user-visible changes as a result of this. 1. Command-line macros (eg spcomp.exe X=Y) will now create an in-memory script, like: ``` #define X Y ``` This will improve diagnostics a bit. 2. Built-in defines and constants are now created via a separate in-memory script, that looks like this: ``` #define __BINARY_PATH__ "test.smx" #define __BINARY_NAME__ "test.smx" #define __DATE__ "10/21/2023" #define __TIME__ "23:19:59" const int EOS = 0; const int cellmax = 2147483647; const int cellmin = -2147483648; ``` 3. The "using" keyword has been removed and is no longer implemented. The __nullable__ and destructor syntax for handles has been re-introduced, and SourceMod will have to bring back the Handle methodmap. Because the native alias syntax no longer exists, CloseHandle will not suffice, and SourceMod will also have to add a "Handle.~Handle" native mapping.
- Loading branch information
Showing
39 changed files
with
267 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// vim: set ts=8 sts=4 sw=4 tw=99 et: | ||
// | ||
// Copyright (c) 2023 AlliedModders LLC | ||
// | ||
// This software is provided "as-is", without any express or implied warranty. | ||
// In no event will the authors be held liable for any damages arising from | ||
// the use of this software. | ||
// | ||
// Permission is granted to anyone to use this software for any purpose, | ||
// including commercial applications, and to alter it and redistribute it | ||
// freely, subject to the following restrictions: | ||
// | ||
// 1. The origin of this software must not be misrepresented; you must not | ||
// claim that you wrote the original software. If you use this software in | ||
// a product, an acknowledgment in the product documentation would be | ||
// appreciated but is not required. | ||
// 2. Altered source versions must be plainly marked as such, and must not be | ||
// misrepresented as being the original software. | ||
// 3. This notice may not be removed or altered from any source distribution. | ||
|
||
#include "builtin-generator.h" | ||
|
||
#include "compile-context.h" | ||
|
||
namespace sp { | ||
|
||
BuiltinGenerator::BuiltinGenerator(CompileContext& cc) | ||
: cc_(cc) | ||
{} | ||
|
||
void BuiltinGenerator::AddDefine(const std::string& key, const std::string& value) { | ||
buffer_ += "#define "; | ||
buffer_ += key; | ||
buffer_ += " "; | ||
buffer_ += value; | ||
buffer_ += "\n"; | ||
} | ||
|
||
void BuiltinGenerator::AddBuiltinConstants() { | ||
buffer_ += "const int EOS = 0;\n"; | ||
buffer_ += "const int cellmax = " + std::to_string(INT_MAX) + ";\n"; | ||
buffer_ += "const int cellmin = " + std::to_string(INT_MIN) + ";\n"; | ||
} | ||
|
||
void BuiltinGenerator::AddDefaultInclude() { | ||
if (cc_.default_include().empty()) | ||
return; | ||
buffer_ += "#tryinclude <" + cc_.default_include() + ">\n"; | ||
} | ||
|
||
std::shared_ptr<SourceFile> BuiltinGenerator::Generate(const std::string& name) { | ||
return cc_.sources()->Open(name, std::move(buffer_)); | ||
} | ||
|
||
} // namespace sp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.