func compileComparison(ctx *context, n *node.BinaryNode) { compileBinaryOperands(ctx, n) switch n.Type() { case node.Equals: ctx.AppendOp(vm.TXOPEquals) case node.NotEquals: ctx.AppendOp(vm.TXOPNotEquals) case node.LT: ctx.AppendOp(vm.TXOPLessThan) case node.GT: ctx.AppendOp(vm.TXOPGreaterThan) default: panic("Unknown operator") } }
func compileBinaryArithmetic(ctx *context, n *node.BinaryNode) { var optype vm.OpType switch n.Type() { case node.Plus: optype = vm.TXOPAdd case node.Minus: optype = vm.TXOPSub case node.Mul: optype = vm.TXOPMul case node.Div: optype = vm.TXOPDiv default: panic("Unknown arithmetic") } ctx.AppendOp(vm.TXOPNoop).SetComment("BEGIN " + optype.String()) compileBinaryOperands(ctx, n) ctx.AppendOp(optype).SetComment("Execute " + optype.String() + " on registers sa and sb") }