annotate Jint.Runtime/VM/Scope.cs @ 6:a6329b092499

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