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
1a7cbc93
Commit
1a7cbc93
authored
4 years ago
by
Nicholas Wesley Robinson
Browse files
Options
Downloads
Patches
Plain Diff
populate strliteral char array
parent
d466a367
No related branches found
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
+20
-2
20 additions, 2 deletions
UnitNodes.py
with
20 additions
and
2 deletions
UnitNodes.py
+
20
−
2
View file @
1a7cbc93
...
...
@@ -65,12 +65,15 @@ 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
]
# FIRST: create char array for this string TODO figure out how to populate this array
# 1. Allocating space for the char array in heap
# Note: uses ecx to temporarily store the array length
self
.
code
+=
"
;Start of char array creation
\n
"
+
\
p
(
instruction
=
"
push
"
,
arg1
=
"
eax
"
,
arg2
=
str
(
len
(
self
.
value
)),
comment
=
"
array length
"
)
+
\
p
(
instruction
=
"
mov
"
,
arg1
=
"
eax
"
,
arg2
=
str
(
len
(
value
)),
comment
=
"
array length
"
)
+
\
p
(
instruction
=
"
push
"
,
arg1
=
"
ecx
"
,
comment
=
"
saving ecx
'
s value
"
)
+
\
p
(
instruction
=
"
mov
"
,
arg1
=
"
ecx
"
,
arg2
=
"
eax
"
,
comment
=
"
ecx now stroes the array
'
s length
"
)
+
\
p
(
instruction
=
"
add
"
,
arg1
=
"
eax
"
,
arg2
=
2
,
comment
=
"
number of items to allocate on heap
"
)
+
\
...
...
@@ -85,7 +88,22 @@ class LiteralNode(ASTNode):
# 3. Storing length in the second slot
self
.
code
+=
p
(
instruction
=
"
mov
"
,
arg1
=
"
[eax+4]
"
,
arg2
=
"
ecx
"
,
comment
=
"
storing array length in second slot
"
)
# 4. Restoring ecx
# 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
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
+=
"
;End of populating char array
\n
"
# 5. Restoring ecx
self
.
code
+=
p
(
instruction
=
"
pop
"
,
arg1
=
"
ecx
"
,
comment
=
"
restoring register ecx
"
)
self
.
code
+=
"
;End of char array creation
\n
"
...
...
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