From 5a6d4664e4417763b4a7d9f215e42102fa1b3fd4 Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 28 Jul 2022 22:11:02 +0000 Subject: Compile type declarations correctly --- pkg/lang/compiler/scope/scopes.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'pkg/lang/compiler/scope/scopes.go') diff --git a/pkg/lang/compiler/scope/scopes.go b/pkg/lang/compiler/scope/scopes.go index 7a1b20c..2a9453a 100644 --- a/pkg/lang/compiler/scope/scopes.go +++ b/pkg/lang/compiler/scope/scopes.go @@ -28,6 +28,9 @@ type FunctionScope struct { subUnitCount int outsideSymbolsInEnv []SymbolID + + isMethod bool + methodLocal int // -1 if in env 0 } func NewFunctionScope(id ScopeID, unit code.Marker) FunctionScope { @@ -40,6 +43,19 @@ func NewFunctionScope(id ScopeID, unit code.Marker) FunctionScope { } } +func NewMethodFunctionScope(id ScopeID, unit code.Marker, methodLocal int) FunctionScope { + return FunctionScope{ + id: id, + unit: unit, + subUnitCount: 0, + + outsideSymbolsInEnv: make([]SymbolID, 0), + + isMethod: true, + methodLocal: methodLocal, + } +} + func (sf FunctionScope) ID() ScopeID { return sf.id } @@ -56,6 +72,22 @@ func (sf FunctionScope) IsRootScope() bool { return sf.ID() == ScopeID(0) } +func (sf FunctionScope) IsMethod() bool { + return sf.isMethod +} + +func (sf FunctionScope) ThisLocal() (bool, int) { + if !sf.isMethod { + return false, 0 + } + + if sf.methodLocal == -1 { + return false, 0 + } + + return true, sf.methodLocal +} + type LoopScope struct { id ScopeID breakMarker code.Marker -- cgit 1.4.1