Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
423cf9fb
Commit
423cf9fb
authored
Jan 12, 1992
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted to use == equality check syntax.
parent
c3cff59a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
22 deletions
+22
-22
Modules/cgen.py
Modules/cgen.py
+22
-22
No files found.
Modules/cgen.py
View file @
423cf9fb
...
@@ -103,7 +103,7 @@ def checkarg(type, arg):
...
@@ -103,7 +103,7 @@ def checkarg(type, arg):
#
#
# Turn "char *x" into "string x".
# Turn "char *x" into "string x".
#
#
if
type
=
'char'
and
arg
[
0
]
=
'*'
:
if
type
=
=
'char'
and
arg
[
0
]
=
=
'*'
:
type
=
'string'
type
=
'string'
arg
=
arg
[
1
:]
arg
=
arg
[
1
:]
#
#
...
@@ -148,12 +148,12 @@ def checkarg(type, arg):
...
@@ -148,12 +148,12 @@ def checkarg(type, arg):
if
not
sub
:
if
not
sub
:
# The subscript is just a number
# The subscript is just a number
return
type
,
mode
,
num
,
''
return
type
,
mode
,
num
,
''
if
sub
[:
1
]
=
'*'
:
if
sub
[:
1
]
=
=
'*'
:
# There is a factor prefix
# There is a factor prefix
sub
=
sub
[
1
:]
sub
=
sub
[
1
:]
else
:
else
:
raise
arg_error
,
(
'
\
'
*
\
'
expected'
,
sub
)
raise
arg_error
,
(
'
\
'
*
\
'
expected'
,
sub
)
if
sub
=
'retval'
:
if
sub
=
=
'retval'
:
# size is retval -- must be a reply argument
# size is retval -- must be a reply argument
if
mode
<>
'r'
:
if
mode
<>
'r'
:
raise
arg_error
,
(
'non-r mode with [retval]'
,
mode
)
raise
arg_error
,
(
'non-r mode with [retval]'
,
mode
)
...
@@ -180,14 +180,14 @@ def generate(type, func, database):
...
@@ -180,14 +180,14 @@ def generate(type, func, database):
n_out_args
=
0
n_out_args
=
0
#
#
for
a_type
,
a_mode
,
a_factor
,
a_sub
in
database
:
for
a_type
,
a_mode
,
a_factor
,
a_sub
in
database
:
if
a_mode
=
's'
:
if
a_mode
=
=
's'
:
n_in_args
=
n_in_args
+
1
n_in_args
=
n_in_args
+
1
elif
a_mode
=
'r'
:
elif
a_mode
=
=
'r'
:
n_out_args
=
n_out_args
+
1
n_out_args
=
n_out_args
+
1
else
:
else
:
# Can't happen
# Can't happen
raise
arg_error
,
(
'bad a_mode'
,
a_mode
)
raise
arg_error
,
(
'bad a_mode'
,
a_mode
)
if
(
a_mode
=
'r'
and
a_sub
)
or
a_sub
=
'retval'
:
if
(
a_mode
=
=
'r'
and
a_sub
)
or
a_sub
=
=
'retval'
:
e
=
'Function'
,
func
,
'too complicated:'
e
=
'Function'
,
func
,
'too complicated:'
err
(
e
+
(
a_type
,
a_mode
,
a_factor
,
a_sub
))
err
(
e
+
(
a_type
,
a_mode
,
a_factor
,
a_sub
))
print
'/* XXX Too complicated to generate code for */'
print
'/* XXX Too complicated to generate code for */'
...
@@ -225,12 +225,12 @@ def generate(type, func, database):
...
@@ -225,12 +225,12 @@ def generate(type, func, database):
#
#
for
i
in
range
(
len
(
database
)):
for
i
in
range
(
len
(
database
)):
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
if
a_mode
=
's'
and
a_sub
[:
3
]
=
'arg'
and
isnum
(
a_sub
[
3
:]):
if
a_mode
=
=
's'
and
a_sub
[:
3
]
=
=
'arg'
and
isnum
(
a_sub
[
3
:]):
# Sending a variable-length array
# Sending a variable-length array
n
=
eval
(
a_sub
[
3
:])
n
=
eval
(
a_sub
[
3
:])
if
1
<=
n
<=
len
(
database
):
if
1
<=
n
<=
len
(
database
):
b_type
,
b_mode
,
b_factor
,
b_sub
=
database
[
n
-
1
]
b_type
,
b_mode
,
b_factor
,
b_sub
=
database
[
n
-
1
]
if
b_mode
=
's'
:
if
b_mode
=
=
's'
:
database
[
n
-
1
]
=
b_type
,
'i'
,
a_factor
,
`i`
database
[
n
-
1
]
=
b_type
,
'i'
,
a_factor
,
`i`
n_in_args
=
n_in_args
-
1
n_in_args
=
n_in_args
-
1
#
#
...
@@ -240,7 +240,7 @@ def generate(type, func, database):
...
@@ -240,7 +240,7 @@ def generate(type, func, database):
i_in
=
0
i_in
=
0
for
i
in
range
(
len
(
database
)):
for
i
in
range
(
len
(
database
)):
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
if
a_mode
=
's'
:
if
a_mode
=
=
's'
:
in_pos
.
append
(
i_in
)
in_pos
.
append
(
i_in
)
i_in
=
i_in
+
1
i_in
=
i_in
+
1
else
:
else
:
...
@@ -250,7 +250,7 @@ def generate(type, func, database):
...
@@ -250,7 +250,7 @@ def generate(type, func, database):
#
#
for
i
in
range
(
len
(
database
)):
for
i
in
range
(
len
(
database
)):
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
if
a_mode
=
'i'
:
if
a_mode
=
=
'i'
:
#
#
# Implicit argument;
# Implicit argument;
# a_factor is divisor if present,
# a_factor is divisor if present,
...
@@ -267,7 +267,7 @@ def generate(type, func, database):
...
@@ -267,7 +267,7 @@ def generate(type, func, database):
print
'
\
t
arg'
+
`i+1`
,
print
'
\
t
arg'
+
`i+1`
,
print
'= arg'
+
`i+1`
,
print
'= arg'
+
`i+1`
,
print
'/'
,
a_factor
+
';'
print
'/'
,
a_factor
+
';'
elif
a_mode
=
's'
:
elif
a_mode
=
=
's'
:
if
a_sub
:
# Allocate memory for varsize array
if
a_sub
:
# Allocate memory for varsize array
print
'
\
t
if ((arg'
+
`i+1`
,
'='
,
print
'
\
t
if ((arg'
+
`i+1`
,
'='
,
print
'NEW('
+
a_type
+
','
,
print
'NEW('
+
a_type
+
','
,
...
@@ -302,7 +302,7 @@ def generate(type, func, database):
...
@@ -302,7 +302,7 @@ def generate(type, func, database):
for
i
in
range
(
len
(
database
)):
for
i
in
range
(
len
(
database
)):
if
i
>
0
:
print
','
,
if
i
>
0
:
print
','
,
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
if
a_mode
=
'r'
and
not
a_factor
:
if
a_mode
=
=
'r'
and
not
a_factor
:
print
'&'
,
print
'&'
,
print
'arg'
+
`i+1`
,
print
'arg'
+
`i+1`
,
#
#
...
@@ -314,7 +314,7 @@ def generate(type, func, database):
...
@@ -314,7 +314,7 @@ def generate(type, func, database):
#
#
for
i
in
range
(
len
(
database
)):
for
i
in
range
(
len
(
database
)):
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
if
a_mode
=
's'
and
a_sub
:
if
a_mode
=
=
's'
and
a_sub
:
print
'
\
t
DEL(arg'
+
`i+1`
+
');'
print
'
\
t
DEL(arg'
+
`i+1`
+
');'
#
#
# Return
# Return
...
@@ -325,10 +325,10 @@ def generate(type, func, database):
...
@@ -325,10 +325,10 @@ def generate(type, func, database):
#
#
if
type
<>
'void'
:
if
type
<>
'void'
:
n_out_args
=
n_out_args
+
1
n_out_args
=
n_out_args
+
1
if
n_out_args
=
1
:
if
n_out_args
=
=
1
:
for
i
in
range
(
len
(
database
)):
for
i
in
range
(
len
(
database
)):
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
if
a_mode
=
'r'
:
if
a_mode
=
=
'r'
:
break
break
else
:
else
:
raise
arg_error
,
'expected r arg not found'
raise
arg_error
,
'expected r arg not found'
...
@@ -346,7 +346,7 @@ def generate(type, func, database):
...
@@ -346,7 +346,7 @@ def generate(type, func, database):
i_out
=
i_out
+
1
i_out
=
i_out
+
1
for
i
in
range
(
len
(
database
)):
for
i
in
range
(
len
(
database
)):
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
a_type
,
a_mode
,
a_factor
,
a_sub
=
database
[
i
]
if
a_mode
=
'r'
:
if
a_mode
=
=
'r'
:
print
'
\
t
settupleitem(v,'
,
print
'
\
t
settupleitem(v,'
,
print
`i_out`
+
','
,
print
`i_out`
+
','
,
s
=
mkobject
(
a_type
,
'arg'
+
`i+1`
)
s
=
mkobject
(
a_type
,
'arg'
+
`i+1`
)
...
@@ -359,7 +359,7 @@ def generate(type, func, database):
...
@@ -359,7 +359,7 @@ def generate(type, func, database):
# Simple function return
# Simple function return
# Return None or return value
# Return None or return value
#
#
if
type
=
'void'
:
if
type
=
=
'void'
:
print
'
\
t
INCREF(None);'
print
'
\
t
INCREF(None);'
print
'
\
t
return None;'
print
'
\
t
return None;'
else
:
else
:
...
@@ -399,12 +399,12 @@ while 1:
...
@@ -399,12 +399,12 @@ while 1:
lno
=
lno
+
1
lno
=
lno
+
1
words
=
string
.
split
(
line
)
words
=
string
.
split
(
line
)
#
#
if
part
=
1
:
if
part
=
=
1
:
#
#
# In part 1, copy everything literally
# In part 1, copy everything literally
# except look for a line of just '%%'
# except look for a line of just '%%'
#
#
if
words
=
[
'%%'
]:
if
words
=
=
[
'%%'
]:
part
=
part
+
1
part
=
part
+
1
else
:
else
:
#
#
...
@@ -413,7 +413,7 @@ while 1:
...
@@ -413,7 +413,7 @@ while 1:
# of the function in Python.
# of the function in Python.
# The stub name is derived by prefixing 'gl_'.
# The stub name is derived by prefixing 'gl_'.
#
#
if
words
and
words
[
0
][
0
]
=
'%'
:
if
words
and
words
[
0
][
0
]
=
=
'%'
:
func
=
words
[
0
][
1
:]
func
=
words
[
0
][
1
:]
if
(
not
func
)
and
words
[
1
:]:
if
(
not
func
)
and
words
[
1
:]:
func
=
words
[
1
]
func
=
words
[
1
]
...
@@ -423,9 +423,9 @@ while 1:
...
@@ -423,9 +423,9 @@ while 1:
print
line
print
line
elif
not
words
:
elif
not
words
:
pass
# skip empty line
pass
# skip empty line
elif
words
[
0
]
=
'#include'
:
elif
words
[
0
]
=
=
'#include'
:
print
line
print
line
elif
words
[
0
][:
1
]
=
'#'
:
elif
words
[
0
][:
1
]
=
=
'#'
:
pass
# ignore comment
pass
# ignore comment
elif
words
[
0
]
not
in
return_types
:
elif
words
[
0
]
not
in
return_types
:
err
(
'Line'
,
lno
,
': bad return type :'
,
words
[
0
])
err
(
'Line'
,
lno
,
': bad return type :'
,
words
[
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