Skip to content
Snippets Groups Projects
Commit dabb2268 authored by carha197's avatar carha197
Browse files

Fixed lab 5

parent 6a11acc5
No related branches found
No related tags found
No related merge requests found
...@@ -2,14 +2,12 @@ macro doWhile(block, cond) ...@@ -2,14 +2,12 @@ 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 = esc(quote
while true $block
$(esc(block)) while $cond
if $(esc(cond)) $block
break
end
end end
end end)
println(res) # Should not print any lines referencing dowhile.jl println(res.args) # Should not print any lines referencing dowhile.jl
res res
end end
...@@ -41,6 +41,6 @@ function testDoWhile() ...@@ -41,6 +41,6 @@ function testDoWhile()
@assert a < 18 @assert a < 18
a += 1 a += 1
println(a) println(a)
end a==100 end a < 100
end end
testDoWhile() testDoWhile()
- # This file is a part of Julia. License is MIT: https://julialang.org/license
-
- ==(w::WeakRef, v::WeakRef) = isequal(w.value, v.value)
- ==(w::WeakRef, v) = isequal(w.value, v)
- ==(w, v::WeakRef) = isequal(w, v.value)
-
- """
- finalizer(f, x)
-
- Register a function `f(x)` to be called when there are no program-accessible references to
- `x`, and return `x`. The type of `x` must be a `mutable struct`, otherwise the behavior of
- this function is unpredictable.
- """
- function finalizer(@nospecialize(f), @nospecialize(o))
- if isimmutable(o)
- error("objects of type ", typeof(o), " cannot be finalized")
- end
- ccall(:jl_gc_add_finalizer_th, Cvoid, (Ptr{Cvoid}, Any, Any),
- Core.getptls(), o, f)
- return o
- end
-
- function finalizer(f::Ptr{Cvoid}, o::T) where T
- @_inline_meta
- if isimmutable(T)
- error("objects of type ", T, " cannot be finalized")
- end
- ccall(:jl_gc_add_ptr_finalizer, Cvoid, (Ptr{Cvoid}, Any, Ptr{Cvoid}),
- Core.getptls(), o, f)
- return o
- end
-
- """
- finalize(x)
-
- Immediately run finalizers registered for object `x`.
- """
- finalize(@nospecialize(o)) = ccall(:jl_finalize_th, Cvoid, (Ptr{Cvoid}, Any,),
- Core.getptls(), o)
-
- """
- Base.GC
-
- Module with garbage collection utilities.
- """
- module GC
-
- """
- GC.gc()
-
- Perform garbage collection.
-
- !!! warning
- Excessive use will likely lead to poor performance.
- """
- gc(full::Bool=true) = ccall(:jl_gc_collect, Cvoid, (Int32,), full)
-
- """
- GC.enable(on::Bool)
-
- Control whether garbage collection is enabled using a boolean argument (`true` for enabled,
- `false` for disabled). Return previous GC state.
-
- !!! warning
- Disabling garbage collection should be used only with caution, as it can cause memory
- use to grow without bound.
- """
- enable(on::Bool) = ccall(:jl_gc_enable, Int32, (Int32,), on) != 0
-
- """
- GC.@preserve x1 x2 ... xn expr
-
- Temporarily protect the given objects from being garbage collected, even if they would
- otherwise be unreferenced.
-
- The last argument is the expression during which the object(s) will be preserved.
- The previous arguments are the objects to preserve.
- """
- macro preserve(args...)
- syms = args[1:end-1]
- for x in syms
- isa(x, Symbol) || error("Preserved variable must be a symbol")
- end
- s, r = gensym(), gensym()
- esc(quote
2824 $s = $(Expr(:gc_preserve_begin, syms...))
2824 $r = $(args[end])
2824 $(Expr(:gc_preserve_end, s))
- $r
- end)
- end
-
- end # module GC
-
- # This file is a part of Julia. License is MIT: https://julialang.org/license
-
- ==(w::WeakRef, v::WeakRef) = isequal(w.value, v.value)
- ==(w::WeakRef, v) = isequal(w.value, v)
- ==(w, v::WeakRef) = isequal(w, v.value)
-
- """
- finalizer(f, x)
-
- Register a function `f(x)` to be called when there are no program-accessible references to
- `x`, and return `x`. The type of `x` must be a `mutable struct`, otherwise the behavior of
- this function is unpredictable.
- """
- function finalizer(@nospecialize(f), @nospecialize(o))
- if isimmutable(o)
- error("objects of type ", typeof(o), " cannot be finalized")
- end
- ccall(:jl_gc_add_finalizer_th, Cvoid, (Ptr{Cvoid}, Any, Any),
- Core.getptls(), o, f)
- return o
- end
-
- function finalizer(f::Ptr{Cvoid}, o::T) where T
- @_inline_meta
- if isimmutable(T)
- error("objects of type ", T, " cannot be finalized")
- end
- ccall(:jl_gc_add_ptr_finalizer, Cvoid, (Ptr{Cvoid}, Any, Ptr{Cvoid}),
- Core.getptls(), o, f)
- return o
- end
-
- """
- finalize(x)
-
- Immediately run finalizers registered for object `x`.
- """
- finalize(@nospecialize(o)) = ccall(:jl_finalize_th, Cvoid, (Ptr{Cvoid}, Any,),
- Core.getptls(), o)
-
- """
- Base.GC
-
- Module with garbage collection utilities.
- """
- module GC
-
- """
- GC.gc()
-
- Perform garbage collection.
-
- !!! warning
- Excessive use will likely lead to poor performance.
- """
- gc(full::Bool=true) = ccall(:jl_gc_collect, Cvoid, (Int32,), full)
-
- """
- GC.enable(on::Bool)
-
- Control whether garbage collection is enabled using a boolean argument (`true` for enabled,
- `false` for disabled). Return previous GC state.
-
- !!! warning
- Disabling garbage collection should be used only with caution, as it can cause memory
- use to grow without bound.
- """
- enable(on::Bool) = ccall(:jl_gc_enable, Int32, (Int32,), on) != 0
-
- """
- GC.@preserve x1 x2 ... xn expr
-
- Temporarily protect the given objects from being garbage collected, even if they would
- otherwise be unreferenced.
-
- The last argument is the expression during which the object(s) will be preserved.
- The previous arguments are the objects to preserve.
- """
- macro preserve(args...)
- syms = args[1:end-1]
- for x in syms
- isa(x, Symbol) || error("Preserved variable must be a symbol")
- end
- s, r = gensym(), gensym()
- esc(quote
2 $s = $(Expr(:gc_preserve_begin, syms...))
2 $r = $(args[end])
2 $(Expr(:gc_preserve_end, s))
- $r
- end)
- end
-
- end # module GC
-
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -15,18 +15,17 @@ end ...@@ -15,18 +15,17 @@ end
f() f()
#@time f()
@time f() #@profile f()
@profile f() #@allocated f()
@allocated f() #x = @benchmark f()
x = @benchmark f()
println() println()
println(x) #println(x)
Profile.print(); #Profile.print();
#./julia-1.0.4/bin/julia --track-allocation=user #./julia-1.0.4/bin/julia --track-allocation=user --code-coverage=user
#include("test.jl") #include("test.jl")
#ctrl d #ctrl d
#emacs test.jl.mem #emacs test.jl.mem
- using BenchmarkTools
- using Random
- using Profile
-
-
- function f()
2818 lst = rand(50000)
2818 for i in lst
140900000 if i > 0.99
- s = "List entry $(i)\r" # The \r makes it so the terminal isn't filled
142307721 print(s)
- end
- end
- end
-
- f()
-
- @time f()
- @profile f()
- @allocated f()
- x = @benchmark f()
- println()
- println(x)
- Profile.print();
-
-
-
- #./julia-1.0.4/bin/julia --track-allocation=user --code-coverage=user
- #include("test.jl")
- #ctrl d
- #emacs test.jl.mem
-
- using BenchmarkTools
- using Random
- using Profile
-
-
- function f()
1 lst = rand(50000)
1 for i in lst
50000 if i > 0.99
- s = "List entry $(i)\r" # The \r makes it so the terminal isn't filled
50486 print(s)
- end
- end
- end
-
- f()
-
- #@time f()
- #@profile f()
- #@allocated f()
- #x = @benchmark f()
- println()
- #println(x)
- #Profile.print();
-
-
-
- #./julia-1.0.4/bin/julia --track-allocation=user --code-coverage=user
- #include("test.jl")
- #ctrl d
- #emacs test.jl.mem
-
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment