From 86f31acf6789be116dcc54ed85b069a37c0f7aa8 Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 11 Aug 2022 01:25:47 +0000 Subject: Actual modules and core --- pkg/lang/compiler/scope/scope_chain.go | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'pkg/lang/compiler/scope/scope_chain.go') diff --git a/pkg/lang/compiler/scope/scope_chain.go b/pkg/lang/compiler/scope/scope_chain.go index f386017..0c8f5cf 100644 --- a/pkg/lang/compiler/scope/scope_chain.go +++ b/pkg/lang/compiler/scope/scope_chain.go @@ -160,6 +160,35 @@ func (sc *ScopeChain) DeclareTemporary() int { return len(sc.Current().variableSymbols) // :) } +func (sc *ScopeChain) DeclareGlobal(name, module, author string) bool { + if _, ok := sc.nameToSymbol[name]; ok { + return false + } + + current := sc.Current() + indexInScope := len(current.globalSymbols) + + symbolID := SymbolID{ + symbolKind: SymbolKindGlobal, + scopeID: sc.CurrentScopeID(), + indexInScope: indexInScope, + } + + globalID := fmt.Sprintf("%s:%s:%s", author, module, name) + + // Declare the symbol in the current scope. + current.globalSymbols = append(current.globalSymbols, Symbol[SymbolGlobal]{ + name: name, + data: SymbolGlobal{ + id: globalID, + }, + }) + + sc.nameToSymbol[name] = symbolID + + return true +} + func (sc *ScopeChain) CreateAnonymousFunctionSubUnit() code.Marker { fnScope := sc.CurrentFunction() @@ -242,3 +271,11 @@ func (sc *ScopeChain) GetEnv(id SymbolID) Symbol[SymbolEnv] { }, } } + +func (sc *ScopeChain) GetGlobal(id SymbolID) Symbol[SymbolGlobal] { + if id.symbolKind != SymbolKindGlobal { + panic("incorrect symbol id kind given") + } + + return sc.symbolScopes[id.scopeID].globalSymbols[id.indexInScope] +} -- cgit 1.4.1 lapin/devices.nix?id=d8daf09dbaec2610ce80986265b998271725d680'>diff
path: root/machines/lapin/devices.nix
blob: ccf7d75230aa71772f6f9b1447173704a0f28e22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66