* net/loveruby/cflat/ast/ExprNode.java: has all LHSNode methods.

* net/loveruby/cflat/ast/LHSNode.java: removed (methods merged into ExprNode).
* net/loveruby/cflat/ast/CastNode.java: should implement #isConstantAddress.
* net/loveruby/cflat/ast/DereferenceNode.java: does not implement LHSNode.
* net/loveruby/cflat/ast/ArefNode.java: ditto.
* net/loveruby/cflat/ast/PtrMemberNode.java: ditto.
* net/loveruby/cflat/ast/MemberNode.java: ditto.
* net/loveruby/cflat/ast/VariableNode.java: ditto.
* net/loveruby/cflat/ast/LiteralNode.java: ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java: cast not needed.
* test/cast3.cb: test cast on LHS.
* test/test.sh: run it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3802 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2008-01-05 03:52:41 +00:00
parent 8bc055ed4e
commit 8ca82908c1
14 changed files with 85 additions and 34 deletions

View File

@ -1,3 +1,32 @@
Sat Jan 5 12:52:38 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/ast/ExprNode.java: has all LHSNode methods.
* net/loveruby/cflat/ast/LHSNode.java: removed (methods merged
into ExprNode).
* net/loveruby/cflat/ast/CastNode.java: should implement
#isConstantAddress.
* net/loveruby/cflat/ast/DereferenceNode.java: does not implement
LHSNode.
* net/loveruby/cflat/ast/ArefNode.java: ditto.
* net/loveruby/cflat/ast/PtrMemberNode.java: ditto.
* net/loveruby/cflat/ast/MemberNode.java: ditto.
* net/loveruby/cflat/ast/VariableNode.java: ditto.
* net/loveruby/cflat/ast/LiteralNode.java: ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java: cast not needed.
* test/cast3.cb: test cast on LHS.
* test/test.sh: run it.
Sat Jan 5 12:23:25 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/compiler/Compiler.java: show error location.

4
ToDo
View File

@ -180,8 +180,8 @@
- parse command line option
- --dump-tokens
- --dump-ast
- print node location in error message
* parse command line option more precisely
* print node location in error message
* --dump-semantic
* generate IR
* --dump-ir
@ -197,4 +197,4 @@
* semantic check (dflow)
* register allocation
* vararg retrieve
* 64bit long_long support
? 64bit long_long support

View File

@ -2,7 +2,7 @@ package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.*;
import net.loveruby.cflat.asm.*;
public class ArefNode extends ExprNode implements LHSNode {
public class ArefNode extends ExprNode {
protected ExprNode expr, index;
public ArefNode(ExprNode expr, ExprNode index) {

View File

@ -1,5 +1,6 @@
package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.*;
import net.loveruby.cflat.asm.*;
public class CastNode extends ExprNode {
protected TypeNode typeNode;
@ -26,10 +27,22 @@ public class CastNode extends ExprNode {
return expr;
}
public boolean isConstant() {
return expr.isConstant();
}
public boolean isAssignable() {
return expr.isAssignable();
}
public boolean isConstantAddress() {
return expr.isConstantAddress();
}
public AsmEntity address() {
return expr.address();
}
public Location location() {
return typeNode.location();
}

View File

@ -2,7 +2,7 @@ package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.*;
import net.loveruby.cflat.asm.*;
public class DereferenceNode extends UnaryOpNode implements LHSNode {
public class DereferenceNode extends UnaryOpNode {
public DereferenceNode(ExprNode n) {
super(n);
}
@ -12,15 +12,8 @@ public class DereferenceNode extends UnaryOpNode implements LHSNode {
}
public boolean isAssignable() { return true; }
// LHS node requirement
public boolean isConstantAddress() { return false; }
// LHS node requirement
public AsmEntity address() {
throw new Error("DereferenceNode#address");
}
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}

View File

@ -17,11 +17,18 @@ abstract public class ExprNode extends Node {
return type().isDereferable();
}
public boolean isConstant() {
return false;
}
public boolean isAssignable() {
return false;
}
// FIXME: move this method to LHSNode
public boolean isConstantAddress() {
throw new Error("ExprNode#isConstantAddress called");
}
public AsmEntity address() {
throw new Error("ExprNode#address called");
}

View File

@ -1,8 +0,0 @@
package net.loveruby.cflat.ast;
import net.loveruby.cflat.asm.*;
public interface LHSNode {
public boolean isAssignable();
public boolean isConstantAddress();
public AsmEntity address();
}

View File

@ -22,4 +22,8 @@ abstract public class LiteralNode extends ExprNode {
public TypeNode typeNode() {
return typeNode;
}
public boolean isConstant() {
return true;
}
}

View File

@ -3,7 +3,7 @@ import net.loveruby.cflat.type.*;
import net.loveruby.cflat.asm.AsmEntity;
import net.loveruby.cflat.exception.*;
public class MemberNode extends ExprNode implements LHSNode {
public class MemberNode extends ExprNode {
protected ExprNode expr;
protected String name;
@ -41,14 +41,16 @@ public class MemberNode extends ExprNode implements LHSNode {
return true;
}
// LHS node requirement
public boolean isConstantAddress() {
return ((LHSNode)expr).isConstantAddress();
public boolean isConstant() {
return expr.isConstantAddress();
}
public boolean isConstantAddress() {
return expr.isConstantAddress();
}
// LHS node requirement
public AsmEntity address() {
return ((LHSNode)expr).address().add(offset());
return expr.address().add(offset());
}
public Location location() {

View File

@ -3,7 +3,7 @@ import net.loveruby.cflat.type.*;
import net.loveruby.cflat.asm.*;
import net.loveruby.cflat.exception.*;
public class PtrMemberNode extends ExprNode implements LHSNode {
public class PtrMemberNode extends ExprNode {
public ExprNode expr;
public String name;
@ -38,12 +38,10 @@ public class PtrMemberNode extends ExprNode implements LHSNode {
return true;
}
// LHS node requirement
public boolean isConstantAddress() {
return false;
}
// LHS node requirement
public AsmEntity address() {
throw new Error("PtrMemberNode#address");
}

View File

@ -2,7 +2,7 @@ package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.Type;
import net.loveruby.cflat.asm.*;
public class VariableNode extends ExprNode implements LHSNode {
public class VariableNode extends ExprNode {
protected Location location;
protected String name;
protected Entity entity;
@ -40,12 +40,10 @@ public class VariableNode extends ExprNode implements LHSNode {
return true;
}
// LHS node requirement
public boolean isConstantAddress() {
return true;
}
// LHS node requirement
public AsmEntity address() {
return entity.address();
}

View File

@ -399,8 +399,7 @@ static public void p(String s) { System.err.println(s); }
}
public void visit(AssignNode node) {
// FIXME
if (((LHSNode)node.lhs()).isConstantAddress()) {
if (node.lhs().isConstantAddress()) {
compile(node.rhs());
saveWords(node.type(), "ax", node.lhs().address());
}

15
test/cast3.cb Normal file
View File

@ -0,0 +1,15 @@
import stdio;
int
main(int argc, char **argv)
{
int i;
int* ptr = &i;
(int)i = 666;
printf("%d", i);
*(int*)ptr = 777;
printf(";%d", *ptr);
puts("");
return 0;
}

View File

@ -196,6 +196,7 @@ assert_out "1;2;1073741824;2147483648;0" ./ulongops # 32bit
assert_out "25000000" ./cast
assert_out "777;666" ./cast2
assert_out "666;777" ./cast3
assert_out "2" ./block
assert_out "1;2;3" ./defvar