Commit Graph

25 Commits

Author SHA1 Message Date
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 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 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
Minero Aoki 50a9d75946 * net/loveruby/cflat/compiler/TypeChecker.java: check if parameter type is valid.
* net/loveruby/cflat/compiler/TypeChecker.java: check if argument type is valid.
* net/loveruby/cflat/compiler/TypeChecker.java: check if lhs is assignable.
* net/loveruby/cflat/compiler/TypeChecker.java: reduce cast.
* net/loveruby/cflat/ast/Function.java: define #address here.
* net/loveruby/cflat/ast/DefinedFunction.java: ditto.
* net/loveruby/cflat/ast/UndefinedFunction.java: ditto.
* net/loveruby/cflat/ast/BlockNode.java: fix type error by cast.
* test/test.sh: test funcptr2.
* test/funcptr2.cb: test a function pointer to local (defined) function.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3775 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 09:00:13 +00:00
Minero Aoki c2298ffbd2 * net/loveruby/cflat/compiler/TypeChecker.java: check return type.
* net/loveruby/cflat/compiler/JumpResolver.java: set exiting function to ReturnNode.
* net/loveruby/cflat/ast/ReturnNode.java: new method #setExpr.
* net/loveruby/cflat/ast/ReturnNode.java: new method #function.
* net/loveruby/cflat/ast/ReturnNode.java: new method #setFunction.
* net/loveruby/cflat/ast/Function.java: new method #isVoid.
* net/loveruby/cflat/ast/Function.java: new method #returnType.
* net/loveruby/cflat/ast/Function.java: new method #functionType.
* net/loveruby/cflat/type/TypeRef.java: new method #getPointerTypeRef.
* net/loveruby/cflat/type/TypeRef.java: new method #getArrayTypeRef.
* net/loveruby/cflat/type/TypeRef.java: new method #getStructTypeRef.
* net/loveruby/cflat/type/TypeRef.java: new method #getUnionTypeRef.
* net/loveruby/cflat/type/TypeRef.java: new method #getFunctionTypeRef.
* net/loveruby/cflat/type/TypeRef.java: #isFunctionType -> #isFunction.
* net/loveruby/cflat/type/FunctionTypeRef.java: ditto.
* net/loveruby/cflat/type/TypeRef.java: #isVoidTypeRef -> #isVoid.
* net/loveruby/cflat/type/VoidTypeRef.java: ditto.
* net/loveruby/cflat/type/TypeRef.java: #isArrayTypeRef -> #isArray.
* net/loveruby/cflat/type/ArrayTypeRef.java: ditto.
* net/loveruby/cflat/type/Type.java: #isNumeric removed.
* net/loveruby/cflat/type/IntegerType.java: ditto.
* net/loveruby/cflat/type/Type.java: new method #getComplexType.
* net/loveruby/cflat/type/Type.java: new method #getStructType.
* net/loveruby/cflat/type/Type.java: new method #getUnionType.
* net/loveruby/cflat/type/Type.java: new method #getArrayType.
* net/loveruby/cflat/type/Type.java: new method #getPointerType.
* net/loveruby/cflat/type/Type.java: new method #getFunctionType.
* net/loveruby/cflat/type/UserType.java: override them.
* net/loveruby/cflat/type/PointerType.java (equals): reduce instanceof.
* net/loveruby/cflat/type/TypeTable.java: reduce instanceof/cast.
* test/test.sh: invoke following tests.
* test/defun-semcheck2.cb: test returning value from void function.
* test/defun-semcheck3.cb: test returning nothing from non-void function.
* test/defun-semcheck4.cb: test returning struct.
* test/defun-semcheck5.cb: test returning union.
* test/defun-semcheck6.cb: test returning user type, which is union.
* test/defun-semcheck7.cb: test returning user type, which is struct.
* test/defun-semcheck8.cb: test returning array.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3771 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-02 10:18:38 +00:00
Minero Aoki ea681c1f96 * net/loveruby/cflat/compiler/TypeResolver.java: pass ErrorHandler to TypeType#semanticCheck.
* net/loveruby/cflat/type/TypeTable.java (semanticCheck): check duplicated member.
* test/test.sh: invoke following test cases.
* test/struct-semcheck7.cb: test duplicated member on struct.
* test/union-semcheck7.cb: test duplicated member on union.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3769 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 18:17:50 +00:00
Minero Aoki 1dedd1d283 * net/loveruby/cflat/compiler/TypeChecker.java: better error message.
* test/test.sh: run following tests.
* test/deref-semcheck1.cb: check if dereferencing int causes compile error.
* test/deref-semcheck2.cb: check if dereferencing char causes compile error.
* test/deref-semcheck3.cb: check if dereferencing struct causes compile error.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3767 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 16:32:15 +00:00
Minero Aoki 705818d1dc * net/loveruby/cflat/compiler/TypeChecker.java: check member validity for s.memb, s->memb, u.memb, u->memb.
* net/loveruby/cflat/type/Type.java: new method #isComplexType.
* net/loveruby/cflat/type/ComplexType.java: override it.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: should resolve variable initializer.
* net/loveruby/cflat/ast/DefinedVariable.java: new method #hasInitializer.
* test/test.sh: run tests.
* test/struct-semcheck5.cb: check if member is valid on s.memb.
* test/struct-semcheck6.cb: check if member is valid on sptr->memb.
* test/union-semcheck5.cb: check if member is valid on u.memb.
* test/union-semcheck6.cb: check if member is valid on uptr->memb.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3766 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 16:24:09 +00:00
Minero Aoki 0b70938a5f * net/loveruby/cflat/compiler/TypeChecker.java: check aref base expr and index expr.
* net/loveruby/cflat/ast/Node.java: new method #isIndexable.
* net/loveruby/cflat/type/Type.java: new method #isIndexable.
* net/loveruby/cflat/type/ArrayType.java: override it.
* net/loveruby/cflat/type/PointerType.java: ditto.
* test/test.sh: test aref and funcall semantic check.
* test/aref-semcheck.cb: check if 1[0] causes error.
* test/funcall-semcheck2.cb: check if 1() causes error.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3765 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 15:38:50 +00:00
Minero Aoki 3356d1fff4 * net/loveruby/cflat/parser/Parser.jj: 5-1-1 should be 3, not 5.
* test/test.sh: test op association.
* test/assoc.cb: new test case.
* test/Makefile: build it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3758 1b9489fe-b721-0410-924e-b54b9192deb8
2007-12-25 17:46:37 +00:00
Minero Aoki dd209e191b import cbc from stdcompiler repository (rev185)
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3753 1b9489fe-b721-0410-924e-b54b9192deb8
2007-12-24 08:19:51 +00:00