mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
[Tolk] Embedded stdlib.tolk, CompilerState, strict includes
Several related changes: - stdlib.tolk is embedded into a distribution (deb package or tolk-js), the user won't have to download it and store as a project file; it's an important step to maintain correct language versioning - stdlib.tolk is auto-included, that's why all its functions are available out of the box - strict includes: you can't use symbol `f` from another file unless you've #include'd this file - drop all C++ global variables holding compilation state, merge them into a single struct CompilerState located at compiler-state.h; for instance, stdlib filename is also there
This commit is contained in:
parent
f0e6470d0b
commit
6c30e5a7eb
21 changed files with 604 additions and 506 deletions
|
@ -15,17 +15,15 @@
|
|||
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "src-file.h"
|
||||
#include "compiler-state.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace tolk {
|
||||
|
||||
extern AllRegisteredSrcFiles all_src_files;
|
||||
extern std::string stdlib_filename;
|
||||
|
||||
static_assert(sizeof(SrcLocation) == 8);
|
||||
|
||||
const SrcFile* AllRegisteredSrcFiles::find_file(int file_id) const {
|
||||
for (const SrcFile* file : all_src_files) {
|
||||
SrcFile* AllRegisteredSrcFiles::find_file(int file_id) const {
|
||||
for (SrcFile* file : all_src_files) {
|
||||
if (file->file_id == file_id) {
|
||||
return file;
|
||||
}
|
||||
|
@ -33,8 +31,8 @@ const SrcFile* AllRegisteredSrcFiles::find_file(int file_id) const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const SrcFile* AllRegisteredSrcFiles::find_file(const std::string& abs_filename) const {
|
||||
for (const SrcFile* file : all_src_files) {
|
||||
SrcFile* AllRegisteredSrcFiles::find_file(const std::string& abs_filename) const {
|
||||
for (SrcFile* file : all_src_files) {
|
||||
if (file->abs_filename == abs_filename) {
|
||||
return file;
|
||||
}
|
||||
|
@ -42,17 +40,13 @@ const SrcFile* AllRegisteredSrcFiles::find_file(const std::string& abs_filename)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const SrcFile* AllRegisteredSrcFiles::register_file(const std::string& rel_filename, const std::string& abs_filename, std::string&& text, const SrcFile* included_from) {
|
||||
SrcFile* created = new SrcFile(++last_file_id, rel_filename, abs_filename, std::move(text), included_from);
|
||||
SrcFile* AllRegisteredSrcFiles::register_file(const std::string& rel_filename, const std::string& abs_filename, std::string&& text) {
|
||||
SrcFile* created = new SrcFile(++last_file_id, rel_filename, abs_filename, std::move(text));
|
||||
all_src_files.push_back(created);
|
||||
return created;
|
||||
}
|
||||
|
||||
|
||||
bool SrcFile::is_entrypoint_file() const {
|
||||
return file_id == (stdlib_filename.empty() ? 0 : 1);
|
||||
}
|
||||
|
||||
bool SrcFile::is_offset_valid(int offset) const {
|
||||
return offset >= 0 && offset < static_cast<int>(text.size());
|
||||
}
|
||||
|
@ -98,7 +92,7 @@ std::ostream& operator<<(std::ostream& os, const Fatal& fatal) {
|
|||
}
|
||||
|
||||
const SrcFile* SrcLocation::get_src_file() const {
|
||||
return all_src_files.find_file(file_id);
|
||||
return G.all_src_files.find_file(file_id);
|
||||
}
|
||||
|
||||
void SrcLocation::show(std::ostream& os) const {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue