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
31e6fcb1
Commit
31e6fcb1
authored
4 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
array assign check, fix subtype count
parent
2b8b7207
No related branches found
No related tags found
2 merge requests
!26
Array subtype
,
!20
Master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
AstBuilding.py
+8
-6
8 additions, 6 deletions
AstBuilding.py
ExprPrimaryNodes.py
+15
-0
15 additions, 0 deletions
ExprPrimaryNodes.py
with
23 additions
and
6 deletions
AstBuilding.py
+
8
−
6
View file @
31e6fcb1
...
...
@@ -112,7 +112,7 @@ def arrayClassMemory(types):
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax]
"
,
arg2
=
"
dword
"
+
m
,
comment
=
"
points to method implementation
"
)
if
tt
.
__class__
.
__name__
==
"
ClassNode
"
:
code
+=
p
(
"
extern
"
,
"
A_subT
"
+
tt
.
name
)
code
+=
p
(
"
extern
"
,
"
A_subT
_
"
+
tt
.
name
)
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
I_subT_spot_
"
+
t
)
code
+=
p
(
"
mov
"
,
"
[eax]
"
,
"
dword A_subT_
"
+
tt
.
name
)
...
...
@@ -135,21 +135,23 @@ def codeGenPrep(ASTs):
interM
=
[]
types
=
[
'
boolean
'
,
'
byte
'
,
'
char
'
,
'
int
'
,
'
short
'
]
# All possible types
classNodes
=
[]
j
=
0
for
t
in
ASTs
:
classInterNode
=
t
[
1
].
typeDcl
if
classInterNode
.
__class__
.
__name__
==
"
ClassNode
"
:
types
.
append
(
classInterNode
)
classNodes
.
append
(
classInterNode
)
else
:
# interfaceNode, get their methods to prep for SIT
interM
+=
classInterNode
.
methods
classInterNode
.
subTypeOffset
=
j
*
4
# assign each type a position in the subtype testing table
j
+=
1
# store SIT and subtype table size
for
i
in
range
(
len
(
classNodes
)):
classNodes
[
i
].
SITsize
=
len
(
interM
)
classNodes
[
i
].
subTypeSize
=
len
(
types
)
-
5
# no primitive types in subtype table
classNodes
[
i
].
subTypeOffset
=
i
*
4
# assign each type a position in the subtype testing table
for
c
in
classNodes
:
c
.
SITsize
=
len
(
interM
)
c
.
subTypeSize
=
j
# no primitive types in subtype table
# prep SIT
for
i
in
range
(
len
(
interM
)):
...
...
This diff is collapsed.
Click to expand it.
ExprPrimaryNodes.py
+
15
−
0
View file @
31e6fcb1
...
...
@@ -327,6 +327,21 @@ class AssignNode(ASTNode):
self
.
code
=
self
.
right
.
code
self
.
code
+=
p
(
"
push
"
,
"
eax
"
)
# array assign check
if
self
.
left
.
__class__
.
__name__
==
"
ArrayAccessNode
"
and
(
not
self
.
left
.
myType
.
isPrimitive
):
self
.
code
+=
"
; array assign subtype check
\n
"
self
.
left
.
array
.
codeGen
()
self
.
code
+=
self
.
left
.
array
.
code
offset
=
self
.
right
.
myType
.
typePointer
.
subTypeOffset
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[eax]
"
,
"
start subtype test
"
)
# access class tag of left object
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx + 4]
"
)
# access subtype testing column
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx +
"
+
str
(
offset
)
+
"
]
"
)
# ebx has isSubtype
# exception if not subtype, else do nothing (object is already in eax)
self
.
code
+=
p
(
"
cmp
"
,
"
[G__Zero]
"
,
"
ebx
"
)
self
.
code
+=
p
(
"
je
"
,
"
H__Throw_Exception
"
)
self
.
code
+=
(
"
; Evaluate left of assignment
\n
"
)
self
.
code
+=
self
.
left
.
addr
()
...
...
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