mirror of https://github.com/nocturn9x/nimkalc.git
Bugfixes
This commit is contained in:
parent
e225d77e0d
commit
e92e40b6ea
|
@ -169,6 +169,7 @@ proc visit_call(self: NodeVisitor, node: AstNode): AstNode =
|
||||||
of "tan":
|
of "tan":
|
||||||
callFunction(tan, self.eval(node.arguments[0]).value)
|
callFunction(tan, self.eval(node.arguments[0]).value)
|
||||||
of "sqrt":
|
of "sqrt":
|
||||||
|
let arg = self.eval(node.arguments[0])
|
||||||
ensurePositive(arg)
|
ensurePositive(arg)
|
||||||
callFunction(sqrt, self.eval(node.arguments[0]).value)
|
callFunction(sqrt, self.eval(node.arguments[0]).value)
|
||||||
of "log":
|
of "log":
|
||||||
|
@ -257,6 +258,12 @@ proc visit_unary(self: NodeVisitor, node: AstNode): AstNode =
|
||||||
else:
|
else:
|
||||||
discard # Unreachable
|
discard # Unreachable
|
||||||
of TokenType.Plus:
|
of TokenType.Plus:
|
||||||
result = node # Unary + does nothing
|
case expr.kind:
|
||||||
|
of NodeKind.Float:
|
||||||
|
result = AstNode(kind: NodeKind.Float, value: expr.value)
|
||||||
|
of NodeKind.Integer:
|
||||||
|
result = AstNode(kind: NodeKind.Integer, value: expr.value)
|
||||||
|
else:
|
||||||
|
discard # Unreachable
|
||||||
else:
|
else:
|
||||||
discard # Unreachable
|
discard # Unreachable
|
||||||
|
|
|
@ -174,7 +174,7 @@ proc call(self: Parser): AstNode =
|
||||||
proc unary(self: Parser): AstNode =
|
proc unary(self: Parser): AstNode =
|
||||||
## Parses unary expressions such as -1
|
## Parses unary expressions such as -1
|
||||||
case self.step().kind:
|
case self.step().kind:
|
||||||
of TokenType.Minus:
|
of TokenType.Minus, TokenType.Plus:
|
||||||
result = AstNode(kind: NodeKind.Unary, unOp: self.previous(), operand: self.unary())
|
result = AstNode(kind: NodeKind.Unary, unOp: self.previous(), operand: self.unary())
|
||||||
else:
|
else:
|
||||||
result = self.call()
|
result = self.call()
|
||||||
|
|
Loading…
Reference in New Issue