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
b66154a4
Commit
b66154a4
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
cast instanceof for primitive types
parent
5cf8a149
No related branches found
Branches containing commit
No related tags found
2 merge requests
!22
Subtype test
,
!20
Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ExprPrimaryNodes.py
+24
-19
24 additions, 19 deletions
ExprPrimaryNodes.py
with
24 additions
and
19 deletions
ExprPrimaryNodes.py
+
24
−
19
View file @
b66154a4
...
@@ -293,7 +293,6 @@ class CastNode(ASTNode):
...
@@ -293,7 +293,6 @@ class CastNode(ASTNode):
def
checkType
(
self
):
def
checkType
(
self
):
self
.
left
.
checkType
()
self
.
left
.
checkType
()
from
pprint
import
pprint
self
.
right
.
disambigName
()
self
.
right
.
disambigName
()
self
.
right
.
checkType
()
self
.
right
.
checkType
()
if
(
self
.
left
.
myType
.
isNum
()
and
self
.
right
.
myType
.
isNum
())
\
if
(
self
.
left
.
myType
.
isNum
()
and
self
.
right
.
myType
.
isNum
())
\
...
@@ -308,22 +307,22 @@ class CastNode(ASTNode):
...
@@ -308,22 +307,22 @@ class CastNode(ASTNode):
return
return
self
.
code
=
""
self
.
code
=
""
print
(
self
.
left
.
myType
.
name
,
self
.
typeName
)
offset
=
self
.
left
.
myType
.
typePointer
.
subTypeOffset
# get object at right
# get object at right
self
.
code
+=
"
; casting
\n
"
self
.
code
+=
"
; casting
\n
"
self
.
right
.
codeGen
()
self
.
right
.
codeGen
()
self
.
code
+=
self
.
right
.
code
self
.
code
+=
self
.
right
.
code
# subtype test
# subtype test:
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[eax]
"
,
"
start subtype test
"
)
# access class tag of left object
if
not
self
.
left
.
myType
.
isPrimitive
:
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx + 4]
"
)
# access subtype testing column
# only test if right is not primitive (primitive types would be correctly static tested already)
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx +
"
+
str
(
offset
)
+
"
]
"
)
# ebx has isSubtype
offset
=
self
.
left
.
myType
.
typePointer
.
subTypeOffset
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[eax]
"
,
"
start subtype test
"
)
# access class tag of left object
# exception if not subtype, else do nothing (object is already in eax)
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx + 4]
"
)
# access subtype testing column
self
.
code
+=
p
(
"
cmp
"
,
"
[G__Zero]
"
,
"
ebx
"
)
self
.
code
+=
p
(
"
mov
"
,
"
ebx
"
,
"
[ebx +
"
+
str
(
offset
)
+
"
]
"
)
# ebx has isSubtype
self
.
code
+=
p
(
"
je
"
,
"
H__Throw_Exception
"
)
# 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
+=
"
; end of casting
\n
"
self
.
code
+=
"
; end of casting
\n
"
###################################################################################
###################################################################################
...
@@ -500,14 +499,22 @@ class ExprNode(ASTNode):
...
@@ -500,14 +499,22 @@ class ExprNode(ASTNode):
# instanceOf
# instanceOf
if
self
.
op
==
"
instanceof
"
:
if
self
.
op
==
"
instanceof
"
:
offset
=
self
.
right
.
myType
.
typePointer
.
subTypeOffset
self
.
code
+=
(
"
; evaluate instanceof
\n
"
)
self
.
code
+=
(
"
; evaluate instanceof
\n
"
)
self
.
left
.
codeGen
()
self
.
left
.
codeGen
()
self
.
code
+=
self
.
left
.
code
self
.
code
+=
self
.
left
.
code
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax]
"
)
# access class tag of left object
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax + 4]
"
)
# access subtype testing column
# only test if non-primitive
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax +
"
+
str
(
offset
)
+
"
]
"
)
# subType column stores 0 or 1 already
if
not
self
.
right
.
myType
.
isPrimitive
:
offset
=
self
.
right
.
myType
.
typePointer
.
subTypeOffset
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax]
"
)
# access class tag of left object
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax + 4]
"
)
# access subtype testing column
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
[eax +
"
+
str
(
offset
)
+
"
]
"
)
# subType column stores 0 or 1 already
else
:
# primitive type can be staticly evaluated
if
self
.
right
.
myType
.
assignable
(
self
.
left
.
myType
):
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
1
"
)
else
:
self
.
code
+=
p
(
"
mov
"
,
"
eax
"
,
"
0
"
)
self
.
code
+=
(
"
; end of instanceof
\n
"
)
self
.
code
+=
(
"
; end of instanceof
\n
"
)
return
return
...
@@ -614,8 +621,6 @@ class ExprNode(ASTNode):
...
@@ -614,8 +621,6 @@ class ExprNode(ASTNode):
self
.
code
+=
p
(
'
pop
'
,
'
edx
'
)
# restore edx
self
.
code
+=
p
(
'
pop
'
,
'
edx
'
)
# restore edx
return
return
# if self.op == 'instanceof': TODO
# return
# generate shorter code if self.op = comparison
# generate shorter code if self.op = comparison
def
getIfFalse
(
self
,
label
):
def
getIfFalse
(
self
,
label
):
...
...
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