diff --git a/ChangeLog b/ChangeLog index aa91356..bb54f8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Apr 26 15:48:10 2009 Minero Aoki + + * net/loveruby/cflat/ast/FuncallNode.java: make a static funcall + really static funcall (not use pointer). + + net/loveruby/cflat/compiler/Simplifier.java: set aref result type. + Sun Apr 26 13:50:54 2009 Minero Aoki * net/loveruby/cflat/ast/FuncallNode.java: detect static call. diff --git a/net/loveruby/cflat/ast/FuncallNode.java b/net/loveruby/cflat/ast/FuncallNode.java index c9f4639..53c75ee 100644 --- a/net/loveruby/cflat/ast/FuncallNode.java +++ b/net/loveruby/cflat/ast/FuncallNode.java @@ -22,11 +22,9 @@ public class FuncallNode extends ExprNode { /** Returns true if this funcall is NOT a function pointer call. */ public boolean isStaticCall() { - if (! (expr instanceof AddressNode)) return false; - ExprNode var = ((AddressNode)expr).expr(); - if (! (var instanceof VariableNode)) return false; - Entity e = ((VariableNode)var).entity(); - return (e instanceof Function); + VariableNode var = getFunctionVariable(); + if (var == null) return false; + return (var.entity() instanceof Function); } /** @@ -34,11 +32,25 @@ public class FuncallNode extends ExprNode { * This method expects this is static function call (isStaticCall()). */ public Function function() { - AddressNode a = (AddressNode)expr; - VariableNode var = (VariableNode)a.expr(); + VariableNode var = getFunctionVariable(); + if (var == null) throw new Error("not a static funcall"); return (Function)var.entity(); } + private VariableNode getFunctionVariable() { + if (expr instanceof AddressNode) { + ExprNode e = ((AddressNode)expr).expr(); + if (! (e instanceof VariableNode)) return null; + return (VariableNode)e; + } + else if (expr instanceof VariableNode) { + return (VariableNode)expr; + } + else { + return null; + } + } + /** * Returns a type of return value of the function which is refered * by expr. This method expects expr.type().isCallable() is true. diff --git a/net/loveruby/cflat/compiler/Simplifier.java b/net/loveruby/cflat/compiler/Simplifier.java index 523084f..603f200 100644 --- a/net/loveruby/cflat/compiler/Simplifier.java +++ b/net/loveruby/cflat/compiler/Simplifier.java @@ -552,7 +552,9 @@ class Simplifier implements ASTVisitor { public ExprNode visit(ArefNode node) { ExprNode offset = binaryOp(intValue(node.elementSize()), "*", transformArrayIndex(node)); - return deref(binaryOp(transform(node.baseExpr()), "+", offset)); + return deref( + binaryOp(pointerTo(node.type()), + transform(node.baseExpr()), "+", offset)); } // For multidimension array: t[e][d][c][b][a];