about summary refs log tree commit diff
path: root/pkg/lang/compiler/scope/scopes.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/compiler/scope/scopes.go')
-rw-r--r--pkg/lang/compiler/scope/scopes.go32
1 files changed, 32 insertions, 0 deletions
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