Commit Graph

246 Commits

Author SHA1 Message Date
Minero Aoki 7ffccfb969 * net/loveruby/cflat/compiler/LocalReferenceResolver.java (pushScope): forgot to remove useless line.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3889 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-10 19:29:03 +00:00
Minero Aoki 6895ce1d67 * net/loveruby/cflat/ast/LocalScope.java: new subclass of Scope.
* net/loveruby/cflat/ast/Scope.java: move local scope only methods to LocalScope class.
* net/loveruby/cflat/ast/ToplevelScope.java: local scope only methods are moved to LocalScope, do not need to disable #variables, #allVariables, ...
* net/loveruby/cflat/ast/Frame.java: is useless, removed.
* net/loveruby/cflat/ast/DefinedFunction.java: Frame -> LocalScope.
* net/loveruby/cflat/ast/BlockNode.java: Scope -> LocalScope.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: Frame removed.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: Scope -> LocalScope.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java (pushScope): check duplicated local variables.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3888 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-10 19:26:07 +00:00
Minero Aoki 209116f66a * net/loveruby/cflat/ast/Scope.java: use LinkedHashMap to unify entities and entitiesMap (entities should be ordered).
* net/loveruby/cflat/ast/Frame.java: ditto.
* net/loveruby/cflat/ast/ToplevelScope.java: ditto.
* net/loveruby/cflat/ast/Scope.java: remove unused method #entities.  Use #variables instead.
* net/loveruby/cflat/ast/Frame.java: ditto.
* net/loveruby/cflat/ast/ConstantTable.java: use 
* net/loveruby/cflat/compiler/TypeResolver.java: remove useless code.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3887 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-10 18:59:21 +00:00
Minero Aoki 8c885a42bd * net/loveruby/cflat/ast/Scope.java: ban all allocate* methods, privateEntitiesMap. Use #declareEntity instead.
* net/loveruby/cflat/ast/Frame.java: ditto.
* net/loveruby/cflat/ast/ToplevelScope.java: ditto.
* net/loveruby/cflat/ast/ToplevelScope.java (commonSymbols, globalVariables): static local variables are now in each Scopes, collect static local variables from them by myself.
* net/loveruby/cflat/ast/Entity.java: #defineIn removed.
* net/loveruby/cflat/ast/Variable.java: #defineIn removed.
* net/loveruby/cflat/ast/DefinedVariable.java: #defineIn removed.
* net/loveruby/cflat/ast/UndefinedVariable.java: #defineIn removed.
* net/loveruby/cflat/ast/DefinedFunction.java: #defineIn removed.
* net/loveruby/cflat/ast/UndefinedFunction.java: #defineIn removed.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: follow these changes.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3886 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-10 18:13:29 +00:00
Minero Aoki 1ac456d72e * net/loveruby/cflat/compiler/LocalReferenceResolver.java: add preproc tag.
* net/loveruby/cflat/ast/Scope.java: ditto.
* net/loveruby/cflat/ast/ToplevelScope.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3885 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-10 15:17:30 +00:00
Minero Aoki 0af37dc9cf * net/loveruby/cflat/asm/Reference.java: new constructor Reference(String) for instance.
* net/loveruby/cflat/ast/AST.java: #declarations should include vardecls.
* net/loveruby/cflat/ast/UndefinedVariable.java: #address should return variable symbol.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: declarations may include variable declaration.
* test/vardecl.cb: test reference of declared external variable.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3884 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-10 13:33:19 +00:00
Minero Aoki 23ada77110 * net/loveruby/cflat/compiler/JumpResolver.java: remove currentBreakTarget and currentContinueTarget to simplify.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3872 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-07 19:59:40 +00:00
Minero Aoki 5e8902cc51 * net/loveruby/cflat/compiler/JumpResolver.java (currentBreakTarget, currentContinueTarget): does not throw exception.
* net/loveruby/cflat/compiler/JumpResolver.java: add preproc tags.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3871 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-07 19:46:21 +00:00
Minero Aoki cd77f10e64 * build.xml: unify task: jar and compile.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3866 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-03 09:37:24 +00:00
Minero Aoki f50dfa8add * net/loveruby/cflat/compiler/Compiler.java (dumpTokenList): specialToken handling was wrong. We should trace t.specialToken while it becomes null, then follow t.next.
* net/loveruby/cflat/parser/Parser.jj: write token name for special tokens.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3864 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-03 09:30:23 +00:00
Minero Aoki 63af21eaf4 * net/loveruby/cflat/compiler/Compiler.java: new command line option -v (show arguments of external command invocation).
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3857 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 20:38:06 +00:00
Minero Aoki d04a86cce8 * net/loveruby/cflat/compiler/Compiler.java: new command line option -S (generate assembly source and quit).
* net/loveruby/cflat/compiler/Compiler.java: new command line option -c (assemble and quit).
* net/loveruby/cflat/compiler/Compiler.java: call GNU as and GNU ld directly, instead of gcc.
* net/loveruby/cflat/compiler/Compiler.java (commandMain): refactoring: extract method: parseOptions.
* net/loveruby/cflat/compiler/Compiler.java: refactoring: introduce new class Options and hold all command options in it.
* net/loveruby/cflat/compiler/Compiler.java: refactoring: #compileFile do all tasks by referencing an Options.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3856 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 20:28:53 +00:00
Minero Aoki 564d0fe2d1 * net/loveruby/cflat/compiler/LibraryLoader.java: should reject recursive import.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3855 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 20:24:58 +00:00
Minero Aoki bde2429d8d * net/loveruby/cflat/parser/Parser.jj: produce Error for UnknownEncodingError. Current Java runtime must know UTF-8 encoding.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3854 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 17:51:06 +00:00
Minero Aoki 067629484c * net/loveruby/cflat/parser/Parser.jj: refactoring: reorder member decl.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3853 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 16:58:59 +00:00
Minero Aoki 4a50b276ba * net/loveruby/cflat/parser/Parser.jj: modify preproc tag.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3852 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 16:39:26 +00:00
Minero Aoki d2e6a12902 * net/loveruby/cflat/parser/Parser.jj: change symbol name to fix compile error.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3851 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 16:24:25 +00:00
Minero Aoki 13a10588e7 * net/loveruby/cflat/parser/Parser.jj: refactoring: rename rule: defvars -> defvar.
* net/loveruby/cflat/parser/Parser.jj: refactoring: extract new symbol defvar_list from block.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3850 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 16:22:10 +00:00
Minero Aoki 5c5e0c8781 * net/loveruby/cflat/ast/Declarations.java: refactoring: new method #addDefvars.
* net/loveruby/cflat/parser/Parser.jj: use it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3849 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 16:19:13 +00:00
Minero Aoki 2d2dac92e5 * net/loveruby/cflat/ast/Parameter.java: simplify dump output.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3848 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-20 15:42:54 +00:00
Minero Aoki 9acd26377c * net/loveruby/cflat/parser/Parser.jj: refactoring: rename lvar.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3846 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-18 22:22:32 +00:00
Minero Aoki 339365c677 * net/loveruby/cflat/parser/Parser.jj: should generate special token for block comment, instead of just skipping.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3845 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 17:34:02 +00:00
Minero Aoki 7760b11d55 * net/loveruby/cflat/parser/Parser.jj: LOOKAHEAD is useless here.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3844 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 17:31:17 +00:00
Minero Aoki efa91bbf9f * build.xml: read user defined property file from $HOME.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3841 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 16:05:00 +00:00
Minero Aoki aaa75d0e75 * build.xml: now default task is "jar" instead of "compile".
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3840 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 15:51:43 +00:00
Minero Aoki ad7f9d35f2 * build.xml (recompile): build jar file.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3839 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 15:48:49 +00:00
Minero Aoki 2bb1639165 * build.xml: new task test.
* build.xml: new task comptest.
* test/Makefile: new task compile.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3835 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 15:30:45 +00:00
Minero Aoki cae2548643 * test/test.sh: should be executable from any directory.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3834 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 15:21:40 +00:00
Minero Aoki dd1b1dbd05 * cbc: $basedir should be relative to cbc command.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3833 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 15:16:24 +00:00
Minero Aoki d598c2fef9 * test/cbc -> ./cbc
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3832 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 15:13:09 +00:00
Minero Aoki a20c3d4542 * build.xml: new task recompile.
* build.xml: new task jar.
* build.xml: new task clean-build.
* build.xml: new task dist.
* build.properties: remove unused JJT properties.
* test/cbc: use jar file.
* test/Makefile


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3831 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-14 15:09:51 +00:00
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 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 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 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 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
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 9a7f3015b5 * net/loveruby/cflat/parser/Parser.jj: pass BlockNode to DefinedFunction.
* net/loveruby/cflat/ast/DefinedFunction.java: #body is a BlockNode, not Node.
* net/loveruby/cflat/ast/BlockNode.java: new method #tailStmt.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3774 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-02 12:46:47 +00:00
Minero Aoki e3282566a4 * introduce ExprNode class for all expression nodes.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3773 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-02 11:53:41 +00:00
Minero Aoki 16a2210512 * net/loveruby/cflat/compiler/TypeChecker.java: check &expr is assignable.
* net/loveruby/cflat/ast/Node.java: new generic method #isAssignable.
* net/loveruby/cflat/ast/VariableNode.java: is assignable.
* net/loveruby/cflat/ast/DereferenceNode.java: is assignable.
* net/loveruby/cflat/ast/ArefNode.java: is assignable.
* net/loveruby/cflat/ast/MemberNode.java: is assignable.
* net/loveruby/cflat/ast/PtrMemberNode.java: is assignable.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3772 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-02 10:46:28 +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 46109b45b1 * net/loveruby/cflat/compiler/TypeChecker.java: allow ptr + int, ptr - int.
* net/loveruby/cflat/ast/BinaryOpNode.java: new method #setType.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3770 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 19:03:14 +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 a0c7198db9 * net/loveruby/cflat/parser/Parser.jj: composite literal removed.
* net/loveruby/cflat/ast/CompositeLiteralNode.java: removed.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3768 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 18:00:25 +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 6e3734fcc0 * net/loveruby/cflat/compiler/TypeChecker.java: check function arguments.
* net/loveruby/cflat/ast/FuncallNode.java: rename method: #args -> #argument.
* net/loveruby/cflat/compiler/Visitor.java: ditto.
* net/loveruby/cflat/ast/Params.java: new method #argc, #minArgc.
* net/loveruby/cflat/ast/FixedParams.java: ditto.
* net/loveruby/cflat/ast/VarParams.java: ditto.
* net/loveruby/cflat/ast/Node.java: new method #isCallable.
* net/loveruby/cflat/type/FunctionType.java: new method #acceptsArgc.
* net/loveruby/cflat/type/FunctionType.java: new method #paramTypes.
* net/loveruby/cflat/type/Type.java: new method #isCallable.
* net/loveruby/cflat/type/PointerType.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3764 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 15:22:54 +00:00
Minero Aoki 1e4ac4dabf * net/loveruby/cflat/compiler/Compiler.java: create TypeTable here.
* net/loveruby/cflat/compiler/CodeGenerator.java: accepts TypeTable and ErrorHandler.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: set type of AddressNode.
* net/loveruby/cflat/compiler/TypeChecker.java: warn incompatible cast.
* net/loveruby/cflat/compiler/ErrorHandler.java: modify message (error -> warning).
* net/loveruby/cflat/parser/Parser.jj: rename variable: handler -> errorHandler.
* net/loveruby/cflat/ast/AST.java: do not contain TypeTable.
* net/loveruby/cflat/ast/ComplexTypeDefinition.java: new method #type.
* net/loveruby/cflat/ast/StructNode.java: ditto.
* net/loveruby/cflat/ast/UnionNode.java: ditto.
* net/loveruby/cflat/ast/AddressNode.java: receive Type from TypeChcker.
* net/loveruby/cflat/type/TypeTable.java: new method #pointerTo.
* net/loveruby/cflat/type/IntegerType.java (isCompatible): check if self is compatible with other side (be able to cast to other implicitly).
* net/loveruby/cflat/type/IntegerType.java (isCastableTo): allow explicit cast if type of type is same (integer/pointer).
* net/loveruby/cflat/type/PointerType.java: implement #equals.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3763 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 14:21:26 +00:00
Minero Aoki 5fc167d2e5 * net/loveruby/cflat/compiler/Compiler.java: invoke TypeChecker.
* net/loveruby/cflat/compiler/TypeChecker.java: check type (incomplete).
* net/loveruby/cflat/type/Type.java: new method #isCompatible, #isCastableTo.
* net/loveruby/cflat/type/IntegerType.java: override them.
* net/loveruby/cflat/type/UnsignedCharType.java: change textize result.
* net/loveruby/cflat/type/UnsignedLongType.java: ditto.
* net/loveruby/cflat/type/UnsignedIntType.java: ditto.
* net/loveruby/cflat/type/UnsignedShortType.java: ditto.
* net/loveruby/cflat/ast/AbstractAssignNode.java: new method #setRHS.
* net/loveruby/cflat/ast/AssignNode.java: is now an AbstractAssignNode.
* net/loveruby/cflat/ast/BinaryOpNode.java: new methods #setLeft, #setRight.
* net/loveruby/cflat/ast/FuncallNode.java (type): does not rely on #function (can get type of non-static function).
* net/loveruby/cflat/ast/CondExprNode.java: new methods #setThenBody, #setElseBody.
* net/loveruby/cflat/ast/TypeNode.java: new constructor by Type.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3762 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-01 12:56:25 +00:00
Minero Aoki 6dc898dbd3 * net/loveruby/cflat/parser/Parser.jj (expr10): then expr is expr().
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3759 1b9489fe-b721-0410-924e-b54b9192deb8
2007-12-25 21:12:31 +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 67a9866b59 * net/loveruby/cflat/parser/Parser.jj (fixedparams, fixedparam_typerefs, args): simplify lookahead.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3757 1b9489fe-b721-0410-924e-b54b9192deb8
2007-12-24 20:53:23 +00:00
Minero Aoki bda63ace95 * net/loveruby/cflat/parser/Parser.jj: expr0 -> expr1, expr1 -> expr2, ...
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3756 1b9489fe-b721-0410-924e-b54b9192deb8
2007-12-24 17:09:37 +00:00
Minero Aoki b8936df200 set svn:ignore again
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3755 1b9489fe-b721-0410-924e-b54b9192deb8
2007-12-24 09:05:01 +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