Mercurial > projects > dang
changeset 50:e24515bcd4ef new_gen
Removed unused LuaGen
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sat, 26 Apr 2008 15:31:20 +0200 |
parents | c7cde6af0095 |
children | c96cdcbdb9d6 |
files | dang/compiler.d gen/LuaGen.d |
diffstat | 2 files changed, 0 insertions(+), 190 deletions(-) [+] |
line wrap: on
line diff
--- a/dang/compiler.d Sat Apr 26 13:15:37 2008 +0200 +++ b/dang/compiler.d Sat Apr 26 15:31:20 2008 +0200 @@ -104,16 +104,6 @@ ).help("Output the AST as dot-graphicz"); argParse.addOption( - ["--gen-lua"], { - postParse.attach( - (Decl[] decls, DataSource src) { - auto luaGen = new LuaGen(); - luaGen.gen(decls); - }); - } - ).help("Compile to Lua code"); - - argParse.addOption( ["--gen-llvm"], { /* postParse.attach( (Decl[] decls, DataSource src) {
--- a/gen/LuaGen.d Sat Apr 26 13:15:37 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,180 +0,0 @@ -module gen.LuaGen; - -import tango.io.Stdout, - Int = tango.text.convert.Integer; - -import ast.Decl, - ast.Stmt, - ast.Exp; - -import lexer.Token; - -class LuaGen -{ -public: - this() - { - } - - void gen(Decl[] decls) - { - - foreach(decl ; decls) - genDecl(decl); - printBeginLine("main()"); - printEndLine; - } - - void genDecl(Decl decl) - { - switch(decl.declType) - { - case DeclType.FuncDecl: - FuncDecl funcDecl = cast(FuncDecl)decl; - - printBeginLine("function "); - genIdentifier(funcDecl.identifier); - print("("); - foreach(i, funcArg ; funcDecl.funcArgs) - { - genIdentifier(funcArg.identifier); - if(i+1 < funcDecl.funcArgs.length) - print(", "); - } - printEndLine(")"); - indent; - foreach(stmt ; funcDecl.statements) - { - genStmt(stmt); - } - dedent; - printBeginLine("end"); - printEndLine(); - break; - - case DeclType.VarDecl: - genVarDecl(cast(VarDecl)decl); - - default: - } - } - - void genStmt(Stmt stmt) - { - switch(stmt.stmtType) - { - case StmtType.Return: - auto ret = cast(ReturnStmt)stmt; - printBeginLine("return "); - genExpression(ret.exp); - printEndLine(); - break; - case StmtType.Decl: - auto declStmt = cast(DeclStmt)stmt; - genDecl(declStmt.decl); - break; - case StmtType.Exp: - auto expStmt = cast(ExpStmt)stmt; - printBeginLine(); - genExpression(expStmt.exp); - printEndLine(); - break; - - } - } - - void genVarDecl(VarDecl decl) - { - printBeginLine("local "); - genIdentifier(decl.identifier); - if(decl.init) - { - print(" = "); - genExpression(decl.init); - } - printEndLine(); - - } - - void genExpression(Exp exp) - { - switch(exp.expType) - { - case ExpType.Binary: - auto binaryExp = cast(BinaryExp)exp; - genExpression(binaryExp.left); - print(" " ~ [binaryExp.op] ~ " "); - genExpression(binaryExp.right); - break; - case ExpType.IntegerLit: - auto integetLit = cast(IntegerLit)exp; - auto t = integetLit.token; - print(t.get); - break; - case ExpType.Negate: - auto negateExp = cast(NegateExp)exp; - print("-("); - genExpression(negateExp.exp); - print(")"); - break; - case ExpType.AssignExp: - auto assignExp = cast(AssignExp)exp; - genExpression(assignExp.identifier); - print(" = "); - genExpression(assignExp.exp); - break; - case ExpType.CallExp: - auto callExp = cast(CallExp)exp; - genExpression(callExp.exp); - print("("); - foreach(i, arg ; callExp.args) - { - genExpression(arg); - if(i+1 < callExp.args.length) - print(", "); - } - print(")"); - break; - case ExpType.Identifier: - auto identifier = cast(Identifier)exp; - print(identifier.token.get); - break; - } - - } - - void genIdentifier(Identifier identifier) - { - print(identifier.token.get); - } - - void indent() - { - tabIndex ~= tabType; - } - - void dedent() - { - tabIndex = tabIndex[0 .. $-tabType.length]; - } - - void printBeginLine(char[] line = "") - { - Stdout(tabIndex~line); - } - - void printEndLine(char[] line = "") - { - Stdout(line).newline; - } - - void print(char[] line) - { - Stdout(line); - } - -private: - char[] tabIndex; - const char[] tabType = " "; // 4 spaces -} -