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
be4d8bf8
Commit
be4d8bf8
authored
4 years ago
by
Nicholas Wesley Robinson
Browse files
Options
Downloads
Patches
Plain Diff
literal string improvements
parent
d622e05f
No related branches found
Branches containing commit
No related tags found
3 merge requests
!30
New new string
,
!27
String concat
,
!20
Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
UnitNodes.py
+9
-11
9 additions, 11 deletions
UnitNodes.py
with
9 additions
and
11 deletions
UnitNodes.py
+
9
−
11
View file @
be4d8bf8
...
...
@@ -90,17 +90,9 @@ class LiteralNode(ASTNode):
# 4. populate array with this string literal's chars
self
.
code
+=
"
;Start of populating char array
\n
"
# 4.1. store array pointer
self
.
code
+=
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
comment
=
"
push arrray pointer
"
)
# 4.2. point to a[0]
self
.
code
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
eax
"
,
arg2
=
8
,
comment
=
"
eax points at a[0]
"
)
# 4.3. loop through string
# loop through string
for
i
in
range
(
len
(
value
)):
if
i
!=
0
:
self
.
code
+=
p
(
instruction
=
"
add
"
,
arg1
=
"
eax
"
,
arg2
=
4
,
comment
=
"
eax points at a[
"
+
str
(
i
)
+
"
]
"
)
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax]
"
,
arg2
=
str
(
"
dword
'"
+
value
[
i
]
+
"'"
),
comment
=
"
a[
"
+
str
(
i
)
+
"
]=
"
+
str
(
value
[
i
]))
# 4.4. restore array pointer
self
.
code
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
eax
"
,
comment
=
"
eax is pointer to array
"
)
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax+
"
+
str
(
8
+
i
*
4
)
+
"
]
"
,
arg2
=
str
(
"
dword
'"
+
value
[
i
]
+
"'"
),
comment
=
"
a[
"
+
str
(
i
)
+
"
]=
"
+
str
(
value
[
i
]))
self
.
code
+=
"
;End of populating char array
\n
"
# 5. Restoring ecx
...
...
@@ -109,6 +101,9 @@ class LiteralNode(ASTNode):
# 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
"
)
# 1. alloc enough space for this object
classDef
=
self
.
env
.
getNode
(
'
java.lang.String
'
,
'
type
'
)
fieldOffset
=
classDef
.
fieldOffset
...
...
@@ -122,11 +117,14 @@ class LiteralNode(ASTNode):
self
.
code
+=
importHelper
(
classDef
.
name
,
self
.
typeName
,
"
C_
"
+
classDef
.
name
)
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax]
"
,
arg2
=
"
dword C_
"
+
classDef
.
name
,
comment
=
"
first item is vtable pointer
"
)
# restore pointer to our char array
self
.
code
+=
p
(
"
pop
"
,
"
ebx
"
,
comment
=
"
restore pointer to our char array
"
)
# 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
(
"
mov
"
,
"
e
a
x
"
,
aLabel
)
# TODO this is probably wrong, where is my array I just created?
self
.
code
+=
p
(
"
push
"
,
"
e
b
x
"
,
comment
=
"
add our char array as arg
"
)
# 4. call String::String(char[] chars)
label
=
"
M_String_String_char
"
...
...
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