Mercurial > hg > truffle
diff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java @ 13821:b16ec83edc73
Documentation and more refactoring of Simple Language
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Wed, 29 Jan 2014 20:45:43 -0800 |
parents | 7c418666c6c9 |
children | ff3136ecb5a7 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java Wed Jan 29 20:43:28 2014 -0800 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java Wed Jan 29 20:45:43 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,14 +24,40 @@ import java.math.*; +import com.oracle.truffle.api.dsl.*; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.sl.runtime.*; +/** + * Base class for all SL nodes that produce a value and therefore benefit from type specialization. + * The annotation {@Link TypeSystemReference} specifies the SL types. Specifying it here + * defines the type system for all subclasses. + */ +@TypeSystemReference(SLTypes.class) public abstract class SLExpressionNode extends SLStatementNode { + /** + * The execute method when no specialization is possible. This is the most general case, + * therefore it must be provided by all subclasses. + */ public abstract Object executeGeneric(VirtualFrame frame); + /** + * When we use an expression at places where a {@SLStatmentNode statement} is + * already sufficient, the return value is just discarded. + */ + @Override + public void executeVoid(VirtualFrame frame) { + executeGeneric(frame); + } + + /* + * Execute methods for specialized types. They all follow the same pattern: they call the + * generic execution method and then expect a result of their return type. Type-specialized + * subclasses overwrite the appropriate methods. + */ + public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException { return SLTypesGen.SLTYPES.expectBoolean(executeGeneric(frame)); } @@ -52,24 +78,7 @@ return SLTypesGen.SLTYPES.expectSLFunction(executeGeneric(frame)); } - public Object[] executeArray(VirtualFrame frame) throws UnexpectedResultException { - return SLTypesGen.SLTYPES.expectObjectArray(executeGeneric(frame)); - } - public SLNull executeNull(VirtualFrame frame) throws UnexpectedResultException { return SLTypesGen.SLTYPES.expectSLNull(executeGeneric(frame)); } - - public final boolean executeCondition(VirtualFrame frame) { - try { - return executeBoolean(frame); - } catch (UnexpectedResultException ex) { - throw new RuntimeException("Illegal type for condition: " + ex.getResult().getClass().getSimpleName()); - } - } - - @Override - public void executeVoid(VirtualFrame frame) { - executeGeneric(frame); - } }