Skip to content

Commit

Permalink
Compiler updates... coming along slowly though...
Browse files Browse the repository at this point in the history
  • Loading branch information
efrederickson committed Dec 3, 2012
1 parent b5c0be0 commit dcff8df
Show file tree
Hide file tree
Showing 5 changed files with 460 additions and 36 deletions.
4 changes: 4 additions & 0 deletions SharpLua.NewCompilerTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
using System;
using System.IO;
using System.Text;
using SharpLua.Ast;
using SharpLua.LASM;

Expand All @@ -30,7 +31,10 @@ public static void Main(string[] args)
Console.WriteLine("compiled!");
FileStream fs = File.Open("out.sluac", FileMode.Create);
foreach (char ch in proto.Compile())
{
//Console.WriteLine(ch + " " + (int)ch);
fs.WriteByte((byte)ch);
}
fs.Close();
Console.WriteLine("written to out.sluac!");
}
Expand Down
11 changes: 11 additions & 0 deletions SharpLua/NewParser/Ast/BinaryOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ public enum BinaryOperator

NONE = -1,
}

public enum UnaryOperator
{
Not, // !, not
Length, // #
BitNot, // ~
Negate, // -
UnNegate, // +

NONE = -1,
}
}
16 changes: 16 additions & 0 deletions SharpLua/NewParser/Ast/Expression/UnOpExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@ public class UnOpExpr : Expression
{
public Expression Rhs = null;
public string Op = "";

public UnaryOperator GetOperator()
{
if (Op == "!" || Op == "not")
return UnaryOperator.Not;
else if (Op == "#")
return UnaryOperator.Length;
else if (Op == "~")
return UnaryOperator.BitNot;
else if (Op == "-")
return UnaryOperator.Negate;
else if (Op == "+")
return UnaryOperator.UnNegate;
else
return UnaryOperator.NONE;
}
}
}
7 changes: 5 additions & 2 deletions SharpLua/NewParser/Compiler/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ public Block()
}

public Block(Block parent)
: this()
{
parent.PreviousBlock = this;
K = new K2Reg(this);
//parent.PreviousBlock = this;
this.PreviousBlock = parent;
V = new Var2Reg(parent.V);
Chunk = parent.Chunk;
}

public int regnum = 0;
public int getreg()
{
//Console.WriteLine(regnum);
return
/*++*/
regnum
Expand Down
Loading

0 comments on commit dcff8df

Please sign in to comment.