Commit Graph

72 Commits

Author SHA1 Message Date
Minero Aoki cf37e6ae72 * test/cbc: provide -I option to add load path.
* net/loveruby/cflat/compiler/Compiler.java: new option -I.
* net/loveruby/cflat/parser/Parser.jj: allow nested library ID "a.b.c".
* net/loveruby/cflat/compiler/LibraryLoader.java: ditto.
* import/unistd.hb: declare fork, getpid, getppid.
* import/sys/types.hb: new file.
* test/fork.cb: test nested library ID "sys.types".


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3829 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 12:49:03 +00:00
Minero Aoki 1b544d25f6 * move *.hb files from test/ to import/.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3828 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 12:23:38 +00:00
Minero Aoki 173fedc9ef * test/string.hb: new file.
* test/strings.hb: new file.
* test/stddef.hb: new file.
* test/errno.hb: new file.
* test/stdio.hb: add more decls.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3827 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 12:22:33 +00:00
Minero Aoki 2c3c2d2db7 * net/loveruby/cflat/ast/DefinedFunction.java: remove unused method #isFunction.
* net/loveruby/cflat/ast/UndefinedFunction.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3826 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-13 17:40:39 +00:00
Minero Aoki 0a0e766158 * net/loveruby/cflat/parser/Parser.jj: unify IntegerLiteralNode and CharacterLiteralNode.
* net/loveruby/cflat/compiler/Visitor.java: ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java: ditto.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/ast/ASTVisitor.java: ditto.
* net/loveruby/cflat/ast/CharacterLiteralNode.java: removed.
* net/loveruby/cflat/ast/IntegerLiteralNode.java: show typeNode member.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3825 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-13 17:21:25 +00:00
Minero Aoki bb539ff306 add preproc tag
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3824 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-13 15:45:29 +00:00
Minero Aoki 828bba1d9e * net/loveruby/cflat/compiler/Compiler.java (parseFile): report errors if it is not a syntax error.
* net/loveruby/cflat/parser/Parser.jj: declare SyntaxException and FileException separately.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3823 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 23:13:48 +00:00
Minero Aoki b640304ccf * net/loveruby/cflat/compiler/Compiler.java: new option --debug-parser.
* net/loveruby/cflat/parser/Parser.jj: dump parsing process using JavaCC's tracing function.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3822 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 22:54:07 +00:00
Minero Aoki 13bee146e1 * net/loveruby/cflat/compiler/DereferenceChecker.java: throw SemanticError on invalid expr and catch it on each statement.
* test/test3.cb: make compilable.
* test/aref-semcheck2.cb: test nested invalid expr.
* test/test.sh: run aref-semcheck2.cb.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3821 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 21:53:46 +00:00
Minero Aoki d77ee40092 * net/loveruby/cflat/type/ArrayType.java (size): returns pointer size if the type is not allocated.
* test/test.sh: test integer.cb.
* test/test.sh: test initializer.cb.
* test/test.sh: test test2.cb.
* test/test.sh: test test3.cb.
* test/test.sh: test test4.cb.
* test/test2.cb: long long is not supported now.
* test/test4.cb: f -> main to make compilable.
* test/list-untested.rb: new tool.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3820 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 20:21:11 +00:00
Minero Aoki fd5caed6fc * net/loveruby/cflat/compiler/TypeChecker.java: fork DereferenceChecker, to reduce catch(SemanticError).
* net/loveruby/cflat/compiler/DereferenceChecker.java: new class.
* net/loveruby/cflat/ast/ExprNode.java (isAssignable, isDereferable): catch SemanticError which may occuer on type.isXXXX.
* net/loveruby/cflat/compiler/Visitor.java: refactoring: rename method: #resolve -> #visitNode.
* net/loveruby/cflat/compiler/Visitor.java: refactoring: rename method: #resolveNodeList -> #visitNodeList.
* net/loveruby/cflat/compiler/JumpResolver.java: ditto.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: ditto.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/compiler/Compiler.java: parse command line options more precisely.
* net/loveruby/cflat/compiler/Compiler.java: new option --compile.
* net/loveruby/cflat/compiler/Compiler.java: new option --dump-reference.
* net/loveruby/cflat/compiler/Compiler.java: new option --dump-semantic.
* net/loveruby/cflat/ast/VariableNode.java (dump): show resolved or not.
* net/loveruby/cflat/ast/TypeNode.java (dump): ditto.
* net/loveruby/cflat/ast/Dumper.java (printMember): ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3819 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 19:48:31 +00:00
Minero Aoki a88b9a2bca * net/loveruby/cflat/type/Type.java: make #isCompatible and #isCastable abstract.
* net/loveruby/cflat/type/VoidType.java: define #equals, #isSameType, #isCompatible, #isCastableTo.
* net/loveruby/cflat/type/ComplexType.java: define #isSameType, #isCompatible, #isCastableTo, #memberTypes.
* net/loveruby/cflat/type/ArrayType.java: define #isCompatible, #isCastableTo.
* net/loveruby/cflat/type/PointerType.java (isCompatible): void pointer is compatible with any pointer.
* net/loveruby/cflat/type/FunctionType.java: check parameter types.
* net/loveruby/cflat/ast/Params.java: define #types and #isSameType to be used from FunctionType.
* net/loveruby/cflat/ast/FixedParams.java: ditto.
* net/loveruby/cflat/ast/VarParams.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: new method #voidType.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3818 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 19:47:28 +00:00
Minero Aoki 3c73577871 forgot to check in
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3817 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 19:34:57 +00:00
Minero Aoki 89667f89fa * test/unistd.hb: define _exit.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3816 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 19:34:34 +00:00
Minero Aoki 2416f943ee forgot to check in
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3815 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-06 22:47:03 +00:00
Minero Aoki ab9b6482c0 * net/loveruby/cflat/parser/Parser.jj: refactoring: rename method: #loc -> #location.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3814 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-06 22:08:49 +00:00
Minero Aoki 7f4052d80d add preproc tag
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3813 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-06 20:12:30 +00:00
Minero Aoki 3c595a692e * net/loveruby/cflat/compiler/Compiler.java (invoke): pass through stdout/stderr of child process.
* net/loveruby/cflat/compiler/CodeGenerator.java: #register removed.  Use DSL method al(), cl(), eax() instead.
* net/loveruby/cflat/asm/Register.java: return "%al" for size 1 ax register.
* test/shunit.sh: allow to get stderr of testing command by setting environment variable SHUNIT_VERBOSE.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3812 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-06 17:22:55 +00:00
Minero Aoki 6d4a3ec301 * net/loveruby/cflat/ast/UnaryOpNode.java (_dump): show operator.
* net/loveruby/cflat/ast/BinaryOpNode.java (_dump): show operator.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3811 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 17:27:32 +00:00
Minero Aoki edb761bfb4 * Type class hierarchy grand restruct: retire Signed*Type, Unsigned*Type, Signed*Ref, Unsigned*Ref.
* net/loveruby/cflat/type/IntegerTypeRef.java: new class.  unify Signed*Ref, Unsigned*Ref.
* net/loveruby/cflat/type/IntegerType.java: unify Signed*Type, Unsigned*Type.
* net/loveruby/cflat/type/Unsigned*.java: removed.
* net/loveruby/cflat/type/Signed*.java: removed.
* net/loveruby/cflat/type/TypeRef.java (hashCode): calculate hashCode based on typeref name.
* net/loveruby/cflat/type/*TypeRef.java: follow it.
* net/loveruby/cflat/type/TypeTable.java: follow these changes.
* net/loveruby/cflat/parser/Parser.jj: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3808 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 15:33:44 +00:00
Minero Aoki 4c48f185f6 * AST class hierarchy grand restruct: remove and unify many operator nodes.
* net/loveruby/cflat/ast/UnaryOpNode.java: unify arithmetic unary op nodes (+, -, !, ~).
* net/loveruby/cflat/ast/BinaryOpNode.java: unify almost all binary op nodes (+, -, *, /, %, &, |, ^, <<, >>) and comparison operators (==, !=, >, >=, <, <=).
* net/loveruby/cflat/ast/PrefixOpNode.java: new class.  unify prefix inc/dec.
* net/loveruby/cflat/ast/SuffixOpNode.java: new class.  unify suffix inc/dec.
* net/loveruby/cflat/ast/OpAssignNode.java: new class.  unify all *AssignNode.
* net/loveruby/cflat/parser/Parser.jj: follow these grand changes.
* net/loveruby/cflat/compiler/Visitor.java: ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/ast/DereferenceNode.java: ditto.
* net/loveruby/cflat/ast/LogicalAndNode.java: ditto.
* net/loveruby/cflat/ast/LogicalOrNode.java: ditto.
* net/loveruby/cflat/ast/AddressNode.java: ditto.
* net/loveruby/cflat/ast/ASTVisitor.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3807 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 14:48:18 +00:00
Minero Aoki 7d66e5dffc * net/loveruby/cflat/compiler/Compiler.java: report error.
* net/loveruby/cflat/parser/Parser.jj: simplify error message.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3806 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 04:57:36 +00:00
Minero Aoki cf1b3c39a8 * net/loveruby/cflat/ast/MemberNode.java: #name -> #member.
* net/loveruby/cflat/ast/PtrMemberNode.java: #name -> #member.
* net/loveruby/cflat/compiler/TypeChecker.java: follow changes.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3805 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 04:24:00 +00:00
Minero Aoki 4120f4c40a * net/loveruby/cflat/ast/Declaration.java: removed.
* net/loveruby/cflat/ast/Definition.java: removed.
* net/loveruby/cflat/ast/Entity.java: inherits Node now.
* net/loveruby/cflat/ast/TypeDefinition.java: inherits Node now.
* net/loveruby/cflat/ast/ToplevelScope.java: do not depend on Declaration.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/ast/CaseNode.java: inherits StmtNode.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3804 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 04:20:35 +00:00
Minero Aoki d1cc40efdf updated
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3803 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 03:53:29 +00:00
Minero Aoki 8ca82908c1 * 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
2008-01-05 03:52:41 +00:00
Minero Aoki 8bc055ed4e * net/loveruby/cflat/compiler/Compiler.java: show error location.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/compiler/ErrorHandler.java: ditto.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: ditto.
* net/loveruby/cflat/compiler/JumpResolver.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: ditto.
* net/loveruby/cflat/ast/Scope.java: ditto.
* net/loveruby/cflat/type/NamedType.java: introduce new common superclass of ComplexType and UserType.
* net/loveruby/cflat/type/ComplexType.java: inherit NamedType.
* net/loveruby/cflat/type/UserType.java: inherit NamedType.
* net/loveruby/cflat/type/StructType.java: memoise defined location.
* net/loveruby/cflat/type/UnionType.java: ditto.
* net/loveruby/cflat/ast/DefinedFunction.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: change define* methods interface to pass all definition informations.
* net/loveruby/cflat/ast/StructNode.java: follow it.
* net/loveruby/cflat/ast/UnionNode.java: follow it.
* net/loveruby/cflat/ast/TypedefNode.java: follow it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3801 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 03:23:27 +00:00
Minero Aoki 879738ba62 * net/loveruby/cflat/ast/Node.java: all nodes must contain Location.
* net/loveruby/cflat/ast/*Node.java: ditto.
* net/loveruby/cflat/ast/Location.java: new class.
* net/loveruby/cflat/ast/Dumper.java (printClass): show location.
* net/loveruby/cflat/type/*Ref.java: support Location.
* net/loveruby/cflat/parser/Parser.jj: pass location to nodes.
* net/loveruby/cflat/parser/Parser.jj: long long removed.
* net/loveruby/cflat/type/SignedLongLongRef.java: ditto.
* net/loveruby/cflat/type/UnsignedLongLongRef.java: ditto.
* net/loveruby/cflat/type/SignedLongLongType.java: ditto.
* net/loveruby/cflat/type/UnsignedLongLongType.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: ditto.
* net/loveruby/cflat/ast/LiteralNode.java: introduce new superclass of all literal nodes.
* net/loveruby/cflat/ast/StmtNode.java: introduce new superclass of all statement nodes.
* net/loveruby/cflat/ast/Declaration.java: is subclass of Node.
* net/loveruby/cflat/ast/Dumpable.java: removed: Now declarations are subclass of Node.
* net/loveruby/cflat/ast/Dumper.java: follow new class hierarchy.
* net/loveruby/cflat/ast/DefinitionVisitor.java: removed: merge into ASTVisitor again.
* net/loveruby/cflat/compiler/Visitor.java: follow new class hierarchy.
* net/loveruby/cflat/compiler/CodeGenerator.java: ditto.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3800 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 01:34:27 +00:00
Minero Aoki 57b38c5a86 * test/test.sh: compile command by myself before run it.
* test/shunit.sh (assert_status, assert_error, assert_stdout): allow any number of arguments for command.
* test/Makefile: remove task "cbprograms".
* test/Makefile (clean): clean programs depending on svn:ignore list.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3799 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 23:00:28 +00:00
Minero Aoki 67442a4801 * test/cast2.cb: test cast from long* to int*.
* test/test.sh: change result.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3798 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 22:36:45 +00:00
Minero Aoki 6e3f520a14 * net/loveruby/cflat/compiler/CodeGenerator.java (DereferenceNode): reduce compileLHS call.
* test/pointer4.cb: test derefering AddressNode.
* test/test.sh: run it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3797 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 22:33:14 +00:00
Minero Aoki f327f73a0e * net/loveruby/cflat/compiler/CodeGenerator.java (compileLHS): support CastNode.
* net/loveruby/cflat/compiler/TypeChecker.java: do not warn incompatible cast, if it is castable.
* net/loveruby/cflat/type/IntegerType.java (isCastable): allow array.
* net/loveruby/cflat/type/Type.java (isCastable): use isCompatible for default implementation.
* net/loveruby/cflat/type/PointerType.java: forgot to add #isCompatible.
* net/loveruby/cflat/type/PointerType.java: forgot to add #isCastable.
* net/loveruby/cflat/type/PointerType.java (equals): reject type alias by using instanceof.
* net/loveruby/cflat/ast/CastNode.java: forward #isAssignable to base expr.
* test/cast2.cb: test cast of pointer.
* test/Makefile: build it.
* test/test.sh: test it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3796 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 22:21:20 +00:00
Minero Aoki 0f19acf7c4 * test/pointer2.cb: test multiple level of pointer.
* test/array-semcheck2.cb -> array2.cb.
* test/pointer-semcheck1.cb -> pointer3.cb.
* test/Makefile: follow them.
* test/test.sh: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3795 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 21:51:37 +00:00
Minero Aoki 6524517b78 * net/loveruby/cflat/compiler/TypeChecker.java: reject invalid RHS type explicitly.
* net/loveruby/cflat/compiler/TypeChecker.java: reject void paramters.
* net/loveruby/cflat/compiler/TypeChecker.java: allow all type of arrays for RHS.
* net/loveruby/cflat/compiler/CodeGenerator.java (variableNode): generate address for allocated array on RHS.
* net/loveruby/cflat/compiler/CodeGenerator.java (ArefNode): expects expr generates pointer by compile().
* net/loveruby/cflat/compiler/CodeGenerator.java (compileLHS/ArefNode): unallocated array is a pointer.
* net/loveruby/cflat/type/Type.java: new method #isPointerAlike.
* net/loveruby/cflat/type/ArrayType.java: implement it.
* net/loveruby/cflat/type/PointerType.java: implement it.
* net/loveruby/cflat/asm/Assembler.java: new method #comment, to add comment.
* test/array-semcheck2.cb: check assignment to unallocated array.
* test/array-semcheck2.cb: check dereference of unallocated array.
* test/Makefile: build it.
* test/test.sh: run it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3794 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 21:36:54 +00:00
Minero Aoki 4314a6b35c * test/test.sh: new function assert_compile_error to check if compile error occured really (rejects runtime error).
* test/Makefile: remove task "errors".


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3793 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 19:27:31 +00:00
Minero Aoki 78c1c633dc * net/loveruby/cflat/compiler/TypeChecker.java: check if variable type is not void (gvar, lvar).
* net/loveruby/cflat/compiler/TypeChecker.java: check if parameter type is not void.
* net/loveruby/cflat/compiler/TypeChecker.java: allow unallocated array for parameter.
* net/loveruby/cflat/compiler/TypeChecker.java: refactoring: rename method: #resolve -> #check.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3792 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 19:05:23 +00:00
Minero Aoki bdaa4f96d1 * net/loveruby/cflat/type/Type.java: #textize -> #toString.
* net/loveruby/cflat/type/IntegerType.java: ditto.
* net/loveruby/cflat/type/ComplexType.java: ditto.
* net/loveruby/cflat/type/StructType.java: ditto.
* net/loveruby/cflat/type/FunctionType.java: ditto.
* net/loveruby/cflat/type/VoidType.java: ditto.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/type/ArrayType.java: ditto.
* net/loveruby/cflat/type/PointerType.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: ditto.
* net/loveruby/cflat/type/UnionType.java: ditto.
* net/loveruby/cflat/ast/Dumper.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3791 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-04 18:43:45 +00:00
Minero Aoki a023940537 * net/loveruby/cflat/ast/Dumper.java: specialize TypeNode printing.
* net/loveruby/cflat/ast/Params.java: show parameter list.
* net/loveruby/cflat/type/*TypeRef.java: define #toString.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3788 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 23:30:58 +00:00
Minero Aoki 132e4cbbb2 * net/loveruby/cflat/compiler/Compiler.java: implement command line option --dump-ast.
* net/loveruby/cflat/compiler/Compiler.java: implement command line option --dump-tokens.
* net/loveruby/cflat/ast/Dumper.java: new class; AST dumper.
* net/loveruby/cflat/ast/Dumpable.java: new interface; AST dumper interface.
* net/loveruby/cflat/ast/*.java: define #dump, #_dump.
* net/loveruby/cflat/asm/Assembler.java: fork utils/TextUtils.java.
* net/loveruby/cflat/utils/TextUtils.java: new file.
* test/stdlib.hb: new header file.
* test/unistd.hb: new header file.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3787 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 23:01:49 +00:00
Minero Aoki e62800377f * test/struct-semcheck10.cb: test struct which contains void.
* test/union-semcheck10.cb: test union which contains void.
* test/array-semcheck1.cb: test array which contains void.
* test/test.sh: run them.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3786 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 18:23:38 +00:00
Minero Aoki 36c6071ffa * net/loveruby/cflat/compiler/TypeResolver.java: refactoring: unify gvar/lvar initializer resolver.
* net/loveruby/cflat/compiler/TypeChecker.java: check gvar initializer.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: resolve gvar initializer.
* net/loveruby/cflat/ast/AST.java: new method #variables.
* test/initializer.cb: test variable initializer.
* test/stdio.hb: return type of printf/puts/putc is int.
* test/usertype.cb: ditto.
* test/funcptr.cb: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3785 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 18:15:31 +00:00
Minero Aoki 1a71c3cdad * net/loveruby/cflat/compiler/Visitor.java: did not visit lvar initializer.
* net/loveruby/cflat/compiler/TypeChecker.java: check lvar initializer.
* net/loveruby/cflat/ast/DefinedVariable.java: new method #setInitializer.
* net/loveruby/cflat/type/PointerType.java (isSameType): all array is same type (allocated arrays are rejected by LHS check).
* test/block.cb: was wrong test.
* test/assign.cb: add tests.
* test/test.sh: adjust output for assign.cb.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3784 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 17:47:21 +00:00
Minero Aoki b904473b66 * net/loveruby/cflat/compiler/TypeChecker.java (PtrMemberNode): allow array for base expr.
* net/loveruby/cflat/compiler/CodeGenerator.java (AssignNode): should not leave RHS value on stack (because of feature change).
* net/loveruby/cflat/compiler/CodeGenerator.java (VariableNode): load address for array, to support ptr = ary.
* net/loveruby/cflat/compiler/CodeGenerator.java (ArefNode): dereference pointer, to support ptr[0].
* net/loveruby/cflat/compiler/CodeGenerator.java (compileLHS/ArefNode): ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java (compileLHS/ArefNode): support non-LHS expr.
* net/loveruby/cflat/compiler/CodeGenerator.java (compileLHS/ArefNode): support non-constant index.
* net/loveruby/cflat/compiler/CodeGenerator.java (compileLHS/DereferenceNode): support non-LHS expr.
* net/loveruby/cflat/compiler/CodeGenerator.java (compileLHS/PtrMemberNode): support non-LHS expr.
* net/loveruby/cflat/compiler/CodeGenerator.java (PrefixIncNode, PrefixDecNode, SuffixIncNode, SuffixDecNode): support pointer inc/dec.
* net/loveruby/cflat/compiler/CodeGenerator.java: #size -> #allocSize.
* net/loveruby/cflat/type/Type.java: new method #allocSize, to support ptr = ary.
* net/loveruby/cflat/type/ArrayType.java: override #size and #allocSize.
* net/loveruby/cflat/ast/Entity.java: should define #allocSize, not #size.
* net/loveruby/cflat/asm/Register.java: should not handle AMD64 registers.
* net/loveruby/cflat/asm/Assembler.java: should not handle >4 size operators.
* test/pointer-semcheck1.cb: test ptr = ary; ptr[0].
* test/deref-semcheck4.cb: test 1->memb.
* test/deref-semcheck5.cb: test ptr->y where y is not a member.
* test/Makefile: build pointer-semcheck1.
* test/test.sh: run them.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3783 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 16:46:44 +00:00
Minero Aoki cf5e6d12ef * net/loveruby/cflat/type/TypeTable.java: should use #getComplexType to dereference UserType into real ComplexType.
* test/union-semcheck9.cb: test recursive struct whose member is user type.
* test/struct-semcheck9.cb: test recursive union whose member is user type.
* test/test.sh: run them.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3782 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 14:37:41 +00:00
Minero Aoki 5b61b2f529 * net/loveruby/cflat/compiler/TypeChecker.java: try semantic check and catch semantic errors (mainly thrown from *Node#type).
* net/loveruby/cflat/exception/SemanticError.java: new class.
* net/loveruby/cflat/type/ComplexType.java: throw SemanticError when no member found.
* net/loveruby/cflat/type/Type.java: #baseType throw SemanticError instead of Error.
* net/loveruby/cflat/ast/FuncallNode.java: convert ClassCastException to SemanticError.
* net/loveruby/cflat/ast/PtrMemberNode.java: ditto.
* net/loveruby/cflat/ast/MemberNode.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: check recursive typedef.
* net/loveruby/cflat/type/TypeTable.java: validate array/struct/union does not contain void.
* net/loveruby/cflat/type/UserType.java: #real -> #realType.
* test/struct-semcheck8.cb: test 1.memb.
* test/union-semcheck8.cb: test (1+"str").memb.
* test/Makefile: build them.
* test/test.sh: run them.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3781 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 14:31:26 +00:00
Minero Aoki 1264a6649a * net/loveruby/cflat/compiler/TypeChecker.java: check type by #isSameType, do not use #equals. List uses #equals for identity check, PointerType.equals(UserType) should be false. But type check expects PointerType.isSameType(UserType) should be true if the UserType is really a pointer.
* net/loveruby/cflat/type/Type.java: new method #isSameType.
* net/loveruby/cflat/type/IntegerType.java: ditto.
* net/loveruby/cflat/type/StructType.java: ditto.
* net/loveruby/cflat/type/FunctionType.java: ditto.
* net/loveruby/cflat/type/VoidType.java: ditto.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/type/ArrayType.java: ditto.
* net/loveruby/cflat/type/PointerType.java: ditto.
* net/loveruby/cflat/type/UnionType.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3780 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 12:36:36 +00:00
Minero Aoki b5a6bf6b05 * net/loveruby/cflat/compiler/TypeChecker.java: reject LHS which has invalid type (struct, union, allocated array).
* net/loveruby/cflat/compiler/TypeChecker.java: reject arguments which has invalid type (struct, union, allocated array).
* net/loveruby/cflat/type/Type.java: new method #isAllocatedArray.
* net/loveruby/cflat/type/ArrayType.java: override it.
* net/loveruby/cflat/type/ArrayType.java: new method #isAllocated.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3779 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 11:51:51 +00:00
Minero Aoki 61791bbb0d * test/ptrmemb.cb: test ptr->x where ptr is a pointer to union.
* test/ptrmemb.cb: test (*ptr).x where ptr is a pointer to struct.
* test/ptrmemb.cb: test (*ptr).x where ptr is a pointer to union.
* test/ptrtostruct.cb: merged to ptrmemb.cb.
* test/test.sh: remove ptrtostruct.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3778 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 11:37:57 +00:00
Minero Aoki a368d3cc92 * test/ptrtostruct.cb: test (*ptr).memb access.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3777 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 11:31:57 +00:00
Minero Aoki 9915a036dc * net/loveruby/cflat/compiler/TypeChecker.java: <<, >> does not require same type of integers. 2 types of integers are OK.
* net/loveruby/cflat/compiler/TypeChecker.java: arrays and pointers are both dereferable (== indexable).  We can dereference both.
* net/loveruby/cflat/type/Type.java: #isIndexable -> #isDereferable.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/type/ArrayType.java: ditto.
* net/loveruby/cflat/ast/ExprNode.java: ditto.
* net/loveruby/cflat/type/Type.java: #isReferable -> #isDereferable.
* net/loveruby/cflat/type/ArrayType.java: ditto.
* net/loveruby/cflat/type/PointerType.java: ditto.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/ast/ArefNode.java: ptr[0] should be allowed.  Use #isDereferable instead of explict pointer check.
* net/loveruby/cflat/ast/DereferenceNode.java: override #type.
* net/loveruby/cflat/ast/ArefNode.java: remove cast for Type.
* net/loveruby/cflat/ast/FuncallNode.java: #functionType should be called after checking isCallable, type check is not needed in #functionType.
* net/loveruby/cflat/ast/PtrMemberNode.java: #baseType -> #dereferedType.
* net/loveruby/cflat/ast/MemberNode.java: reduce cast for Type.
* net/loveruby/cflat/type/Type.java: define #baseType here.
* net/loveruby/cflat/type/ArrayType.java: override #baseType (#base -> #baseType).
* net/loveruby/cflat/type/PointerType.java: ditto.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/ast/Function.java: ditto.
* net/loveruby/cflat/type/PointerType.java: is not an integer.  #isInteger removed.
* net/loveruby/cflat/type/ArrayTypeRef.java: #base -> #baseType.
* net/loveruby/cflat/type/PointerTypeRef.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: do not use cast methods, use true cast, since the real type is required here.
* test/usertype.cb: test user type.
* test/Makefile: build it.
* test/test.sh: run it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3776 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 11:26:07 +00:00