mollusk 0e4acfb8f2 fix incorrect folder name for julia-0.6.x
Former-commit-id: ef2c7401e0876f22d2f7762d182cfbcd5a7d9c70
2018-06-11 03:28:36 -07:00

19 lines
28 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Initialization of the Julia runtime · The Julia Language</title><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-28835595-6', 'auto');
ga('send', 'pageview');
</script><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link href="../assets/documenter.css" rel="stylesheet" type="text/css"/><link href="../assets/julia-manual.css" rel="stylesheet" type="text/css"/></head><body><nav class="toc"><a href="../index.html"><img class="logo" src="../assets/logo.png" alt="The Julia Language logo"/></a><h1>The Julia Language</h1><select id="version-selector" onChange="window.location.href=this.value" style="visibility: hidden"></select><form class="search" id="search-form" action="../search.html"><input id="search-query" name="q" type="text" placeholder="Search docs"/></form><ul><li><a class="toctext" href="../index.html">Home</a></li><li><span class="toctext">Manual</span><ul><li><a class="toctext" href="../manual/introduction.html">Introduction</a></li><li><a class="toctext" href="../manual/getting-started.html">Getting Started</a></li><li><a class="toctext" href="../manual/variables.html">Variables</a></li><li><a class="toctext" href="../manual/integers-and-floating-point-numbers.html">Integers and Floating-Point Numbers</a></li><li><a class="toctext" href="../manual/mathematical-operations.html">Mathematical Operations and Elementary Functions</a></li><li><a class="toctext" href="../manual/complex-and-rational-numbers.html">Complex and Rational Numbers</a></li><li><a class="toctext" href="../manual/strings.html">Strings</a></li><li><a class="toctext" href="../manual/functions.html">Functions</a></li><li><a class="toctext" href="../manual/control-flow.html">Control Flow</a></li><li><a class="toctext" href="../manual/variables-and-scoping.html">Scope of Variables</a></li><li><a class="toctext" href="../manual/types.html">Types</a></li><li><a class="toctext" href="../manual/methods.html">Methods</a></li><li><a class="toctext" href="../manual/constructors.html">Constructors</a></li><li><a class="toctext" href="../manual/conversion-and-promotion.html">Conversion and Promotion</a></li><li><a class="toctext" href="../manual/interfaces.html">Interfaces</a></li><li><a class="toctext" href="../manual/modules.html">Modules</a></li><li><a class="toctext" href="../manual/documentation.html">Documentation</a></li><li><a class="toctext" href="../manual/metaprogramming.html">Metaprogramming</a></li><li><a class="toctext" href="../manual/arrays.html">Multi-dimensional Arrays</a></li><li><a class="toctext" href="../manual/linear-algebra.html">Linear algebra</a></li><li><a class="toctext" href="../manual/networking-and-streams.html">Networking and Streams</a></li><li><a class="toctext" href="../manual/parallel-computing.html">Parallel Computing</a></li><li><a class="toctext" href="../manual/dates.html">Date and DateTime</a></li><li><a class="toctext" href="../manual/interacting-with-julia.html">Interacting With Julia</a></li><li><a class="toctext" href="../manual/running-external-programs.html">Running External Programs</a></li><li><a class="toctext" href="../manual/calling-c-and-fortran-code.html">Calling C and Fortran Code</a></li><li><a class="toctext" href="../manual/handling-operating-system-variation.html">Handling Operating System Variation</a></li><li><a class="toctext" href="../manual/environment-variables.html">Environment Variables</a></li><li><a class="toctext" href="../manual/embedding.html">Embedding Julia</a></li><li><a class="toctext" href="../manual/packages.html">Packages</a></li><li><a class="toctext" href="../manual/profile.html">Profiling</a></li><li><a class="toctext" href="../manual/stacktraces.html">Stack Traces</a></li><li><a class="toctext" href="../manual/performance-tips.html">Performance Tips</a></li><li><a class="toctext" href="../manual/workflow-tips.html">Workflow Tips</a></li><li><a class="toctext" href="../manual/style-guide.html">Style Guide</a></li><li><a class="toctext" href="../manual/faq.html">Frequently Asked Questions</a></li><li><a class="toctext" href="../manual/noteworthy-differences.html">Noteworthy Differences from other Languages</a></li><li><a class="toctext" href="../manual/unicode-input.html">Unicode Input</a></li></ul></li><li><span class="toctext">Standard Library</span><ul><li><a class="toctext" href="../stdlib/base.html">Essentials</a></li><li><a class="toctext" href="../stdlib/collections.html">Collections and Data Structures</a></li><li><a class="toctext" href="../stdlib/math.html">Mathematics</a></li><li><a class="toctext" href="../stdlib/numbers.html">Numbers</a></li><li><a class="toctext" href="../stdlib/strings.html">Strings</a></li><li><a class="toctext" href="../stdlib/arrays.html">Arrays</a></li><li><a class="toctext" href="../stdlib/parallel.html">Tasks and Parallel Computing</a></li><li><a class="toctext" href="../stdlib/linalg.html">Linear Algebra</a></li><li><a class="toctext" href="../stdlib/constants.html">Constants</a></li><li><a class="toctext" href="../stdlib/file.html">Filesystem</a></li><li><a class="toctext" href="../stdlib/io-network.html">I/O and Network</a></li><li><a class="toctext" href="../stdlib/punctuation.html">Punctuation</a></li><li><a class="toctext" href="../stdlib/sort.html">Sorting and Related Functions</a></li><li><a class="toctext" href="../stdlib/pkg.html">Package Manager Functions</a></li><li><a class="toctext" href="../stdlib/dates.html">Dates and Time</a></li><li><a class="toctext" href="../stdlib/iterators.html">Iteration utilities</a></li><li><a class="toctext" href="../stdlib/test.html">Unit Testing</a></li><li><a class="toctext" href="../stdlib/c.html">C Interface</a></li><li><a class="toctext" href="../stdlib/libc.html">C Standard Library</a></li><li><a class="toctext" href="../stdlib/libdl.html">Dynamic Linker</a></li><li><a class="toctext" href="../stdlib/profile.html">Profiling</a></li><li><a class="toctext" href="../stdlib/stacktraces.html">StackTraces</a></li><li><a class="toctext" href="../stdlib/simd-types.html">SIMD Support</a></li></ul></li><li><span class="toctext">Developer Documentation</span><ul><li><a class="toctext" href="reflection.html">Reflection and introspection</a></li><li><span class="toctext">Documentation of Julia&#39;s Internals</span><ul><li class="current"><a class="toctext" href="init.html">Initialization of the Julia runtime</a><ul class="internal"><li><a class="toctext" href="#main()-1">main()</a></li><li><a class="toctext" href="#julia_init()-1">julia_init()</a></li><li><a class="toctext" href="#true_main()-1">true_main()</a></li><li><a class="toctext" href="#Base._start-1">Base._start</a></li><li><a class="toctext" href="#Base.eval-1">Base.eval</a></li><li><a class="toctext" href="#jl_atexit_hook()-1">jl_atexit_hook()</a></li><li><a class="toctext" href="#julia_save()-1">julia_save()</a></li></ul></li><li><a class="toctext" href="ast.html">Julia ASTs</a></li><li><a class="toctext" href="types.html">More about types</a></li><li><a class="toctext" href="object.html">Memory layout of Julia Objects</a></li><li><a class="toctext" href="eval.html">Eval of Julia code</a></li><li><a class="toctext" href="callconv.html">Calling Conventions</a></li><li><a class="toctext" href="compiler.html">High-level Overview of the Native-Code Generation Process</a></li><li><a class="toctext" href="functions.html">Julia Functions</a></li><li><a class="toctext" href="cartesian.html">Base.Cartesian</a></li><li><a class="toctext" href="meta.html">Talking to the compiler (the <code>:meta</code> mechanism)</a></li><li><a class="toctext" href="subarrays.html">SubArrays</a></li><li><a class="toctext" href="sysimg.html">System Image Building</a></li><li><a class="toctext" href="llvm.html">Working with LLVM</a></li><li><a class="toctext" href="stdio.html">printf() and stdio in the Julia runtime</a></li><li><a class="toctext" href="boundscheck.html">Bounds checking</a></li><li><a class="toctext" href="locks.html">Proper maintenance and care of multi-threading locks</a></li><li><a class="toctext" href="offset-arrays.html">Arrays with custom indices</a></li><li><a class="toctext" href="libgit2.html">Base.LibGit2</a></li><li><a class="toctext" href="require.html">Module loading</a></li></ul></li><li><span class="toctext">Developing/debugging Julia&#39;s C code</span><ul><li><a class="toctext" href="backtraces.html">Reporting and analyzing crashes (segfaults)</a></li><li><a class="toctext" href="debuggingtips.html">gdb debugging tips</a></li><li><a class="toctext" href="valgrind.html">Using Valgrind with Julia</a></li><li><a class="toctext" href="sanitizers.html">Sanitizer support</a></li></ul></li></ul></li></ul></nav><article id="docs"><header><nav><ul><li>Developer Documentation</li><li>Documentation of Julia&#39;s Internals</li><li><a href="init.html">Initialization of the Julia runtime</a></li></ul><a class="edit-page" href="https://github.com/JuliaLang/julia/blob/master/doc/src/devdocs/init.md"><span class="fa"></span> Edit on GitHub</a></nav><hr/><div id="topbar"><span>Initialization of the Julia runtime</span><a class="fa fa-bars" href="#"></a></div></header><h1><a class="nav-anchor" id="Initialization-of-the-Julia-runtime-1" href="#Initialization-of-the-Julia-runtime-1">Initialization of the Julia runtime</a></h1><p>How does the Julia runtime execute <code>julia -e &#39;println(&quot;Hello World!&quot;)&#39;</code> ?</p><h2><a class="nav-anchor" id="main()-1" href="#main()-1">main()</a></h2><p>Execution starts at <a href="https://github.com/JuliaLang/julia/blob/master/ui/repl.c"><code>main()</code> in <code>ui/repl.c</code></a>.</p><p><code>main()</code> calls <a href="https://github.com/JuliaLang/julia/blob/master/src/support/libsupportinit.c"><code>libsupport_init()</code></a> to set the C library locale and to initialize the &quot;ios&quot; library (see <a href="https://github.com/JuliaLang/julia/blob/master/src/support/ios.c"><code>ios_init_stdstreams()</code></a> and <a href="stdio.html#Legacy-ios.c-library-1">Legacy <code>ios.c</code> library</a>).</p><p>Next <a href="https://github.com/JuliaLang/julia/blob/master/ui/repl.c"><code>parse_opts()</code></a> is called to process command line options. Note that <code>parse_opts()</code> only deals with options that affect code generation or early initialization. Other options are handled later by <a href="https://github.com/JuliaLang/julia/blob/master/base/client.jl"><code>process_options()</code> in <code>base/client.jl</code></a>.</p><p><code>parse_opts()</code> stores command line options in the <a href="https://github.com/JuliaLang/julia/blob/master/src/julia.h">global <code>jl_options</code> struct</a>.</p><h2><a class="nav-anchor" id="julia_init()-1" href="#julia_init()-1">julia_init()</a></h2><p><a href="https://github.com/JuliaLang/julia/blob/master/src/task.c"><code>julia_init()</code> in <code>task.c</code></a> is called by <code>main()</code> and calls <a href="https://github.com/JuliaLang/julia/blob/master/src/init.c"><code>_julia_init()</code> in <code>init.c</code></a>.</p><p><code>_julia_init()</code> begins by calling <code>libsupport_init()</code> again (it does nothing the second time).</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/signals-unix.c"><code>restore_signals()</code></a> is called to zero the signal handler mask.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/init.c"><code>jl_resolve_sysimg_location()</code></a> searches configured paths for the base system image. See <a href="sysimg.html#Building-the-Julia-system-image-1">Building the Julia system image</a>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/gc.c"><code>jl_gc_init()</code></a> sets up allocation pools and lists for weak refs, preserved values and finalization.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/ast.c"><code>jl_init_frontend()</code></a> loads and initializes a pre-compiled femtolisp image containing the scanner/parser.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/jltypes.c"><code>jl_init_types()</code></a> creates <code>jl_datatype_t</code> type description objects for the <a href="https://github.com/JuliaLang/julia/blob/master/src/julia.h">built-in types defined in <code>julia.h</code></a>. e.g.</p><pre><code class="language-c">jl_any_type = jl_new_abstracttype(jl_symbol(&quot;Any&quot;), NULL, jl_null);
jl_any_type-&gt;super = jl_any_type;
jl_type_type = jl_new_abstracttype(jl_symbol(&quot;Type&quot;), jl_any_type, jl_null);
jl_int32_type = jl_new_bitstype(jl_symbol(&quot;Int32&quot;),
jl_any_type, jl_null, 32);</code></pre><p><a href="https://github.com/JuliaLang/julia/blob/master/src/task.c"><code>jl_init_tasks()</code></a> creates the <code>jl_datatype_t* jl_task_type</code> object; initializes the global <code>jl_root_task</code> struct; and sets <code>jl_current_task</code> to the root task.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/codegen.cpp"><code>jl_init_codegen()</code></a> initializes the <a href="http://llvm.org">LLVM library</a>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/dump.c"><code>jl_init_serializer()</code></a> initializes 8-bit serialization tags for 256 frequently used <code>jl_value_t</code> values. The serialization mechanism uses these tags as shorthand (in lieu of storing whole objects) to save storage space.</p><p>If there is no sysimg file (<code>!jl_options.image_file</code>) then the <code>Core</code> and <code>Main</code> modules are created and <code>boot.jl</code> is evaluated:</p><p><code>jl_core_module = jl_new_module(jl_symbol(&quot;Core&quot;))</code> creates the Julia <code>Core</code> module.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/intrinsics.cpp"><code>jl_init_intrinsic_functions()</code></a> creates a new Julia module <code>Intrinsics</code> containing constant <code>jl_intrinsic_type</code> symbols. These define an integer code for each <a href="https://github.com/JuliaLang/julia/blob/master/src/intrinsics.cpp">intrinsic function</a>. <a href="https://github.com/JuliaLang/julia/blob/master/src/intrinsics.cpp"><code>emit_intrinsic()</code></a> translates these symbols into LLVM instructions during code generation.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/builtins.c"><code>jl_init_primitives()</code></a> hooks C functions up to Julia function symbols. e.g. the symbol <code>Base.is()</code> is bound to C function pointer <code>jl_f_is()</code> by calling <code>add_builtin_func(&quot;eval&quot;, jl_f_top_eval)</code>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/toplevel.c"><code>jl_new_main_module()</code></a> creates the global &quot;Main&quot; module and sets <code>jl_current_task-&gt;current_module = jl_main_module</code>.</p><p>Note: <code>_julia_init()</code> <a href="https://github.com/JuliaLang/julia/blob/master/src/init.c">then sets</a> <code>jl_root_task-&gt;current_module = jl_core_module</code>. <code>jl_root_task</code> is an alias of <code>jl_current_task</code> at this point, so the <code>current_module</code> set by <code>jl_new_main_module()</code> above is overwritten.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/init.c"><code>jl_load(&quot;boot.jl&quot;, sizeof(&quot;boot.jl&quot;))</code></a> calls <a href="https://github.com/JuliaLang/julia/blob/master/src/ast.c"><code>jl_parse_eval_all</code></a> which repeatedly calls <a href="https://github.com/JuliaLang/julia/blob/master/src/toplevel.c"><code>jl_toplevel_eval_flex()</code></a> to execute <a href="https://github.com/JuliaLang/julia/blob/master/base/boot.jl"><code>boot.jl</code></a>. &lt;! TODO drill down into eval? &gt;</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/init.c"><code>jl_get_builtin_hooks()</code></a> initializes global C pointers to Julia globals defined in <code>boot.jl</code>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/datatype.c"><code>jl_init_box_caches()</code></a> pre-allocates global boxed integer value objects for values up to 1024. This speeds up allocation of boxed ints later on. e.g.:</p><pre><code class="language-c">jl_value_t *jl_box_uint8(uint32_t x)
{
return boxed_uint8_cache[(uint8_t)x];
}</code></pre><p><a href="https://github.com/JuliaLang/julia/blob/master/src/init.c"><code>_julia_init()</code> iterates</a> over the <code>jl_core_module-&gt;bindings.table</code> looking for <code>jl_datatype_t</code> values and sets the type name&#39;s module prefix to <code>jl_core_module</code>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/toplevel.c"><code>jl_add_standard_imports(jl_main_module)</code></a> does &quot;using Base&quot; in the &quot;Main&quot; module.</p><p>Note: <code>_julia_init()</code> now reverts to <code>jl_root_task-&gt;current_module = jl_main_module</code> as it was before being set to <code>jl_core_module</code> above.</p><p>Platform specific signal handlers are initialized for <code>SIGSEGV</code> (OSX, Linux), and <code>SIGFPE</code> (Windows).</p><p>Other signals (<code>SIGINFO, SIGBUS, SIGILL, SIGTERM, SIGABRT, SIGQUIT, SIGSYS</code> and <code>SIGPIPE</code>) are hooked up to <a href="https://github.com/JuliaLang/julia/blob/master/src/signals-unix.c"><code>sigdie_handler()</code></a> which prints a backtrace.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/dump.c"><code>jl_init_restored_modules()</code></a> calls <a href="https://github.com/JuliaLang/julia/blob/master/src/module.c"><code>jl_module_run_initializer()</code></a> for each deserialized module to run the <code>__init__()</code> function.</p><p>Finally <a href="https://github.com/JuliaLang/julia/blob/master/src/signals-unix.c"><code>sigint_handler()</code></a> is hooked up to <code>SIGINT</code> and calls <code>jl_throw(jl_interrupt_exception)</code>.</p><p><code>_julia_init()</code> then returns <a href="https://github.com/JuliaLang/julia/blob/master/ui/repl.c">back to <code>main()</code> in <code>ui/repl.c</code></a> and <code>main()</code> calls <code>true_main(argc, (char**)argv)</code>.</p><div class="admonition sidebar"><div class="admonition-title">sysimg</div><div class="admonition-text"><p>If there is a sysimg file, it contains a pre-cooked image of the <code>Core</code> and <code>Main</code> modules (and whatever else is created by <code>boot.jl</code>). See <a href="sysimg.html#Building-the-Julia-system-image-1">Building the Julia system image</a>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/dump.c"><code>jl_restore_system_image()</code></a> deserializes the saved sysimg into the current Julia runtime environment and initialization continues after <code>jl_init_box_caches()</code> below...</p><p>Note: <a href="https://github.com/JuliaLang/julia/blob/master/src/dump.c"><code>jl_restore_system_image()</code> (and <code>dump.c</code> in general)</a> uses the <a href="stdio.html#Legacy-ios.c-library-1">Legacy <code>ios.c</code> library</a>.</p></div></div><h2><a class="nav-anchor" id="true_main()-1" href="#true_main()-1">true_main()</a></h2><p><a href="https://github.com/JuliaLang/julia/blob/master/ui/repl.c"><code>true_main()</code></a> loads the contents of <code>argv[]</code> into <a href="../stdlib/constants.html#Base.ARGS"><code>Base.ARGS</code></a>.</p><p>If a <code>.jl</code> &quot;program&quot; file was supplied on the command line, then <a href="https://github.com/JuliaLang/julia/blob/master/ui/repl.c"><code>exec_program()</code></a> calls <a href="https://github.com/JuliaLang/julia/blob/master/src/toplevel.c"><code>jl_load(program,len)</code></a> which calls <a href="https://github.com/JuliaLang/julia/blob/master/src/ast.c"><code>jl_parse_eval_all</code></a> which repeatedly calls <a href="https://github.com/JuliaLang/julia/blob/master/src/toplevel.c"><code>jl_toplevel_eval_flex()</code></a> to execute the program.</p><p>However, in our example (<code>julia -e &#39;println(&quot;Hello World!&quot;)&#39;</code>), <a href="https://github.com/JuliaLang/julia/blob/master/src/module.c"><code>jl_get_global(jl_base_module, jl_symbol(&quot;_start&quot;))</code></a> looks up <a href="https://github.com/JuliaLang/julia/blob/master/base/client.jl"><code>Base._start</code></a> and <a href="https://github.com/JuliaLang/julia/blob/master/src/julia.h"><code>jl_apply()</code></a> executes it.</p><h2><a class="nav-anchor" id="Base._start-1" href="#Base._start-1">Base._start</a></h2><p><a href="https://github.com/JuliaLang/julia/blob/master/base/client.jl"><code>Base._start</code></a> calls <a href="https://github.com/JuliaLang/julia/blob/master/base/client.jl"><code>Base.process_options</code></a> which calls <a href="https://github.com/JuliaLang/julia/blob/master/src/ast.c"><code>jl_parse_input_line(&quot;println(&quot;Hello World!&quot;)&quot;)</code></a> to create an expression object and <a href="../stdlib/base.html#Core.eval"><code>Base.eval()</code></a> to execute it.</p><h2><a class="nav-anchor" id="Base.eval-1" href="#Base.eval-1">Base.eval</a></h2><p><a href="../stdlib/base.html#Core.eval"><code>Base.eval()</code></a> was <a href="https://github.com/JuliaLang/julia/blob/master/src/builtins.c">mapped to <code>jl_f_top_eval</code></a> by <code>jl_init_primitives()</code>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/builtins.c"><code>jl_f_top_eval()</code></a> calls <a href="https://github.com/JuliaLang/julia/blob/master/src/builtins.c"><code>jl_toplevel_eval_in(jl_main_module, ex)</code></a>, where <code>ex</code> is the parsed expression <code>println(&quot;Hello World!&quot;)</code>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/builtins.c"><code>jl_toplevel_eval_in()</code></a> calls <a href="https://github.com/JuliaLang/julia/blob/master/src/toplevel.c"><code>jl_toplevel_eval_flex()</code></a> which calls <a href="https://github.com/JuliaLang/julia/blob/master/src/interpreter.c"><code>eval()</code> in <code>interpreter.c</code></a>.</p><p>The stack dump below shows how the interpreter works its way through various methods of <a href="../stdlib/io-network.html#Base.println"><code>Base.println()</code></a> and <a href="../stdlib/io-network.html#Base.print"><code>Base.print()</code></a> before arriving at <a href="https://github.com/JuliaLang/julia/blob/master/base/stream.jl"><code>write(s::IO, a::Array{T}) where T</code></a> which does <code>ccall(jl_uv_write())</code>.</p><p><a href="https://github.com/JuliaLang/julia/blob/master/src/jl_uv.c"><code>jl_uv_write()</code></a> calls <code>uv_write()</code> to write &quot;Hello World!&quot; to <code>JL_STDOUT</code>. See <a href="stdio.html#Libuv-wrappers-for-stdio-1">Libuv wrappers for stdio</a>.:</p><pre><code class="language-none">Hello World!</code></pre><table><tr><th>Stack frame</th><th>Source code</th><th>Notes</th></tr><tr><td><code>jl_uv_write()</code></td><td><code>jl_uv.c</code></td><td>called though <a href="../stdlib/c.html#ccall"><code>ccall</code></a></td></tr><tr><td><code>julia_write_282942</code></td><td><code>stream.jl</code></td><td>function <code>write!(s::IO, a::Array{T}) where T</code></td></tr><tr><td><code>julia_print_284639</code></td><td><code>ascii.jl</code></td><td><code>print(io::IO, s::String) = (write(io, s); nothing)</code></td></tr><tr><td><code>jlcall_print_284639</code></td><td> </td><td> </td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_trampoline()</code></td><td><code>builtins.c</code></td><td> </td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_apply_generic()</code></td><td><code>gf.c</code></td><td><code>Base.print(Base.TTY, String)</code></td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_trampoline()</code></td><td><code>builtins.c</code></td><td> </td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_apply_generic()</code></td><td><code>gf.c</code></td><td><code>Base.print(Base.TTY, String, Char, Char...)</code></td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_f_apply()</code></td><td><code>builtins.c</code></td><td> </td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_trampoline()</code></td><td><code>builtins.c</code></td><td> </td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_apply_generic()</code></td><td><code>gf.c</code></td><td><code>Base.println(Base.TTY, String, String...)</code></td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_trampoline()</code></td><td><code>builtins.c</code></td><td> </td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>jl_apply_generic()</code></td><td><code>gf.c</code></td><td><code>Base.println(String,)</code></td></tr><tr><td><code>jl_apply()</code></td><td><code>julia.h</code></td><td> </td></tr><tr><td><code>do_call()</code></td><td><code>interpreter.c</code></td><td> </td></tr><tr><td><code>eval()</code></td><td><code>interpreter.c</code></td><td> </td></tr><tr><td><code>jl_interpret_toplevel_expr()</code></td><td><code>interpreter.c</code></td><td> </td></tr><tr><td><code>jl_toplevel_eval_flex()</code></td><td><code>toplevel.c</code></td><td> </td></tr><tr><td><code>jl_toplevel_eval()</code></td><td><code>toplevel.c</code></td><td> </td></tr><tr><td><code>jl_toplevel_eval_in()</code></td><td><code>builtins.c</code></td><td> </td></tr><tr><td><code>jl_f_top_eval()</code></td><td><code>builtins.c</code></td><td> </td></tr></table><p>Since our example has just one function call, which has done its job of printing &quot;Hello World!&quot;, the stack now rapidly unwinds back to <code>main()</code>.</p><h2><a class="nav-anchor" id="jl_atexit_hook()-1" href="#jl_atexit_hook()-1">jl_atexit_hook()</a></h2><p><code>main()</code> calls <a href="https://github.com/JuliaLang/julia/blob/master/src/init.c"><code>jl_atexit_hook()</code></a>. This calls <code>_atexit</code> for each module, then calls <a href="https://github.com/JuliaLang/julia/blob/master/src/gc.c"><code>jl_gc_run_all_finalizers()</code></a> and cleans up libuv handles.</p><h2><a class="nav-anchor" id="julia_save()-1" href="#julia_save()-1">julia_save()</a></h2><p>Finally, <code>main()</code> calls <a href="https://github.com/JuliaLang/julia/blob/master/src/init.c"><code>julia_save()</code></a>, which if requested on the command line, saves the runtime state to a new system image. See <a href="https://github.com/JuliaLang/julia/blob/master/src/gf.c"><code>jl_compile_all()</code></a> and <a href="https://github.com/JuliaLang/julia/blob/master/src/dump.c"><code>jl_save_system_image()</code></a>.</p><footer><hr/><a class="previous" href="reflection.html"><span class="direction">Previous</span><span class="title">Reflection and introspection</span></a><a class="next" href="ast.html"><span class="direction">Next</span><span class="title">Julia ASTs</span></a></footer></article></body></html>