Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab5-metaprogramming-and-debugging-lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Måns Fredriksson Franzén
lab5-metaprogramming-and-debugging-lab
Commits
435c0938
Commit
435c0938
authored
5 years ago
by
simsc266
Browse files
Options
Downloads
Patches
Plain Diff
commiting 1 and 2
parent
9aff870b
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
debugging/dividearrays.cpp
+8
-1
8 additions, 1 deletion
debugging/dividearrays.cpp
julia/dowhile.jl
+14
-3
14 additions, 3 deletions
julia/dowhile.jl
julia/run.jl
+16
-0
16 additions, 0 deletions
julia/run.jl
profiling/test.jl
+8
-1
8 additions, 1 deletion
profiling/test.jl
with
46 additions
and
5 deletions
debugging/dividearrays.cpp
+
8
−
1
View file @
435c0938
...
@@ -9,7 +9,14 @@ int main(int argc, char **argv)
...
@@ -9,7 +9,14 @@ int main(int argc, char **argv)
for
(
int
i
=
0
;
i
<
1024
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1024
;
i
++
)
{
int
nom
=
intdist
(
generator
);
int
nom
=
intdist
(
generator
);
int
denom
=
intdist
(
generator
);
int
denom
=
intdist
(
generator
);
res
[
i
]
=
nom
/
denom
;
res
[
i
]
=
nom
/
denom
;
}
}
return
0
;
return
0
;
}
}
/*Program received signal SIGFPE, Arithmetic exception.
0x0000555555554bb9 in main (argc=1, argv=0x7fffffffd688) at dividearrays.cpp:13
13 res[i] = nom / denom;
cant divide if denom = 0. Solve by checking if denom == 0.*/
This diff is collapsed.
Click to expand it.
julia/dowhile.jl
+
14
−
3
View file @
435c0938
macro
doWhile
(
block
,
cond
)
macro
doWhile
(
block
,
cond
)
println
(
"__source__ "
,
__source__
)
println
(
"__source__ "
,
__source__
)
println
(
"cond "
,
cond
)
println
(
"cond "
,
cond
)
println
(
"block "
,
block
)
println
(
"block "
,
block
)
res
=
quote
res
=
quote
error
(
"TODO: Your code here"
)
while
true
$
(
esc
(
block
))
if
$
(
esc
(
cond
))
break
end
end
end
end
println
(
res
)
# Should not print any lines referencing dowhile.jl
res
# println(res) # Should not print any lines referencing dowhile.jl
res
.
args
[
1
]
.
striplines
end
end
This diff is collapsed.
Click to expand it.
julia/run.jl
+
16
−
0
View file @
435c0938
"""Template programming is a sort of metaprogramming where you fill
"""Template programming is a sort of metaprogramming where you fill
in the blanks, but most parts of the code are very similar."""
in the blanks, but most parts of the code are very similar."""
for
(
name
,
op
)
in
[(
:
add
,
:+
),
(
:
sub
,
:-
),
(
:
mul
,
:*
)]
for
(
name
,
op
)
in
[(
:
add
,
:+
),
(
:
sub
,
:-
),
(
:
mul
,
:*
)]
# Create a function that is named for example add and returns the
# Create a function that is named for example add and returns the
# sum of its two arguments
# sum of its two arguments
@eval
$
name
(
x
,
y
)
=
$
op
(
x
,
y
)
end
end
@assert
3
==
add
(
1
,
2
)
@assert
3
==
add
(
1
,
2
)
@assert
-
1.0
==
sub
(
1.0
,
2.0
)
@assert
-
1.0
==
sub
(
1.0
,
2.0
)
@assert
"abc"
==
mul
(
"ab"
,
"c"
)
@assert
"abc"
==
mul
(
"ab"
,
"c"
)
...
@@ -18,7 +25,13 @@ module Problem1
...
@@ -18,7 +25,13 @@ module Problem1
f
(
a
::
Int
)
=
1
f
(
a
::
Int
)
=
1
f
(
a
::
Any
)
=
2
f
(
a
::
Any
)
=
2
end
end
# TODO: Delete the method f(a::Int) so that f(1) returns the value 2 instead of 1
# TODO: Delete the method f(a::Int) so that f(1) returns the value 2 instead of 1
Base
.
delete_method
(
which
(
Problem1
.
f
,(
Int
,)))
@assert
2
==
Problem1
.
f
(
1
)
@assert
2
==
Problem1
.
f
(
1
)
# TODO: Make an until block for Julia, similar to do {} while (cond); in C
# TODO: Make an until block for Julia, similar to do {} while (cond); in C
...
@@ -26,6 +39,9 @@ end
...
@@ -26,6 +39,9 @@ end
# Make sure that any assertions and error-messages refer to lines in the original code.
# Make sure that any assertions and error-messages refer to lines in the original code.
# Hint: You can access a hidden input __source__ in a macro and use that to replace source information.
# Hint: You can access a hidden input __source__ in a macro and use that to replace source information.
# By having the macro in a separate file, you can check source locations that match dowhile.jl and replace them with __source__.
# By having the macro in a separate file, you can check source locations that match dowhile.jl and replace them with __source__.
include
(
"dowhile.jl"
)
include
(
"dowhile.jl"
)
function
testDoWhile
()
function
testDoWhile
()
local
a
=
5
local
a
=
5
...
...
This diff is collapsed.
Click to expand it.
profiling/test.jl
+
8
−
1
View file @
435c0938
using
Profile
using
BenchmarkTools
using
BenchmarkTools
using
Random
using
Random
function
f
()
function
f
()
lst
=
rand
(
50000
)
lst
=
rand
(
50000
)
for
i
in
lst
for
i
in
lst
s
=
"List entry
$(i)
\r
"
# The \r makes it so the terminal isn't filled
s
=
"List entry
$(i)
\r
"
# The \r makes it so the terminal isn't filled
if
i
>
0.99
if
i
>
0.99
print
(
s
)
print
(
s
)
end
end
end
end
end
end
@profile
f
()
Profile
.
print
()
f
()
f
()
@time
f
()
@time
f
()
x
=
@benchmark
f
()
x
=
@benchmark
f
()
...
...
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