Mercurial > projects > dil
view src/dil/semantic/Interpreter.d @ 820:1d06b4aed7cf
Revised code in the first pass.
Added code to handle anonymous unions and structs. Hope the idea will work.
Added type to class Aggregate and isAnonymous to some other Symbol classes.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 14 Mar 2008 15:42:08 +0100 |
parents | bcb74c9b895c |
children | 09a64d96967a |
line wrap: on
line source
/++ Author: Aziz Köksal License: GPL3 +/ module dil.semantic.Interpreter; import dil.ast.Visitor; import dil.ast.Node, dil.ast.Declarations, dil.ast.Expressions, dil.ast.Statements, dil.ast.Types, dil.ast.Parameters; import dil.semantic.Symbol, dil.semantic.Symbols, dil.semantic.Scope, dil.semantic.Types; import dil.Information; /// Used for compile-time evaluation of expressions. class Interpreter : Visitor { // Scope scop; InfoManager infoMan; static class Result : Expression { override Result copy(){return null;} } static const Result NAR; /// Not a Result. Similar to NAN in floating point arithmetics. static this() { NAR = new Result; NAR.type = Types.Error; } /// Evaluates the expression e. /// Returns: NAR or a value. static Expression interpret(Expression e, InfoManager infoMan/+, Scope scop+/) { return (new Interpreter(/+scop,+/ infoMan)).eval(e); } /// Constructs an Interpreter object. this(/+Scope scop, +/InfoManager infoMan) { // this.scop = scop; this.infoMan = infoMan; } /// Start evaluation. Expression eval(Expression e) { return e; } /// Returns true if e is immutable. bool isImmutable(Expression e) { switch (e.kind) { alias NodeKind NK; case NK.IntExpression, NK.RealExpression, NK.ComplexExpression, NK.CharExpression, NK.BoolExpression, NK.StringExpression: return true; default: } return false; } }