Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs444
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Yang
cs444
Commits
20169afd
Commit
20169afd
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
constructor
parent
eb5d7d87
No related branches found
No related tags found
1 merge request
!14
Insta field
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ExprPrimaryNodes.py
+2
-3
2 additions, 3 deletions
ExprPrimaryNodes.py
MemberNodes.py
+25
-12
25 additions, 12 deletions
MemberNodes.py
with
27 additions
and
15 deletions
ExprPrimaryNodes.py
+
2
−
3
View file @
20169afd
...
...
@@ -373,10 +373,9 @@ class ClassCreateNode(ASTNode):
self
.
code
+=
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
pushing object as first argument
"
)
# Evaluate arguments and pushing parameters
if
self
.
args
and
hasattr
(
self
.
args
,
"
codeGen
"
):
if
not
hasattr
(
self
.
args
,
"
code
"
):
self
.
args
.
codeGen
()
self
.
args
.
codeGen
()
self
.
code
+=
self
.
args
.
code
label
=
"
M_
"
+
self
.
cons
.
typeName
+
"
_
"
+
self
.
cons
.
name
+
"
_
"
+
self
.
cons
.
paramTypes
label
=
"
M_
"
+
self
.
cons
.
typeName
+
"
_
"
+
self
.
cons
.
paramTypes
self
.
code
+=
importHelper
(
classDef
.
name
,
self
.
typeName
,
label
)
self
.
code
+=
p
(
instruction
=
"
call
"
,
arg1
=
label
,
comment
=
"
Calling constructor
"
)
...
...
This diff is collapsed.
Click to expand it.
MemberNodes.py
+
25
−
12
View file @
20169afd
...
...
@@ -82,7 +82,7 @@ class FieldNode(ASTNode):
p
(
instruction
=
"
mov
"
,
arg1
=
"
[ebx]
"
,
arg2
=
"
eax
"
,
comment
=
"
eax is a pointer to field value in heap
"
)
self
.
code
+=
"
;End of declaration of static field
\n
"
###########################################################
...
...
@@ -245,36 +245,49 @@ class MethodNode(ASTNode):
if
hasattr
(
self
,
"
code
"
)
and
self
.
code
!=
""
:
return
myClass
=
self
.
env
.
getNode
(
self
.
typeName
,
'
type
'
)
self
.
label
=
"
M_
"
+
self
.
typeName
+
"
_
"
+
self
.
paramTypes
self
.
code
=
pLabel
(
self
.
typeName
+
"
_
"
+
self
.
paramTypes
,
"
method
"
)
# label
thisLoc
=
len
(
self
.
params
)
*
4
+
8
bodyCode
=
""
# init fields
# body code
if
self
.
body
:
bodyCode
=
""
# push all local var to stack
vars
=
getVarDclNodes
(
self
.
body
)
for
i
in
range
(
len
(
vars
)):
vars
[
i
].
offset
=
i
*
4
+
16
bodyCode
+=
p
(
"
push
"
,
0
)
# call parent constructor
if
myClass
.
superClass
:
suLabel
=
"
M_
"
+
myClass
.
superClass
.
name
+
"
_
"
bodyCode
+=
importHelper
(
myClass
.
superClass
.
name
,
self
.
typeName
,
suLabel
)
bodyCode
+=
p
(
"
mov
"
,
"
eax
"
,
"
[ebp -
"
+
thisLoc
+
"
]
"
)
bodyCode
+=
p
(
"
push
"
,
"
eax
"
,
None
,
"
# Pass THIS as argument to superClass.
"
)
bodyCode
+=
p
(
"
call
"
,
suLabel
)
# init fields
fields
=
sorted
(
myClass
.
fields
,
key
=
lambda
x
:
x
.
order
)
for
f
in
fields
:
if
not
'
static
'
in
field
.
mods
and
f
.
variableDcl
.
variableInit
:
f
.
variableDcl
.
variableInit
.
right
.
codeGen
()
bodyCode
+=
f
.
variableDcl
.
variableInit
.
right
.
code
bodyCode
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebp -
"
+
thisLoc
+
"
]
"
)
# THIS
bodyCode
+=
p
(
"
mov
"
,
"
[ebx +
"
+
f
.
offset
+
"
]
"
,
"
eax
"
)
# body code
if
self
.
body
:
self
.
body
.
codeGen
()
bodyCode
+=
self
.
body
.
code
bodyCode
+=
self
.
label
+
"
_end: ; end of method for
"
+
self
.
name
+
"
\n
"
# pop off all the local var
for
i
in
range
(
len
(
vars
)):
bodyCode
+=
p
(
"
pop
"
,
"
edx
"
)
self
.
code
+=
genProcedure
(
bodyCode
,
"
method definition for
"
+
self
.
name
)
else
:
self
.
code
+=
p
(
"
ret
"
,
""
)
self
.
code
+=
genProcedure
(
bodyCode
,
"
Constructor definition for
"
+
self
.
name
+
"
"
+
self
.
paramTypes
)
############# helper for forward ref checking ########
# Input: AST Node
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment