Mercurial > projects > dil
comparison src/dil/semantic/Interpreter.d @ 835:451ede0105e0
Applied minor fixes and tidied some code up a bit.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 02:59:11 +0200 |
parents | 09a64d96967a |
children |
comparison
equal
deleted
inserted
replaced
834:8bcf482b2062 | 835:451ede0105e0 |
---|---|
41 /// Returns: NAR or a value. | 41 /// Returns: NAR or a value. |
42 static Expression interpret(Expression e, InfoManager infoMan/+, Scope scop+/) | 42 static Expression interpret(Expression e, InfoManager infoMan/+, Scope scop+/) |
43 { | 43 { |
44 return (new Interpreter(/+scop,+/ infoMan)).eval(e); | 44 return (new Interpreter(/+scop,+/ infoMan)).eval(e); |
45 } | 45 } |
46 | 46 |
47 /// Executes the function at compile-time with the given arguments. | 47 /// Executes the function at compile-time with the given arguments. |
48 /// Returns: NAR or a value. | 48 /// Returns: NAR or a value. |
49 static Expression interpret(FunctionDeclaration fd, Expression[] args, InfoManager infoMan/+, Scope scop+/) | 49 static Expression interpret(FunctionDeclaration fd, Expression[] args, InfoManager infoMan/+, Scope scop+/) |
50 { | 50 { |
51 return (new Interpreter(/+scop,+/ infoMan)).eval(fd, args); | 51 return (new Interpreter(/+scop,+/ infoMan)).eval(fd, args); |
61 /// Start evaluation. | 61 /// Start evaluation. |
62 Expression eval(Expression e) | 62 Expression eval(Expression e) |
63 { | 63 { |
64 return e; | 64 return e; |
65 } | 65 } |
66 | 66 |
67 /// Start evaluation of a function. | 67 /// Start evaluation of a function. |
68 Expression eval(FunctionDeclaration fd, Expression[] args) | 68 Expression eval(FunctionDeclaration fd, Expression[] args) |
69 { | 69 { |
70 // We cache this result so that we don't blindly try to reevaluate functions | 70 // We cache this result so that we don't blindly try to reevaluate functions |
71 // that can't be evaluated at compile time | 71 // that can't be evaluated at compile time |
83 | 83 |
84 // remove me plx | 84 // remove me plx |
85 assert(false); | 85 assert(false); |
86 return NAR; | 86 return NAR; |
87 } | 87 } |
88 | 88 |
89 alias Expression E; | 89 alias Expression E; |
90 | 90 |
91 override | 91 override |
92 { | 92 { |
93 E visit(CondExpression e) | 93 E visit(CondExpression e) |
258 static bool isBool(Expression e, bool value) | 258 static bool isBool(Expression e, bool value) |
259 { | 259 { |
260 switch(e.kind) | 260 switch(e.kind) |
261 { | 261 { |
262 alias NodeKind NK; | 262 alias NodeKind NK; |
263 | 263 |
264 case NK.IntExpression: | 264 case NK.IntExpression: |
265 auto num = (cast(IntExpression)e).number; | 265 auto num = (cast(IntExpression)e).number; |
266 return num ? value == true : value == false; | 266 return num ? value == true : value == false; |
267 | 267 |
268 case NK.RealExpression: | 268 case NK.RealExpression: |