Skip to content

Commit

Permalink
Extend scope functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer committed Nov 7, 2022
1 parent 1960d3f commit a4c91db
Show file tree
Hide file tree
Showing 11 changed files with 546 additions and 101 deletions.
6 changes: 3 additions & 3 deletions src-bootstrap/symbol/SymbolTable.spice
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public type SymbolTable struct {
bool inMainSourceFile
bool isSourceFileRootScope
bool isShadowTable
bool isCapturingRequired
bool capturingRequired
}

public p SymbolTable.ctor(
Expand All @@ -61,7 +61,7 @@ public p SymbolTable.ctor(
this.inMainSourceFile = inMainSourceFile;
this.isSourceFileRootScope = isSourceFileRoot;
this.isShadowTable = false;
this.isCapturingRequired = false;
this.capturingRequired = false;
}

/**
Expand Down Expand Up @@ -127,7 +127,7 @@ public f<ste::SymbolTableEntry*> SymbolTable.lookup(const string name) {
if entry == nil<SymbolTable*> { return nil<ste::SymbolTableEntry*>; }

// Check if this scope requires capturing and capture the variable if appropriate
if this.isCapturingRequired && !this.captures.contains(name) && !entry.ty.isOneOf({TY_IMPORT, TY_FUNCTION, TY_PROCEDURE}) {
if this.capturingRequired && !this.captures.contains(name) && !entry.ty.isOneOf({TY_IMPORT, TY_FUNCTION, TY_PROCEDURE}) {
this.captures.insert(name, cpt::Capture(entry));
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/global/RuntimeModuleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <SourceFile.h>
#include <scope/Scope.h>
#include <symbol/SymbolTable.h>
#include <util/FileUtil.h>

#include <ast/ASTNodes.h>
Expand All @@ -18,9 +17,9 @@ SourceFile *RuntimeModuleManager::requestModule(SourceFile *sourceFile, const Ru
return available ? modules.at(moduleName) : nullptr;
}

SymbolTable *RuntimeModuleManager::getModuleScope(const RuntimeModuleName &moduleName) const {
Scope *RuntimeModuleManager::getModuleScope(const RuntimeModuleName &moduleName) const {
assert(modules.contains(moduleName));
return &modules.at(moduleName)->globalScope->symbolTable;
return modules.at(moduleName)->globalScope.get();
}

bool RuntimeModuleManager::isModuleAvailable(const RuntimeModuleName &module) const { return modules.contains(module); }
Expand Down
8 changes: 4 additions & 4 deletions src/global/RuntimeModuleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#pragma once

#include <map>
#include <unordered_map>

// Forward declaration
class SourceFile;
class SymbolTable;
class Scope;

const char *const STRING_RT_IMPORT_NAME = "__rt_string";
const char *const THREAD_RT_IMPORT_NAME = "__rt_thread";
Expand All @@ -17,13 +17,13 @@ class RuntimeModuleManager {
public:
// Public methods
SourceFile *requestModule(SourceFile *sourceFile, const RuntimeModuleName &moduleName);
[[nodiscard]] SymbolTable *getModuleScope(const RuntimeModuleName &moduleName) const;
[[nodiscard]] Scope *getModuleScope(const RuntimeModuleName &moduleName) const;
[[nodiscard]] bool isModuleAvailable(const RuntimeModuleName &moduleName) const;

private:
// Private methods
bool addModule(SourceFile *parentSourceFile, const RuntimeModuleName &moduleName);

// Private fields
std::map<RuntimeModuleName, SourceFile *> modules;
std::unordered_map<RuntimeModuleName, SourceFile *> modules;
};

0 comments on commit a4c91db

Please sign in to comment.