diff options
| author | Mel <einebeere@gmail.com> | 2022-07-12 00:29:56 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-07-12 00:29:56 +0200 |
| commit | e5ae4ea1288a555c4019dad43ee27e960eec46b9 (patch) | |
| tree | b0c92bae8bd7d58be9c5b42dc0b06081f4a1d780 /pkg/lang/compiler/scope/scopes.go | |
| parent | 74dd678dfd1aae9e655fd13cb65278ea9ba307e2 (diff) | |
| download | jinx-e5ae4ea1288a555c4019dad43ee27e960eec46b9.tar.zst jinx-e5ae4ea1288a555c4019dad43ee27e960eec46b9.zip | |
Extract scopes and scope chain from compiler
Diffstat (limited to 'pkg/lang/compiler/scope/scopes.go')
| -rw-r--r-- | pkg/lang/compiler/scope/scopes.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/pkg/lang/compiler/scope/scopes.go b/pkg/lang/compiler/scope/scopes.go new file mode 100644 index 0000000..39e48ef --- /dev/null +++ b/pkg/lang/compiler/scope/scopes.go @@ -0,0 +1,50 @@ +package scope + +import "jinx/pkg/lang/vm/code" + +type ScopeID int + +type ScopeKind int + +const ( + ScopeKindNormal ScopeKind = iota + ScopeKindFunction +) + +type SymbolScope struct { + variableSymbols []Symbol[SymbolVariable] + functionSymbols []Symbol[SymbolFunction] +} + +func NewSymbolScope() SymbolScope { + return SymbolScope{ + variableSymbols: make([]Symbol[SymbolVariable], 0), + functionSymbols: make([]Symbol[SymbolFunction], 0), + } +} + +type FunctionScope struct { + id ScopeID + unit code.Marker + subUnitCount int +} + +func NewFunctionScope(id ScopeID, unit code.Marker) FunctionScope { + return FunctionScope{ + id: id, + unit: unit, + subUnitCount: 0, + } +} + +func (sf FunctionScope) ID() ScopeID { + return sf.id +} + +func (sf FunctionScope) Unit() code.Marker { + return sf.unit +} + +func (sf FunctionScope) IsRootScope() bool { + return sf.ID() == ScopeID(0) +} |
