Mercurial Hosting > luan
comparison src/luan/interp/ExpList.java @ 40:e3624b7cd603
implement stack trace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 10:45:54 +0000 |
parents | 5cf15507d77e |
children | 64ecb7a3aad7 |
comparison
equal
deleted
inserted
replaced
39:e5bcb1eeafc1 | 40:e3624b7cd603 |
---|---|
2 | 2 |
3 import java.util.List; | 3 import java.util.List; |
4 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import java.util.Collections; | 5 import java.util.Collections; |
6 import luan.LuaException; | 6 import luan.LuaException; |
7 import luan.LuaSource; | |
7 | 8 |
8 | 9 |
9 final class ExpList implements Expressions { | 10 final class ExpList implements Expressions { |
10 | 11 |
11 private interface Adder { | 12 private interface Adder { |
12 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException; | 13 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException; |
14 public Code code(); | |
13 } | 15 } |
14 | 16 |
15 private static class ExprAdder implements Adder { | 17 private static class ExprAdder implements Adder { |
16 private final Expr expr; | 18 private final Expr expr; |
17 | 19 |
19 this.expr = expr; | 21 this.expr = expr; |
20 } | 22 } |
21 | 23 |
22 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException { | 24 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException { |
23 list.add( expr.eval(lua) ); | 25 list.add( expr.eval(lua) ); |
26 } | |
27 | |
28 public Code code() { | |
29 return expr; | |
24 } | 30 } |
25 | 31 |
26 } | 32 } |
27 | 33 |
28 private static class ExpressionsAdder implements Adder { | 34 private static class ExpressionsAdder implements Adder { |
34 | 40 |
35 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException { | 41 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException { |
36 for( Object val : expressions.eval(lua) ) { | 42 for( Object val : expressions.eval(lua) ) { |
37 list.add( val ); | 43 list.add( val ); |
38 } | 44 } |
45 } | |
46 | |
47 public Code code() { | |
48 return expressions; | |
39 } | 49 } |
40 | 50 |
41 } | 51 } |
42 | 52 |
43 static class Builder { | 53 static class Builder { |
68 } | 78 } |
69 | 79 |
70 private static final Object[] EMPTY = new Object[0]; | 80 private static final Object[] EMPTY = new Object[0]; |
71 | 81 |
72 static final Expressions emptyExpList = new Expressions() { | 82 static final Expressions emptyExpList = new Expressions() { |
83 | |
73 @Override public Object[] eval(LuaStateImpl lua) { | 84 @Override public Object[] eval(LuaStateImpl lua) { |
74 return EMPTY; | 85 return EMPTY; |
86 } | |
87 | |
88 @Override public LuaSource.Element se() { | |
89 return null; | |
75 } | 90 } |
76 }; | 91 }; |
77 | 92 |
78 static class SingleExpList implements Expressions { | 93 static class SingleExpList implements Expressions { |
79 private final Expr expr; | 94 private final Expr expr; |
82 this.expr = expr; | 97 this.expr = expr; |
83 } | 98 } |
84 | 99 |
85 @Override public Object[] eval(LuaStateImpl lua) throws LuaException { | 100 @Override public Object[] eval(LuaStateImpl lua) throws LuaException { |
86 return new Object[]{expr.eval(lua)}; | 101 return new Object[]{expr.eval(lua)}; |
102 } | |
103 | |
104 @Override public LuaSource.Element se() { | |
105 return expr.se(); | |
87 } | 106 } |
88 } | 107 } |
89 | 108 |
90 private final Adder[] adders; | 109 private final Adder[] adders; |
91 | 110 |
98 for( Adder adder : adders ) { | 117 for( Adder adder : adders ) { |
99 adder.addTo(lua,list); | 118 adder.addTo(lua,list); |
100 } | 119 } |
101 return list.toArray(); | 120 return list.toArray(); |
102 } | 121 } |
122 | |
123 @Override public LuaSource.Element se() { | |
124 return new LuaSource.Element(adders[0].code().se().source,adders[0].code().se().start,adders[adders.length-1].code().se().end); | |
125 } | |
103 } | 126 } |