Fixed bug with imports and added missing time module

This commit is contained in:
Mattia Giambirtone 2023-05-22 14:38:03 +02:00
parent 879fec20fe
commit b281961a5c
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
3 changed files with 16 additions and 5 deletions

View File

@ -212,7 +212,7 @@ type
# The module importing us, if any
parentModule*: Name
# Currently imported modules
modules*: HashSet[string]
modules*: TableRef[string, Name]
TypedNode* = ref object
## A wapper for AST nodes
@ -354,7 +354,7 @@ proc resolve*(self: Compiler, name: string): Name =
# module, so we definitely can't
# use it
continue
elif self.currentModule.path in obj.exportedTo:
if self.currentModule.path in obj.exportedTo:
# The name is public in its owner
# module and said module has explicitly
# exported it to us: we can use it
@ -988,7 +988,7 @@ proc declare*(self: Compiler, node: ASTNode): Name {.discardable.} =
line: node.moduleName.token.line,
kind: NameKind.Module,
isPrivate: false,
isReal: true
isReal: true,
))
n = self.names[^1]
declaredName = self.names[^1].ident.token.lexeme

View File

@ -1689,6 +1689,10 @@ proc importStmt(self: BytecodeCompiler, node: ImportStmt, compile: bool = true)
# its public names to us
for name in self.findInModule("", module):
name.exportedTo.incl(self.currentModule.path)
for module in self.modules.values():
if self.currentModule.path in module.exportedTo:
for name in self.findInModule("", module):
name.exportedTo.incl(self.currentModule.path)
except IOError:
self.error(&"could not import '{module.ident.token.lexeme}': {getCurrentExceptionMsg()}")
except OSError:
@ -2077,6 +2081,7 @@ proc compile*(self: BytecodeCompiler, ast: seq[Declaration], file: string, lines
let start = self.chunk.code.len()
if not incremental:
self.jumps = @[]
self.modules = newTable[string, Name]()
let pos = self.beginProgram()
let idx = self.stackIndex
self.stackIndex = idx
@ -2100,7 +2105,7 @@ proc compileModule(self: BytecodeCompiler, module: Name) =
break
elif i == searchPath.high():
self.error(&"""could not import '{path}': module not found""")
if self.modules.contains(module.path):
if self.modules.hasKey(module.path):
return
let source = readFile(path)
let current = self.current
@ -2141,4 +2146,4 @@ proc compileModule(self: BytecodeCompiler, module: Name) =
self.replMode = replMode
self.lines = lines
self.source = src
self.modules.incl(module.path)
self.modules[module.path] = module

6
src/peon/stdlib/time.pn Normal file
View File

@ -0,0 +1,6 @@
import std;
fn clock*: float {
#pragma[magic: "SysClock64"]
}