about summary refs log tree commit diff
path: root/pkg/lang/compiler/scope/scopes.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-07-28 22:11:02 +0000
committerMel <einebeere@gmail.com>2022-07-28 22:11:02 +0000
commit5a6d4664e4417763b4a7d9f215e42102fa1b3fd4 (patch)
tree525f8151bd1bb604ce015425126c5f3dfc84a32c /pkg/lang/compiler/scope/scopes.go
parent95c742ef729a657198be43dc2f295f249860332f (diff)
downloadjinx-5a6d4664e4417763b4a7d9f215e42102fa1b3fd4.tar.zst
jinx-5a6d4664e4417763b4a7d9f215e42102fa1b3fd4.zip
Compile type declarations correctly
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