private CompilerContext IntLiteral(CompilerContext context) { context.AsFluent() .Mov.RU(Register.A, uint.Parse(context.Node.ToString())); return(context); }
private CompilerContext UnaryOperator(CompilerContext context) { switch (context.Node.Value) { case "!": context.AsFluent() .Not.RR(Register.A, Register.A); break; case "-": context.AsFluent() .Neg.RR(Register.A, Register.A); break; default: throw new InvalidOperationException("Cannot determine unary operator: " + context.Node.Value); } return(context); }
private CompilerContext Identifier(CompilerContext context) { var name = context.Node.Value; var symbol = context.SymbolTable[name]; context.AsFluent() .Mov.RU(Register.A, symbol.Address) .Add.RR(Register.A, Register.H) .Mov.RM(Register.A, MemoryAddress.A); return(context); }
private CompilerContext AssignmentExpression(CompilerContext context) { var identifier = context.Node[0]; foreach (var right in context.Node[1]) { context.Compile(right[1]); } var name = identifier.Value; var symbol = context.SymbolTable[name]; context.AsFluent() .Mov.RU(Register.B, symbol.Address, $"Load variable {name} into rB") .Add.RR(Register.B, Register.H) .Mov.MR(MemoryAddress.B, Register.A); return(context); }
public IEnumerable<Instruction> Compile() { var context = new CompilerContext { Code = new CodeStream(), Compiler = Compile, Node = _root, Parent = null, SymbolTable = new SymbolTable(), }; foreach ( var node in context.Node ) context.Compile(node); context.AsFluent() .Exit.R(Register.A); return context.Code; }
public IEnumerable <Instruction> Compile() { var context = new CompilerContext { Code = new CodeStream(), Compiler = Compile, Node = _root, Parent = null, SymbolTable = new SymbolTable(), }; foreach (var node in context.Node) { context.Compile(node); } context.AsFluent() .Exit.R(Register.A); return(context.Code); }
private static CompilerContext CompileExpression(CompilerContext context, params Tuple <string, Action <FluentWriter>, OpCode>[] codeWriters) { context.Compile(context.Node[0]); var code = context.AsFluent(); var expressions = codeWriters.ToDictionary(k => k.Item1, v => new { writer = v.Item2, jumpCode = v.Item3 }); foreach (var right in context.Node[1]) { code.Push.R(Register.A); var @operator = right[0]; context.Compile(right[1]); code.Pop.R(Register.B); var expr = expressions[@operator.Value]; expr.writer(code); context.JumpExpression = expr.jumpCode; } return(context); }
private static CompilerContext CompileExpression(CompilerContext context, params Tuple<string, Action<FluentWriter>, OpCode>[] codeWriters) { context.Compile(context.Node[0]); var code = context.AsFluent(); var expressions = codeWriters.ToDictionary(k => k.Item1, v => new { writer = v.Item2, jumpCode = v.Item3 }); foreach (var right in context.Node[1]) { code.Push.R(Register.A); var @operator = right[0]; context.Compile(right[1]); code.Pop.R(Register.B); var expr = expressions[@operator.Value]; expr.writer(code); context.JumpExpression = expr.jumpCode; } return context; }
private CompilerContext UnaryOperator(CompilerContext context) { switch ( context.Node.Value ) { case "!": context.AsFluent() .Not.RR(Register.A, Register.A); break; case "-": context.AsFluent() .Neg.RR(Register.A, Register.A); break; default: throw new InvalidOperationException("Cannot determine unary operator: " + context.Node.Value ); } return context; }
private CompilerContext IntLiteral(CompilerContext context) { context.AsFluent() .Mov.RU(Register.A, uint.Parse(context.Node.ToString())); return context; }
private CompilerContext Identifier(CompilerContext context) { var name = context.Node.Value; var symbol = context.SymbolTable[name]; context.AsFluent() .Mov.RU(Register.A, symbol.Address) .Add.RR(Register.A, Register.H) .Mov.RM(Register.A, MemoryAddress.A); return context; }
private CompilerContext AssignmentExpression(CompilerContext context) { var identifier = context.Node[0]; foreach (var right in context.Node[1]) { context.Compile(right[1]); } var name = identifier.Value; var symbol = context.SymbolTable[name]; context.AsFluent() .Mov.RU(Register.B, symbol.Address, $"Load variable {name} into rB") .Add.RR(Register.B, Register.H) .Mov.MR(MemoryAddress.B, Register.A); return context; }