Compare commits

..

7 Commits

Author SHA1 Message Date
007cf34c56 Making use of the baller ass new highlighting style 2022-11-29 03:08:28 -05:00
080b5ffd43 Upgrade to stone v0.2.1 2022-11-25 17:58:27 -05:00
7eb2b5ea2f Removed the weird way to create negatives
You can just press s it's fine
2022-11-25 17:51:24 -05:00
cc7d516dbd Upgrade to stone v0.2.0 2022-11-24 22:21:28 -05:00
c64cda0870 Bitwise operations on floats actually arent useful 2022-11-23 22:24:45 -05:00
afe0ed33ca Swap precision of individual operations 2022-11-23 21:42:55 -05:00
2f2c381d71 Added "encompass" key 2022-11-23 21:33:37 -05:00
7 changed files with 57 additions and 104 deletions

View File

@@ -183,7 +183,6 @@ func (operation *Operation) solution () (solution int64, err error) {
func (operation *Operation) inexactSolution () (solution float64, err error) {
var subSolution float64
var rawSolution uint64
switch operation.opcode {
case OpcodeAdd:
@@ -194,13 +193,6 @@ func (operation *Operation) inexactSolution () (solution float64, err error) {
}
case OpcodeSubtract:
if len(operation.operands) == 1 {
solution, err = operation.operands[0].InexactSolution()
solution *= -1
if err != nil { return }
break
}
for index, operand := range operation.operands {
subSolution, err = operand.InexactSolution()
if err != nil { return }
@@ -271,88 +263,10 @@ func (operation *Operation) inexactSolution () (solution float64, err error) {
}
}
case OpcodeOr:
for _, operand := range operation.operands {
subSolution, err = operand.InexactSolution()
if err != nil { return }
rawSolution |= math.Float64bits(subSolution)
}
solution = math.Float64frombits(rawSolution)
case OpcodeNot:
if len(operation.operands) != 1 {
err = ErrorWrongOperandCount
return
}
subSolution, err = operation.operands[0].InexactSolution()
solution = math.Float64frombits(^math.Float64bits(subSolution))
case OpcodeAnd:
for index, operand := range operation.operands {
subSolution, err = operand.InexactSolution()
if err != nil { return }
if index == 0 {
rawSolution = math.Float64bits(subSolution)
} else {
rawSolution &= math.Float64bits(subSolution)
}
}
solution = math.Float64frombits(rawSolution)
case OpcodeXor:
for index, operand := range operation.operands {
subSolution, err = operand.InexactSolution()
if err != nil { return }
if index == 0 {
rawSolution = math.Float64bits(subSolution)
} else {
rawSolution ^= math.Float64bits(subSolution)
}
}
solution = math.Float64frombits(rawSolution)
case OpcodeLeftShift:
if len(operation.operands) != 2 {
err = ErrorWrongOperandCount
return
}
var left, right float64
left, err = operation.operands[0].InexactSolution()
if err != nil { return }
right, err = operation.operands[1].InexactSolution()
if err != nil { return }
if right < 0 {
err = ErrorNegativeShiftAmount
return
}
solution = math.Float64frombits (
math.Float64bits(left) <<
math.Float64bits(right))
case OpcodeRightShift:
if len(operation.operands) != 2 {
err = ErrorWrongOperandCount
return
}
var left, right float64
left, err = operation.operands[0].InexactSolution()
if err != nil { return }
right, err = operation.operands[1].InexactSolution()
if err != nil { return }
if right < 0 {
err = ErrorNegativeShiftAmount
return
}
solution = math.Float64frombits (
math.Float64bits(left) >>
math.Float64bits(right))
case
OpcodeOr, OpcodeNot, OpcodeAnd, OpcodeXor, OpcodeLeftShift,
OpcodeRightShift:
err = ErrorWrongType
case OpcodeMean:
if len(operation.operands) == 0 { break }

View File

@@ -60,8 +60,10 @@ func drawInput () {
if character == '_' {
application.SetColor(x + xOffset, y, stone.ColorDim)
application.SetStyle(x + xOffset, y, stone.StyleNormal)
} else {
application.SetColor(x + xOffset, y, cell.Color())
application.SetStyle(x + xOffset, y, cell.Style())
}
}
}

2
go.mod
View File

@@ -2,7 +2,7 @@ module git.tebibyte.media/sashakoshka/mathpan
go 1.19
require git.tebibyte.media/sashakoshka/stone v0.0.0-20221124013405-5a76bd0c223d
require git.tebibyte.media/sashakoshka/stone v0.5.1
require (
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect

4
go.sum
View File

@@ -1,5 +1,5 @@
git.tebibyte.media/sashakoshka/stone v0.0.0-20221124013405-5a76bd0c223d h1:2uDDq+lHbhODq+6hmosmCcAaLOg55a7LOIhiJMzeSds=
git.tebibyte.media/sashakoshka/stone v0.0.0-20221124013405-5a76bd0c223d/go.mod h1:ISnqmX6xvItOot3eW3YWLcNFeJrGpKetQGQniAjnU2A=
git.tebibyte.media/sashakoshka/stone v0.5.1 h1:QQo1lccq6bMebXRKlbAoFBKSDbVwvSkXriKHMGvfAkk=
git.tebibyte.media/sashakoshka/stone v0.5.1/go.mod h1:ISnqmX6xvItOot3eW3YWLcNFeJrGpKetQGQniAjnU2A=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJXZHsaM8b6OLVo6muQUQd4CwkH/D3fnnbHXA=
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=

Binary file not shown.

41
main.go
View File

@@ -83,12 +83,17 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
}, modifiers.Alt, false, false)
redraw()
application.Draw()
case '\\':
insertOperation('?', false, true)
redraw()
application.Draw()
case
'+', '-', '*', '/', 'p', 'P', '%', '|', '~', '&', '^', 'm',
'l', 'r':
insertOperation(rune(button), modifiers.Alt)
insertOperation(rune(button), modifiers.Alt, false)
redraw()
application.Draw()
@@ -237,6 +242,15 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
redraw()
application.Draw()
case 'z':
switch selectedExpression.(type) {
case *Operation:
operation := selectedExpression.(*Operation)
operation.floating = !operation.floating
}
redraw()
application.Draw()
case 'Z':
showFloat = !showFloat
redraw()
@@ -244,9 +258,10 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
}
}
func insertOperation (symbol rune, swap bool) {
func insertOperation (symbol rune, swap, encompass bool) {
var opcode Opcode
switch (symbol) {
case '?': opcode = OpcodeUnknown
case '+': opcode = OpcodeAdd
case '-': opcode = OpcodeSubtract
case '*': opcode = OpcodeMultiply
@@ -263,6 +278,23 @@ func insertOperation (symbol rune, swap bool) {
case 'm': opcode = OpcodeMean
}
newExpression := Operation { opcode: opcode, floating: showFloat }
if encompass {
if selectedExpression == nil { return }
parent := selectedExpression.Parent()
newExpression.Adopt(selectedExpression)
if parent == nil {
expressionRoot = &newExpression
} else {
parent.Swap(selectedExpression, &newExpression)
}
selectedExpression = &newExpression
return
}
operation, isOperation := selectedExpression.(*Operation)
if isOperation {
if operation.opcode == OpcodeUnknown || swap {
@@ -270,9 +302,8 @@ func insertOperation (symbol rune, swap bool) {
return
}
}
newExpression := &Operation { opcode: opcode, floating: showFloat }
insertGeneric(newExpression, swap, false, true)
insertGeneric(&newExpression, swap, false, true)
}
func insertNumber (value int64, swap, before bool) {

18
tree.go
View File

@@ -232,19 +232,22 @@ func (operation *Operation) Render (target stone.Buffer, offset int) (moved int)
}
if selectedExpression == operation {
target.SetColor(offset, 0, stone.ColorBlue)
target.SetColor(offset, 0, stone.ColorYellow)
target.SetStyle(offset, 0, stone.StyleHighlight)
} else {
target.SetColor(offset, 0, stone.ColorDim)
target.SetStyle(offset, 0, stone.StyleNormal)
}
moved ++
opcodeSymbol := operation.opcode.String()
for _, character := range opcodeSymbol {
target.SetRune(offset + moved, 0, character)
target.SetColor(offset + moved, 0, stone.ColorYellow)
if selectedExpression == operation {
target.SetColor(offset + moved, 0, stone.ColorBlue)
target.SetStyle(offset + moved, 0, stone.StyleHighlight)
} else {
target.SetColor(offset + moved, 0, stone.ColorYellow)
target.SetStyle(offset + moved, 0, stone.StyleNormal)
}
moved ++
}
@@ -262,9 +265,11 @@ func (operation *Operation) Render (target stone.Buffer, offset int) (moved int)
}
if selectedExpression == operation {
target.SetColor(offset + moved, 0, stone.ColorBlue)
target.SetColor(offset + moved, 0, stone.ColorYellow)
target.SetStyle(offset + moved, 0, stone.StyleHighlight)
} else {
target.SetColor(offset + moved, 0, stone.ColorDim)
target.SetStyle(offset + moved, 0, stone.StyleNormal)
}
moved ++
return
@@ -362,10 +367,11 @@ func (literal *IntegerLiteral) Render (target stone.Buffer, offset int) (moved i
for _, character := range output {
target.SetRune(offset + moved, 0, character)
target.SetColor(offset + moved, 0, stone.ColorPurple)
if selectedExpression == literal {
target.SetColor(offset + moved, 0, stone.ColorBlue)
target.SetStyle(offset + moved, 0, stone.StyleHighlight)
} else {
target.SetColor(offset + moved, 0, stone.ColorPurple)
target.SetStyle(offset + moved, 0, stone.StyleNormal)
}
moved ++
}