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
e64a8362
Commit
e64a8362
authored
4 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
constructor params, push object last at constructor
parent
32c6f60d
No related branches found
Branches containing commit
No related tags found
2 merge requests
!30
New new string
,
!20
Master
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ExprPrimaryNodes.py
+14
-10
14 additions, 10 deletions
ExprPrimaryNodes.py
MemberNodes.py
+8
-0
8 additions, 0 deletions
MemberNodes.py
UnitNodes.py
+6
-5
6 additions, 5 deletions
UnitNodes.py
with
28 additions
and
15 deletions
ExprPrimaryNodes.py
+
14
−
10
View file @
e64a8362
...
...
@@ -169,7 +169,7 @@ class ArrayAccessNode(ASTNode):
if
not
self
.
index
.
myType
.
isNum
():
raise
Exception
(
"
ERROR: Array index must be a number.
"
)
self
.
myType
=
TypeStruct
(
self
.
array
.
myType
.
name
,
self
.
array
.
myType
.
typePointer
)
def
getIfFalse
(
self
,
label
):
self
.
codeGen
()
return
self
.
code
+
p
(
"
cmp
"
,
"
eax
"
,
"
[G__Zero]
"
)
+
p
(
"
je
"
,
label
)
...
...
@@ -497,18 +497,22 @@ class ClassCreateNode(ASTNode):
# 3. Calling constructor
self
.
code
+=
"
; Calling constructor for object
\n
"
self
.
code
+=
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
pushing object as first argument
"
)
# Evaluate arguments
and pushing parameters
# Evaluate arguments
if
self
.
args
and
hasattr
(
self
.
args
,
"
codeGen
"
):
self
.
args
.
codeGen
()
if
not
hasattr
(
self
.
args
,
"
code
"
):
self
.
args
.
codeGen
()
self
.
code
+=
self
.
args
.
code
self
.
code
+=
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
pushing object as last argument
"
)
label
=
"
M_
"
+
self
.
cons
.
typeName
+
"
_
"
+
self
.
cons
.
name
+
"
_
"
+
self
.
cons
.
paramTypes
self
.
code
+=
importHelper
(
classDef
.
name
,
self
.
typeName
,
label
)
self
.
code
+=
p
(
instruction
=
"
call
"
,
arg1
=
label
,
comment
=
"
Calling constructor
"
)
# 4. Popping parameters and pointer to object
self
.
code
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
esp
"
,
arg2
=
len
(
self
.
args
.
exprs
)
*
4
,
comment
=
"
Popping parameters
"
)
+
\
p
(
instruction
=
"
pop
"
,
arg1
=
"
eax
"
,
comment
=
"
eax now contains pointer to newly created object
"
)
self
.
code
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
eax
"
,
comment
=
"
eax now contains pointer to newly created object
"
)
self
.
code
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
esp
"
,
arg2
=
len
(
self
.
args
.
exprs
)
*
4
,
comment
=
"
Popping parameters
"
)
self
.
code
+=
"
;End of object creation
\n
"
...
...
@@ -590,7 +594,7 @@ class ExprNode(ASTNode):
self
.
myType
.
link
(
self
.
env
)
# var1 + var2 === String.valueOf(var1).concat( String.valueOf(var2) )
# methodInvoc name LPAREN args RPAREN (because it's static)
# MethodInvNode
# ID = NameNode
...
...
@@ -612,7 +616,7 @@ class ExprNode(ASTNode):
# valueOfMethodInvLeft.checkType()
# valueOfMethodInvRight.checkType()
# methodInvoc primary PERIOD ID LPAREN args RPAREN
# MethodInvNode
# primary = self.left
...
...
@@ -630,7 +634,7 @@ class ExprNode(ASTNode):
self
.
concatMethodInv
=
MethodInvNode
(
self
.
parseTree
,
self
.
typeName
,
concatNameNode
,
rightArgMethodInv
,
valueOfMethodInvLeft
)
# 4. Check type to be safe
self
.
concatMethodInv
.
checkType
()
return
raise
Exception
(
"
ERROR: Incompatible types. Left of {} type can
'
t be used with right of {} type on operation {}
"
.
format
(
self
.
left
.
myType
.
name
,
self
.
right
.
myType
.
name
,
self
.
op
))
...
...
@@ -939,7 +943,7 @@ class FieldAccessNode(ASTNode):
checkProtected
(
self
.
ID
.
prefixLink
,
self
)
except
:
# where there are no mods
return
def
getIfFalse
(
self
,
label
):
self
.
codeGen
()
return
self
.
code
+
p
(
"
cmp
"
,
"
eax
"
,
"
[G__Zero]
"
)
+
p
(
"
je
"
,
label
)
...
...
This diff is collapsed.
Click to expand it.
MemberNodes.py
+
8
−
0
View file @
e64a8362
...
...
@@ -260,6 +260,14 @@ class MethodNode(ASTNode):
if
hasattr
(
self
,
"
code
"
)
and
self
.
code
!=
""
:
return
# populate param offsets
# params
stackoffset
=
12
rparams
=
self
.
params
.
copy
()
rparams
.
reverse
()
for
i
,
param
in
enumerate
(
rparams
):
param
.
offset
=
i
*
4
+
stackoffset
# 12 since the stack is now of the order: ebp, eip, o, params
myClass
=
self
.
env
.
getNode
(
self
.
typeName
,
'
type
'
)
self
.
label
=
"
M_
"
+
self
.
typeName
+
"
_
"
+
self
.
name
+
"
_
"
+
self
.
paramTypes
...
...
This diff is collapsed.
Click to expand it.
UnitNodes.py
+
6
−
5
View file @
e64a8362
...
...
@@ -65,7 +65,7 @@ class LiteralNode(ASTNode):
self
.
code
+=
"
;Start of String Literal Creation for class
"
+
self
.
typeName
+
"
\n
"
# generate array of characters
# then call new String(array)
# remove quotation marks
value
=
self
.
value
[
1
:
-
1
]
...
...
@@ -84,7 +84,7 @@ class LiteralNode(ASTNode):
aLabel
=
"
A_char
"
self
.
code
+=
p
(
instruction
=
"
extern
"
,
arg1
=
aLabel
)
+
\
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax]
"
,
arg2
=
"
dword
"
+
aLabel
,
comment
=
"
first item is vtable pointer
"
)
# 3. Storing length in the second slot
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax+4]
"
,
arg2
=
"
ecx
"
,
comment
=
"
storing array length in second slot
"
)
...
...
@@ -99,7 +99,7 @@ class LiteralNode(ASTNode):
self
.
code
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
ecx
"
,
comment
=
"
restoring register ecx
"
)
self
.
code
+=
"
;End of char array creation
\n
"
# SECOND: create new string object with the char array
# SECOND: create new string object with the char array
# push array pointer
self
.
code
+=
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
save pointer to char array
"
)
...
...
@@ -122,9 +122,10 @@ class LiteralNode(ASTNode):
# 3. Calling constructor
self
.
code
+=
"
; Calling constructor for String
\n
"
self
.
code
+=
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
pushing object as first argument
"
)
# Evaluate arguments and pushing parameters
self
.
code
+=
p
(
"
push
"
,
"
ebx
"
,
comment
=
"
add our char array as arg
"
)
self
.
code
+=
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
pushing object as last argument
"
)
# 4. call String::String(char[] chars)
label
=
"
M_String_String_char
"
...
...
@@ -132,8 +133,8 @@ class LiteralNode(ASTNode):
self
.
code
+=
p
(
instruction
=
"
call
"
,
arg1
=
label
,
comment
=
"
Calling constructor
"
)
# 4. Popping parameters and pointer to object
self
.
code
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
esp
"
,
arg2
=
4
,
comment
=
"
Popping parameters
"
)
self
.
code
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
eax
"
,
comment
=
"
eax now contains pointer to newly created object
"
)
self
.
code
+=
p
(
"
add
"
,
"
esp
"
,
"
4
"
,
"
Popping parameters
"
)
self
.
code
+=
"
;End of object creation
\n
"
self
.
code
+=
"
;End of String Literal Creation for class
"
+
self
.
typeName
+
"
\n
"
return
...
...
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