Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
50564e8d
Kaydet (Commit)
50564e8d
authored
Ock 12, 1996
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
changes for complex and power (**) operator
üst
8a5c5d27
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
30 deletions
+136
-30
ceval.c
Python/ceval.c
+38
-0
compile.c
Python/compile.c
+98
-30
No files found.
Python/ceval.c
Dosyayı görüntüle @
50564e8d
...
@@ -82,6 +82,7 @@ static int call_trace
...
@@ -82,6 +82,7 @@ static int call_trace
PROTO
((
object
**
,
object
**
,
frameobject
*
,
char
*
,
object
*
));
PROTO
((
object
**
,
object
**
,
frameobject
*
,
char
*
,
object
*
));
static
object
*
add
PROTO
((
object
*
,
object
*
));
static
object
*
add
PROTO
((
object
*
,
object
*
));
static
object
*
sub
PROTO
((
object
*
,
object
*
));
static
object
*
sub
PROTO
((
object
*
,
object
*
));
static
object
*
pow
PROTO
((
object
*
,
object
*
));
static
object
*
mul
PROTO
((
object
*
,
object
*
));
static
object
*
mul
PROTO
((
object
*
,
object
*
));
static
object
*
divide
PROTO
((
object
*
,
object
*
));
static
object
*
divide
PROTO
((
object
*
,
object
*
));
static
object
*
mod
PROTO
((
object
*
,
object
*
));
static
object
*
mod
PROTO
((
object
*
,
object
*
));
...
@@ -675,6 +676,15 @@ eval_code2(co, globals, locals,
...
@@ -675,6 +676,15 @@ eval_code2(co, globals, locals,
PUSH
(
x
);
PUSH
(
x
);
break
;
break
;
case
BINARY_POWER
:
w
=
POP
();
v
=
POP
();
x
=
pow
(
v
,
w
);
DECREF
(
v
);
DECREF
(
w
);
PUSH
(
x
);
break
;
case
BINARY_MULTIPLY
:
case
BINARY_MULTIPLY
:
w
=
POP
();
w
=
POP
();
v
=
POP
();
v
=
POP
();
...
@@ -2204,6 +2214,34 @@ mod(v, w)
...
@@ -2204,6 +2214,34 @@ mod(v, w)
return
NULL
;
return
NULL
;
}
}
static
object
*
pow
(
v
,
w
)
object
*
v
,
*
w
;
{
object
*
res
;
BINOP
(
"__pow__"
,
"__rpow__"
,
pow
);
if
(
v
->
ob_type
->
tp_as_number
==
NULL
||
w
->
ob_type
->
tp_as_number
==
NULL
)
{
err_setstr
(
TypeError
,
"pow() requires numeric arguments"
);
return
NULL
;
}
if
(
#ifndef WITHOUT_COMPLEX
!
is_complexobject
(
v
)
&&
#endif
is_floatobject
(
w
)
&&
getfloatvalue
(
v
)
<
0
.
0
)
{
if
(
!
err_occurred
())
err_setstr
(
ValueError
,
"negative number to float power"
);
return
NULL
;
}
if
(
coerce
(
&
v
,
&
w
)
!=
0
)
return
NULL
;
res
=
(
*
v
->
ob_type
->
tp_as_number
->
nb_power
)(
v
,
w
,
None
);
DECREF
(
v
);
DECREF
(
w
);
return
res
;
}
static
object
*
static
object
*
neg
(
v
)
neg
(
v
)
object
*
v
;
object
*
v
;
...
...
Python/compile.c
Dosyayı görüntüle @
50564e8d
...
@@ -287,6 +287,7 @@ static int com_init PROTO((struct compiling *, char *));
...
@@ -287,6 +287,7 @@ static int com_init PROTO((struct compiling *, char *));
static
void
com_free
PROTO
((
struct
compiling
*
));
static
void
com_free
PROTO
((
struct
compiling
*
));
static
void
com_done
PROTO
((
struct
compiling
*
));
static
void
com_done
PROTO
((
struct
compiling
*
));
static
void
com_node
PROTO
((
struct
compiling
*
,
struct
_node
*
));
static
void
com_node
PROTO
((
struct
compiling
*
,
struct
_node
*
));
static
void
com_factor
PROTO
((
struct
compiling
*
,
struct
_node
*
));
static
void
com_addbyte
PROTO
((
struct
compiling
*
,
int
));
static
void
com_addbyte
PROTO
((
struct
compiling
*
,
int
));
static
void
com_addint
PROTO
((
struct
compiling
*
,
int
));
static
void
com_addint
PROTO
((
struct
compiling
*
,
int
));
static
void
com_addoparg
PROTO
((
struct
compiling
*
,
int
,
int
));
static
void
com_addoparg
PROTO
((
struct
compiling
*
,
int
,
int
));
...
@@ -563,8 +564,16 @@ parsenumber(s)
...
@@ -563,8 +564,16 @@ parsenumber(s)
extern
double
atof
PROTO
((
const
char
*
));
extern
double
atof
PROTO
((
const
char
*
));
char
*
end
;
char
*
end
;
long
x
;
long
x
;
#ifndef WITHOUT_COMPLEX
complex
c
;
int
imflag
;
#endif
errno
=
0
;
errno
=
0
;
end
=
s
+
strlen
(
s
)
-
1
;
end
=
s
+
strlen
(
s
)
-
1
;
#ifndef WITHOUT_COMPLEX
imflag
=
*
end
==
'i'
||
*
end
==
'I'
||
*
end
==
'j'
||
*
end
==
'J'
;
#endif
if
(
*
end
==
'l'
||
*
end
==
'L'
)
if
(
*
end
==
'l'
||
*
end
==
'L'
)
return
long_scan
(
s
,
0
);
return
long_scan
(
s
,
0
);
if
(
s
[
0
]
==
'0'
)
if
(
s
[
0
]
==
'0'
)
...
@@ -580,7 +589,15 @@ parsenumber(s)
...
@@ -580,7 +589,15 @@ parsenumber(s)
return
newintobject
(
x
);
return
newintobject
(
x
);
}
}
/* XXX Huge floats may silently fail */
/* XXX Huge floats may silently fail */
return
newfloatobject
(
atof
(
s
));
#ifndef WITHOUT_COMPLEX
if
(
imflag
)
{
c
.
real
=
0
.;
c
.
imag
=
atof
(
s
);
return
newcomplexobject
(
c
);
}
else
#endif
return
newfloatobject
(
atof
(
s
));
}
}
static
object
*
static
object
*
...
@@ -810,15 +827,23 @@ com_apply_subscript(c, n)
...
@@ -810,15 +827,23 @@ com_apply_subscript(c, n)
node
*
n
;
node
*
n
;
{
{
REQ
(
n
,
subscript
);
REQ
(
n
,
subscript
);
if
(
NCH
(
n
)
==
1
&&
TYPE
(
CHILD
(
n
,
0
))
!=
COLON
)
{
if
(
TYPE
(
CHILD
(
n
,
0
))
==
COLON
||
(
NCH
(
n
)
>
1
&&
TYPE
(
CHILD
(
n
,
1
))
==
COLON
))
{
/* It's a single subscript */
com_node
(
c
,
CHILD
(
n
,
0
));
com_addbyte
(
c
,
BINARY_SUBSCR
);
}
else
{
/* It's a slice: [expr] ':' [expr] */
/* It's a slice: [expr] ':' [expr] */
com_slice
(
c
,
n
,
SLICE
);
com_slice
(
c
,
n
,
SLICE
);
}
}
else
{
/* It's a list of subscripts */
if
(
NCH
(
n
)
==
1
)
com_node
(
c
,
CHILD
(
n
,
0
));
else
{
int
i
;
int
len
=
(
NCH
(
n
)
+
1
)
/
2
;
for
(
i
=
0
;
i
<
NCH
(
n
);
i
+=
2
)
com_node
(
c
,
CHILD
(
n
,
i
));
com_addoparg
(
c
,
BUILD_TUPLE
,
len
);
}
com_addbyte
(
c
,
BINARY_SUBSCR
);
}
}
}
static
int
static
int
...
@@ -921,6 +946,25 @@ com_apply_trailer(c, n)
...
@@ -921,6 +946,25 @@ com_apply_trailer(c, n)
}
}
}
}
static
void
com_power
(
c
,
n
)
struct
compiling
*
c
;
node
*
n
;
{
int
i
;
REQ
(
n
,
power
);
com_atom
(
c
,
CHILD
(
n
,
0
));
for
(
i
=
1
;
i
<
NCH
(
n
);
i
++
)
{
if
(
TYPE
(
CHILD
(
n
,
i
))
==
DOUBLESTAR
)
{
com_factor
(
c
,
CHILD
(
n
,
i
+
1
));
com_addbyte
(
c
,
BINARY_POWER
);
break
;
}
else
com_apply_trailer
(
c
,
CHILD
(
n
,
i
));
}
}
static
void
static
void
com_factor
(
c
,
n
)
com_factor
(
c
,
n
)
struct
compiling
*
c
;
struct
compiling
*
c
;
...
@@ -941,9 +985,7 @@ com_factor(c, n)
...
@@ -941,9 +985,7 @@ com_factor(c, n)
com_addbyte
(
c
,
UNARY_INVERT
);
com_addbyte
(
c
,
UNARY_INVERT
);
}
}
else
{
else
{
com_atom
(
c
,
CHILD
(
n
,
0
));
com_power
(
c
,
CHILD
(
n
,
0
));
for
(
i
=
1
;
i
<
NCH
(
n
);
i
++
)
com_apply_trailer
(
c
,
CHILD
(
n
,
i
));
}
}
}
}
...
@@ -1338,7 +1380,15 @@ com_assign_subscript(c, n, assigning)
...
@@ -1338,7 +1380,15 @@ com_assign_subscript(c, n, assigning)
node
*
n
;
node
*
n
;
int
assigning
;
int
assigning
;
{
{
com_node
(
c
,
n
);
if
(
NCH
(
n
)
==
1
)
com_node
(
c
,
CHILD
(
n
,
0
));
else
{
int
i
;
int
len
=
(
NCH
(
n
)
+
1
)
/
2
;
for
(
i
=
0
;
i
<
NCH
(
n
);
i
+=
2
)
com_node
(
c
,
CHILD
(
n
,
i
));
com_addoparg
(
c
,
BUILD_TUPLE
,
len
);
}
com_addbyte
(
c
,
assigning
?
STORE_SUBSCR
:
DELETE_SUBSCR
);
com_addbyte
(
c
,
assigning
?
STORE_SUBSCR
:
DELETE_SUBSCR
);
}
}
...
@@ -1359,11 +1409,11 @@ com_assign_trailer(c, n, assigning)
...
@@ -1359,11 +1409,11 @@ com_assign_trailer(c, n, assigning)
break
;
break
;
case
LSQB
:
/* '[' subscript ']' */
case
LSQB
:
/* '[' subscript ']' */
n
=
CHILD
(
n
,
1
);
n
=
CHILD
(
n
,
1
);
REQ
(
n
,
subscript
);
/* subscript: expr | [expr] ':' [expr] */
REQ
(
n
,
subscript
);
/* subscript: expr
(',' expr)*
| [expr] ':' [expr] */
if
(
NCH
(
n
)
>
1
||
TYPE
(
CHILD
(
n
,
0
))
==
COLON
)
if
(
TYPE
(
CHILD
(
n
,
0
))
==
COLON
||
(
NCH
(
n
)
>
1
&&
TYPE
(
CHILD
(
n
,
1
))
==
COLON
)
)
com_assign_slice
(
c
,
n
,
assigning
);
com_assign_slice
(
c
,
n
,
assigning
);
else
else
com_assign_subscript
(
c
,
CHILD
(
n
,
0
)
,
assigning
);
com_assign_subscript
(
c
,
n
,
assigning
);
break
;
break
;
default
:
default
:
err_setstr
(
SystemError
,
"unknown trailer type"
);
err_setstr
(
SystemError
,
"unknown trailer type"
);
...
@@ -1438,6 +1488,7 @@ com_assign(c, n, assigning)
...
@@ -1438,6 +1488,7 @@ com_assign(c, n, assigning)
case
shift_expr
:
case
shift_expr
:
case
arith_expr
:
case
arith_expr
:
case
term
:
case
term
:
case
factor
:
if
(
NCH
(
n
)
>
1
)
{
if
(
NCH
(
n
)
>
1
)
{
err_setstr
(
SyntaxError
,
err_setstr
(
SyntaxError
,
"can't assign to operator"
);
"can't assign to operator"
);
...
@@ -1447,17 +1498,24 @@ com_assign(c, n, assigning)
...
@@ -1447,17 +1498,24 @@ com_assign(c, n, assigning)
n
=
CHILD
(
n
,
0
);
n
=
CHILD
(
n
,
0
);
break
;
break
;
case
factor
:
/* ('+'|'-'|'~') factor | atom trailer* */
case
power
:
/* atom trailer* ('**' power)* */
if
(
TYPE
(
CHILD
(
n
,
0
))
!=
atom
)
{
/* '+'|'-'|'~' */
/* ('+'|'-'|'~') factor | atom trailer* */
if
(
TYPE
(
CHILD
(
n
,
0
))
!=
atom
)
{
err_setstr
(
SyntaxError
,
err_setstr
(
SyntaxError
,
"can't assign to operator"
);
"can't assign to operator"
);
c
->
c_errors
++
;
c
->
c_errors
++
;
return
;
return
;
}
}
if
(
NCH
(
n
)
>
1
)
{
/* trailer present */
if
(
NCH
(
n
)
>
1
)
{
/* trailer
or exponent
present */
int
i
;
int
i
;
com_node
(
c
,
CHILD
(
n
,
0
));
com_node
(
c
,
CHILD
(
n
,
0
));
for
(
i
=
1
;
i
+
1
<
NCH
(
n
);
i
++
)
{
for
(
i
=
1
;
i
+
1
<
NCH
(
n
);
i
++
)
{
if
(
TYPE
(
CHILD
(
n
,
i
))
==
DOUBLESTAR
)
{
err_setstr
(
SyntaxError
,
"can't assign to operator"
);
c
->
c_errors
++
;
return
;
}
com_apply_trailer
(
c
,
CHILD
(
n
,
i
));
com_apply_trailer
(
c
,
CHILD
(
n
,
i
));
}
/* NB i is still alive */
}
/* NB i is still alive */
com_assign_trailer
(
c
,
com_assign_trailer
(
c
,
...
@@ -2059,6 +2117,7 @@ get_docstring(n)
...
@@ -2059,6 +2117,7 @@ get_docstring(n)
case
arith_expr
:
case
arith_expr
:
case
term
:
case
term
:
case
factor
:
case
factor
:
case
power
:
if
(
NCH
(
n
)
==
1
)
if
(
NCH
(
n
)
==
1
)
return
get_docstring
(
CHILD
(
n
,
0
));
return
get_docstring
(
CHILD
(
n
,
0
));
break
;
break
;
...
@@ -2136,7 +2195,7 @@ com_argdefs(c, n)
...
@@ -2136,7 +2195,7 @@ com_argdefs(c, n)
ndefs
=
0
;
ndefs
=
0
;
for
(
i
=
0
;
i
<
nch
;
i
++
)
{
for
(
i
=
0
;
i
<
nch
;
i
++
)
{
int
t
;
int
t
;
if
(
TYPE
(
CHILD
(
n
,
i
))
==
STAR
)
if
(
TYPE
(
CHILD
(
n
,
i
))
==
STAR
||
TYPE
(
CHILD
(
n
,
i
))
==
DOUBLESTAR
)
break
;
break
;
nargs
++
;
nargs
++
;
i
++
;
i
++
;
...
@@ -2373,6 +2432,9 @@ com_node(c, n)
...
@@ -2373,6 +2432,9 @@ com_node(c, n)
case
factor
:
case
factor
:
com_factor
(
c
,
n
);
com_factor
(
c
,
n
);
break
;
break
;
case
power
:
com_power
(
c
,
n
);
break
;
case
atom
:
case
atom
:
com_atom
(
c
,
n
);
com_atom
(
c
,
n
);
break
;
break
;
...
@@ -2431,7 +2493,7 @@ com_arglist(c, n)
...
@@ -2431,7 +2493,7 @@ com_arglist(c, n)
node
*
ch
=
CHILD
(
n
,
i
);
node
*
ch
=
CHILD
(
n
,
i
);
node
*
fp
;
node
*
fp
;
char
*
name
;
char
*
name
;
if
(
TYPE
(
ch
)
==
STAR
)
if
(
TYPE
(
ch
)
==
STAR
||
TYPE
(
ch
)
==
DOUBLESTAR
)
break
;
break
;
REQ
(
ch
,
fpdef
);
/* fpdef: NAME | '(' fplist ')' */
REQ
(
ch
,
fpdef
);
/* fpdef: NAME | '(' fplist ')' */
fp
=
CHILD
(
ch
,
0
);
fp
=
CHILD
(
ch
,
0
);
...
@@ -2455,22 +2517,28 @@ com_arglist(c, n)
...
@@ -2455,22 +2517,28 @@ com_arglist(c, n)
if
(
i
<
nch
)
{
if
(
i
<
nch
)
{
node
*
ch
;
node
*
ch
;
ch
=
CHILD
(
n
,
i
);
ch
=
CHILD
(
n
,
i
);
REQ
(
ch
,
STAR
);
if
(
TYPE
(
ch
)
!=
DOUBLESTAR
)
{
ch
=
CHILD
(
n
,
i
+
1
);
REQ
(
ch
,
STAR
);
if
(
TYPE
(
ch
)
==
NAME
)
{
ch
=
CHILD
(
n
,
i
+
1
);
c
->
c_flags
|=
CO_VARARGS
;
if
(
TYPE
(
ch
)
==
NAME
)
{
i
+=
3
;
c
->
c_flags
|=
CO_VARARGS
;
com_newlocal
(
c
,
STR
(
ch
));
i
+=
3
;
com_newlocal
(
c
,
STR
(
ch
));
}
}
}
}
}
/* Handle **keywords */
/* Handle **keywords */
if
(
i
<
nch
)
{
if
(
i
<
nch
)
{
node
*
ch
;
node
*
ch
;
ch
=
CHILD
(
n
,
i
);
ch
=
CHILD
(
n
,
i
);
REQ
(
ch
,
STAR
);
if
(
TYPE
(
ch
)
!=
DOUBLESTAR
)
{
ch
=
CHILD
(
n
,
i
+
1
);
REQ
(
ch
,
STAR
);
REQ
(
ch
,
STAR
);
ch
=
CHILD
(
n
,
i
+
1
);
ch
=
CHILD
(
n
,
i
+
2
);
REQ
(
ch
,
STAR
);
ch
=
CHILD
(
n
,
i
+
2
);
}
else
ch
=
CHILD
(
n
,
i
+
1
);
REQ
(
ch
,
NAME
);
REQ
(
ch
,
NAME
);
c
->
c_flags
|=
CO_VARKEYWORDS
;
c
->
c_flags
|=
CO_VARKEYWORDS
;
com_newlocal
(
c
,
STR
(
ch
));
com_newlocal
(
c
,
STR
(
ch
));
...
@@ -2482,7 +2550,7 @@ com_arglist(c, n)
...
@@ -2482,7 +2550,7 @@ com_arglist(c, n)
for
(
i
=
0
;
i
<
nch
;
i
++
)
{
for
(
i
=
0
;
i
<
nch
;
i
++
)
{
node
*
ch
=
CHILD
(
n
,
i
);
node
*
ch
=
CHILD
(
n
,
i
);
node
*
fp
;
node
*
fp
;
if
(
TYPE
(
ch
)
==
STAR
)
if
(
TYPE
(
ch
)
==
STAR
||
TYPE
(
ch
)
==
DOUBLESTAR
)
break
;
break
;
REQ
(
ch
,
fpdef
);
/* fpdef: NAME | '(' fplist ')' */
REQ
(
ch
,
fpdef
);
/* fpdef: NAME | '(' fplist ')' */
fp
=
CHILD
(
ch
,
0
);
fp
=
CHILD
(
ch
,
0
);
...
...
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