@@ -77,21 +77,23 @@ private Program() { }
7777
7878 private abstract class node
7979 {
80+ private Position _pos ;
81+ public Position Position { get { return _pos ; } }
8082 public abstract IEnumerable < Position > Execute ( UnreadableEnv env ) ;
83+ protected node ( Position pos ) { _pos = pos ; }
8184 }
8285
8386 private sealed class simpleNode : node
8487 {
8588 private node [ ] _args ;
86- private Position _pos ;
8789 private Action < UnreadableEnv > _executor ;
88- public simpleNode ( node [ ] args , Action < UnreadableEnv > executor , Position pos ) { _args = args ; _executor = executor ; _pos = pos ; }
90+ public simpleNode ( node [ ] args , Action < UnreadableEnv > executor , Position pos ) : base ( pos ) { _args = args ; _executor = executor ; }
8991 public override IEnumerable < Position > Execute ( UnreadableEnv env )
9092 {
9193 foreach ( var arg in _args )
9294 foreach ( var pos in arg . Execute ( env ) )
9395 yield return pos ;
94- yield return _pos ;
96+ yield return Position ;
9597 _executor ( env ) ;
9698 }
9799 }
@@ -100,8 +102,7 @@ private sealed class whileNode : node
100102 {
101103 private node _argCond ;
102104 private node _argCode ;
103- private Position _pos ;
104- public whileNode ( node argCond , node argCode , Position pos ) { _argCond = argCond ; _argCode = argCode ; _pos = pos ; }
105+ public whileNode ( node argCond , node argCode , Position pos ) : base ( pos ) { _argCond = argCond ; _argCode = argCode ; }
105106 public override IEnumerable < Position > Execute ( UnreadableEnv env )
106107 {
107108 env . Push ( null ) ;
@@ -112,7 +113,7 @@ public override IEnumerable<Position> Execute(UnreadableEnv env)
112113 foreach ( var pos in _argCond . Execute ( env ) )
113114 yield return pos ;
114115
115- yield return _pos ;
116+ yield return Position ;
116117 var value = env . Pop ( ) ;
117118 if ( value == null )
118119 throw new Exception ( "While condition cannot be void." ) ;
@@ -126,12 +127,12 @@ public override IEnumerable<Position> Execute(UnreadableEnv env)
126127 foreach ( var pos in _argCode . Execute ( env ) )
127128 yield return pos ;
128129
129- yield return _pos ;
130+ yield return Position ;
130131 goto again ;
131132 }
132133
133134 // Last result is now on the stack
134- yield return _pos ;
135+ yield return Position ;
135136 }
136137 }
137138
@@ -140,15 +141,14 @@ private sealed class ifNode : node
140141 private node _argCond ;
141142 private node _argYCode ;
142143 private node _argNCode ;
143- private Position _pos ;
144- public ifNode ( node argCond , node argYCode , node argNCode , Position pos ) { _argCond = argCond ; _argYCode = argYCode ; _argNCode = argNCode ; _pos = pos ; }
144+ public ifNode ( node argCond , node argYCode , node argNCode , Position pos ) : base ( pos ) { _argCond = argCond ; _argYCode = argYCode ; _argNCode = argNCode ; }
145145 public override IEnumerable < Position > Execute ( UnreadableEnv env )
146146 {
147147 // Evaluate the condition
148148 foreach ( var pos in _argCond . Execute ( env ) )
149149 yield return pos ;
150150
151- yield return _pos ;
151+ yield return Position ;
152152 var value = env . Pop ( ) ;
153153 if ( value == null )
154154 throw new Exception ( "If condition cannot be void." ) ;
@@ -160,7 +160,7 @@ public override IEnumerable<Position> Execute(UnreadableEnv env)
160160 yield return pos ;
161161
162162 // Last result is now on the stack
163- yield return _pos ;
163+ yield return Position ;
164164 }
165165 }
166166 }
0 commit comments