Skip to content

Commit

Permalink
vbs: avoid recursion in env.get, remove Self field
Browse files Browse the repository at this point in the history
  • Loading branch information
asarhaddon committed Oct 24, 2024
1 parent 44c345e commit 9486bd7
Showing 1 changed file with 13 additions and 36 deletions.
49 changes: 13 additions & 36 deletions impls/vbs/env.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,41 @@ Option Explicit
Function NewEnv(objOuter)
Dim varRet
Set varRet = New Environment
Set varRet.Self = varRet
Set varRet.Outer = objOuter
Set NewEnv = varRet
End Function

Class Environment
Private objOuter, objSelf
Private objOuter
Private objBinds
Private Sub Class_Initialize()
Set objBinds = CreateObject("Scripting.Dictionary")
Set objOuter = Nothing
Set objSelf = Nothing
End Sub

Public Property Set Outer(objEnv)
Set objOuter = objEnv
End Property

Public Property Get Outer()
Set Outer = objOuter
End Property

Public Property Set Self(objEnv)
Set objSelf = objEnv
End Property

Public Sub Add(varKey, varValue)
Set objBinds.Item(varKey) = varValue
End Sub

Public Function Find(varKey)
Dim varRet
If objBinds.Exists(varKey) Then
Set varRet = objSelf
Else
If TypeName(objOuter) <> "Nothing" Then
Set varRet = objOuter.Find(varKey)
Else
Public Function [Get](varKey)
Dim objEnv, varRet
Set objEnv = Me
Do
If objEnv.objBinds.Exists(varKey) Then
Set varRet = objEnv.objBinds(varKey)
Exit Do
End If
objEnv = objEnv.objOuter
If TypeName(objEnv) = "Nothing" Then
Set varRet = Nothing
Exit Do
End If
End If
Loop

Set Find = varRet
End Function

Public Function [Get](varKey)
Dim objEnv, varRet
Set objEnv = Find(varKey)
If objEnv Is objSelf Then
Set varRet = objBinds(varKey)
Else
If TypeName(objEnv) <> "Nothing" Then
Set varRet = objEnv.Get(varKey)
Else
Set varRet = Nothing
End If
End If

Set [Get] = varRet
End Function
End Class

0 comments on commit 9486bd7

Please sign in to comment.