Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
75a35b4b
Commit
75a35b4b
authored
Dec 29, 2016
by
Dylan Trotter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement unary negation slot.
parent
93461c68
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
0 deletions
+12
-0
compiler/expr_visitor.py
compiler/expr_visitor.py
+1
-0
runtime/core.go
runtime/core.go
+10
-0
runtime/slots.go
runtime/slots.go
+1
-0
No files found.
compiler/expr_visitor.py
View file @
75a35b4b
...
...
@@ -371,6 +371,7 @@ class ExprVisitor(ast.NodeVisitor):
_UNARY_OP_TEMPLATES
=
{
ast
.
Invert
:
'πg.Invert(πF, {operand})'
,
ast
.
USub
:
'πg.Neg(πF, {operand})'
,
}
def
visit_function_inline
(
self
,
node
):
...
...
runtime/core.go
View file @
75a35b4b
...
...
@@ -759,6 +759,16 @@ func ToStr(f *Frame, o *Object) (*Str, *BaseException) {
return
toStrUnsafe
(
result
),
nil
}
// Neg returns the result of o.__neg__ and is equivalent to the Python
// expression "-o".
func
Neg
(
f
*
Frame
,
o
*
Object
)
(
*
Object
,
*
BaseException
)
{
neg
:=
o
.
typ
.
slots
.
Neg
if
neg
==
nil
{
return
nil
,
f
.
RaiseType
(
TypeErrorType
,
fmt
.
Sprintf
(
"bad operand type for unary ~: '%s'"
,
o
.
typ
.
Name
()))
}
return
neg
.
Fn
(
f
,
o
)
}
// Xor returns the result of the bitwise xor operator v ^ w according to
// __xor/rxor__.
func
Xor
(
f
*
Frame
,
v
,
w
*
Object
)
(
*
Object
,
*
BaseException
)
{
...
...
runtime/slots.go
View file @
75a35b4b
...
...
@@ -408,6 +408,7 @@ type typeSlots struct {
Mul
*
binaryOpSlot
Native
*
nativeSlot
NE
*
binaryOpSlot
Neg
*
unaryOpSlot
New
*
newSlot
Next
*
unaryOpSlot
NonZero
*
unaryOpSlot
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment