mirror of https://github.com/aamine/cbc
* 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:
parent
8bc055ed4e
commit
8ca82908c1
29
ChangeLog
29
ChangeLog
|
@ -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
4
ToDo
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -22,4 +22,8 @@ abstract public class LiteralNode extends ExprNode {
|
|||
public TypeNode typeNode() {
|
||||
return typeNode;
|
||||
}
|
||||
|
||||
public boolean isConstant() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue