Mercurial > pub > Jint1
comparison Jint.Runtime/VM/Scope.cs @ 6:a6329b092499
Added scopes, function builder
| author | cin |
|---|---|
| date | Wed, 30 Oct 2013 17:38:35 +0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 5:cb13da6e3349 | 6:a6329b092499 |
|---|---|
| 1 using System; | |
| 2 using System.Collections.Generic; | |
| 3 | |
| 4 namespace Jint.Runtime.VM | |
| 5 { | |
| 6 class Scope | |
| 7 { | |
| 8 Frame m_frame; | |
| 9 Dictionary<string,int> m_vars; | |
| 10 Scope m_parent; | |
| 11 | |
| 12 public const int ThisRegister = 0; | |
| 13 public const int ScopeRegister = 1; | |
| 14 public const int FirstVarRegsiter = 2; | |
| 15 | |
| 16 public Scope (IDictionary<string,int> vars, Frame frame, Scope parent) | |
| 17 { | |
| 18 if (vars == null) | |
| 19 throw new ArgumentNullException ("vars"); | |
| 20 if (frame == null) | |
| 21 throw new ArgumentNullException ("frame"); | |
| 22 | |
| 23 m_vars = new Dictionary<string, int> (vars); | |
| 24 m_frame = frame; | |
| 25 m_parent = parent; | |
| 26 } | |
| 27 | |
| 28 public IReference Resolve(string name) { | |
| 29 if (String.IsNullOrEmpty (name)) | |
| 30 throw new ArgumentException ("The specified variable name is invalid"); | |
| 31 | |
| 32 int index; | |
| 33 if (m_vars.TryGetValue (name, out index)) | |
| 34 return new ScopeReference (this, index); | |
| 35 | |
| 36 if (m_parent != null) | |
| 37 return m_parent.Resolve (name); | |
| 38 else | |
| 39 throw new KeyNotFoundException (String.Format("The specified variable '{0}' isn't found",name)); | |
| 40 } | |
| 41 } | |
| 42 } | |
| 43 |
