• Mindscape ๐Ÿ”ฅ
    • Playlist ๐ŸŽง
  • Algorithm

    • 1018๋ฒˆ: ์ฒด์ŠคํŒ ๋‹ค์‹œ ์น ํ•˜๊ธฐ
    • 1966๋ฒˆ: ํ”„๋ฆฐํ„ฐ ํ
    • Python ์‹œ๊ฐ„ ์ดˆ๊ณผ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ ํŒ
    • C++ std::vector ์‚ฌ์šฉ๋ฒ• ์ •๋ฆฌ
    • Vim ์‚ฌ์šฉ ๋งค๋‰ด์–ผ
  • Ubuntu

    • ๋ฆฌ๋ˆ…์Šค ์šฐ๋ถ„ํˆฌ GRUB ํฐํŠธ ๋ณ€๊ฒฝ
    • ์šฐ๋ถ„ํˆฌ ์ด๋ฏธ์ง€ ๋น„๋””์˜ค ์ธ๋„ค์ผ(๋ฏธ๋ฆฌ๋ณด๊ธฐ) ์•ˆ ๋ณด์ž„ ๋ฌธ์ œ ํ•ด๊ฒฐ
    • Wine ํ™˜๊ฒฝ์—์„œ ์นด์นด์˜คํ†ก ์‹คํ–‰ ์‹œ explorer.exe ๋œจ์ง€ ์•Š๊ฒŒ ํ•˜๋Š” ๋ฒ•
    • ์šฐ๋ถ„ํˆฌ Wine ์นด์นด์˜คํ†ก ์‚ฌ์ง„ ์ด๋ฏธ์ง€ ์Šคํฌ๋ฆฐ์ƒท ๋ถ™์—ฌ๋„ฃ๊ธฐ
    • Wine ์นด์นด์˜คํ†ก ์ด๋ชจ์ง€ ๊นจ์ง ๋ฌธ์ œ ํ•ด๊ฒฐ
    • Ubuntu ์œˆ๋„์šฐ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋„๊ธฐ
  • Wellness

    • ์ฐจ์ „์žํ”ผ (Psyllium Husk)
    • ์—‘์ŠคํŠธ๋ผ ๋ฒ„์ง„ ์˜ฌ๋ฆฌ๋ธŒ์œ  (Extra Virgin Olive Oil)
    • ์ž๊ฐ€๋น„๊ฐ•์„ธ์ฒ™ (Nasal Irrigation)
    • QCY HT08 (MeloBuds Pro Plus)
    • ์ฝ˜์„œํƒ€ (Concerta)
    • ์ธ๋ฐ๋†€ (Inderal)
    • ์„คํŠธ๋ž„๋ฆฐ (Sertraline)
    • ๋ฉœ๋ผํ† ๋‹Œ (Melatonin)
    • ์น˜๊ฒฝ๋ถ€ ๋งˆ๋ชจ์ฆ
    • ๋ฐ”๋ฒจ ์Šค์ฟผํŠธ (Barbell Squat)
  • Humanities

    • Nordvik, Russia
    • North Sentinel Island
    • ๋กฑ๊ณ ๋กฑ๊ณ (Rongorongo)
    • ๋ฐ”๋กœํฌ ์Œ์•… (Baroque Music)
  • Design

    • ๊ตฌ๊ธ€์˜ ์•„์ด์ฝ˜ ๋Œ€๊ฐœํŽธ โ€” 6๋…„ ๋งŒ์˜ ์‹ค์ˆ˜ ์ธ์ •
    • ์ œ๋Ÿด๋“œ ์  ํƒ€ โ€” ๋Ÿญ์…”๋ฆฌ ์Šคํฌ์ธ  ์›Œ์น˜์˜ ์ฐฝ์‹œ์ž
    • ๋ฐ”์šฐํ•˜์šฐ์Šค โ€” ํ˜„๋Œ€ ๋””์ž์ธ์˜ ์›์ 
  • Brands

    • NOMOS Glashรผtte
    • Frรฉdรฉrique Constant
    • KZ (Knowledge Zenith)
    • ์—์ŠคํŠธ๋ผ (AESTURA)
    • JINHAO (้‡‘่ฑช)
    • Herman Miller
    • ๋ฐ์Šค์ปค (DESKER)
    • ๋ฌด์‹ ์‚ฌ ์Šคํƒ ๋‹ค๋“œ (Musinsa Standard)
  • Finance

    • ํ˜„๋Œ€์นด๋“œ ZERO โ€” Edition2 vs Edition3 ๋น„๊ต
    • ์‹ ํ•œ์นด๋“œ ์ฒ˜์Œ
    • S&P 500 ETF ํˆฌ์ž ๊ฐ€์ด๋“œ
    • ํŒŒํ‚นํ†ต์žฅ vs CMA ํ†ต์žฅ
    • ๋ฒ„ํฌ์…” ํ•ด์„œ์›จ์ด (Berkshire Hathaway)
    • ๋น„ํŠธ์ฝ”์ธ(Bitcoin)
  • Products

    • ์˜ค๋””์˜ค ์ธํ„ฐํŽ˜์ด์Šค (Audio Interface)
    • ์ฟ ๋ฃจํ† ๊ฐ€ (KURUTOGA)
    • CX31993 DAC ๋™๊ธ€
    • ํด๋ Œ์ง• ๋ฐ€ํฌ (Cleansing Milk)
    • ํ”ผ์ ฏ ํ† ์ด (Fidget Toy)
    • ThinkPad
  • Programming Languages

    • 8.0. Statement Level Control Structures
    • 8. Subprogram
    • 9. Implementing Subprogram
    • 10.1. Abstract Data Types and Encapsulation Constructs
    • 10.2. Support for Object Oriented Programming
    • 11. Concurrency
    • 12. FPL (1)
    • 13. FPL (2)
    • 14. Exception Handling and Event Handling
    • Final Exam

9. Implementing Subprogram

์ž‘์„ฑ 2026. 6. 12.ยท์ˆ˜์ • 2026. 6. 12.

Recap: Subprograms

  • Parameters
def compute_pay(income, exemptions = 1, tax_rate):
    ...
    return

  • Positional binding
pay = compute_pay(20000.0, tax_rate = 0.15)

  • Formal parameters: income, exemptions, tax-rate

  • Actual parameters: 20000.0, 0.15

  • Default value

  • Binding by keyword parameters

  • Parameter passing methods

  • Semantics models

  • in mode, out mode, inout mode

  • Implementation models

  • Pass-by-value

  • Pass-by-reference

  • Pass-by-value-result

  • Pass-by-name

  • Pass-by-assignment

  • Two types of subprograms

  • Procedures: does not return

  • Can change variable

  • Functions: return value

  • No side effect ideally

  • Parameter that are subprograms

  • Shallow/deep/ad hoc binding

  • Overloaded subprograms

  • [Issue 1] Coercion is allowed?

  • [Issue 2] The same parameter but different return types

  • Generic subprograms

  • Ad hoc/subtype/parametric polymorphism

  • [Issue 1] Type checking functionโ€™s protocol

  • [Issue 2] If nested โ†’\rightarrowโ†’ referencing environment

  • Closures: function returned by a function

  • Function is also object

  • Function can be nested

  • Subprogram can be called in other place

  • Remembers the referencing environment

def addNumber(fixedNum):
    def add(number):
        return fixedNum + number
    return add
# ===============================
func = addNumber(10)
func(20) # 30
func(30) # 40

  • Coroutines
  • Coroutines are more equitable
  • Coroutines can have multiple entry points
  • Only one coroutine is actually in execution at a given time
  • โ†’\rightarrowโ†’ quasi-concurrency
  • Related to the way multiprogramming operating systems

Implementing Subprogram

  • General semantics of calls and returns

  • โ€œSimpleโ€ subprograms

  • Subprograms with stack-dynamic local variables

  • Nested subprograms

  • Blocks

  • Dynamic scoping

  • Implementation of subprograms

  • How subprogram linkage works?

  • Subprogram์„ ํ˜ธ์ถœํ•˜๊ณ  ์‹คํ–‰ํ•˜๋Š” ๊ณผ์ •์—์„œ ํ•„์š”ํ•œ ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น, ์ธ์ž ์ „๋‹ฌ, ๋ณต๊ท€ ์ฃผ์†Œ ๊ด€๋ฆฌ ๋“ฑ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ณผ์ •

  • ํ˜ธ์ถœํ•  ๋•Œ ํ•„์š”ํ•œ ์ •๋ณด(๋งค๊ฐœ๋ณ€์ˆ˜, ์ง€์—ญ๋ณ€์ˆ˜, ๋ณต๊ท€์ฃผ์†Œ ๋“ฑ)๋ฅผ Activation Record๋กœ ์Šคํƒ์— ์ €์žฅ

  • ํ•จ์ˆ˜ ์‹คํ–‰ ํ›„ ๋ณต๊ท€ ์‹œ Activation Record๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ๋ณต๊ตฌ

  • Simplest: no nested with only local static variable

  • Static variable์€ ์Šคํƒ(stack)์ด ์•„๋‹ˆ๋ผ ๊ณ ์ •๋œ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„(static data area) ์— ์ €์žฅ

  • ํ˜ธ์ถœํ•  ๋•Œ๋งˆ๋‹ค ์ƒˆ๋กœ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•  ํ•„์š” ์—†์Œ

  • โ†’\rightarrowโ†’ Activation Record๋Š” ๋งค์šฐ ๋‹จ์ˆœํ•ด์ง

  • ๋ณต๊ท€ ์ฃผ์†Œ (Return address)๋งŒ ์ €์žฅํ•˜๋ฉด ๋˜๊ณ 

  • ์ง€์—ญ๋ณ€์ˆ˜ ๊ณต๊ฐ„์€ ์ด๋ฏธ ๋”ฐ๋กœ ์žˆ์œผ๋ฏ€๋กœ ์Šคํƒ์— ์ €์žฅํ•  ํ•„์š” ์—†์Œ

int counter() {
    static int cnt = 0; // static local variable
    cnt++;
    return cnt;
}
int main() {
    int a = counter(); // a == 1
    int b = counter(); // b == 2
    return 0;
}

  • Challenges with

  • Stack-dynamic local variable

  • ์ง€์—ญ๋ณ€์ˆ˜๊ฐ€ ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ์ ์— ๋งŒ๋“ค์–ด์ง

  • ํ•จ์ˆ˜ ๋๋‚˜๋ฉด ์Šคํƒ์—์„œ ์ž๋™ ์†Œ๋ฉธ

  • ํฌ๊ธฐ๊ฐ€ ๊ฐ€๋ณ€์ ์ธ ๊ฒฝ์šฐ (ex: ๊ฐ€๋ณ€ ๋ฐฐ์—ด) ๋” ์ฃผ์˜ํ•ด์•ผ ํ•จ

  • Nested subprograms

  • ํ•จ์ˆ˜ ์•ˆ์— ๋˜ ๋‹ค๋ฅธ ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Œ (ex: Pascal, Ada, ์ผ๋ถ€ Python lambda)

  • ๋‚ด๋ถ€ ํ•จ์ˆ˜๊ฐ€ ์™ธ๋ถ€ ํ•จ์ˆ˜์˜ ๋ณ€์ˆ˜์— ์ ‘๊ทผํ•ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Œ

  • Nonlocal access with static scope

  • ์ค‘์ฒฉ ํ•จ์ˆ˜๊ฐ€ ์ƒ์œ„ ํ•จ์ˆ˜์˜ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•  ๋•Œ

  • ์ƒ์œ„ ํ•จ์ˆ˜์˜ Activation Record๋กœ ์ ‘๊ทผ ๋ฐฉ๋ฒ• ํ•„์š” (Static Link)

  • Block and dynamic scope

  • scope ๊ทœ์น™์— ๋”ฐ๋ผ, ๋Ÿฐํƒ€์ž„์— ์ฐพ๋Š” ๋ฐฉ๋ฒ•(static vs dynamic)์ด ๋‹ฌ๋ผ ์ง

General Semantics of Calls and Returns

  • Subprogram linkage: subprogram call and return operations

  • Implementation should be based on semantic of subprogram linkage

  • Subprogram call

  • Must include parameter-passing method

  • Allocation and binding for stack-dynamic local variable

  • Execution status should be saved

  • Everything needed to resume execution of the calling program unit

  • Register value, CPU status bits, environment pointer (EP)

  • Arrange to transfer control to the code of the subprogram

  • After execution is completed, transfer control should be returned proper place

  • For nested subprograms, mechanism for accessing nonlocal variables are needed

  • Subprogram return

  • In out mode and inout mode, formal parameters are returned to the actual parameters

  • Deallocate of stack-dynamic local variables in subprograms

  • Restore the execution status of the calling program

  • Returning control to the caller

  • Code Example:

// [C++]
int g = 0;
int func(int first, int second) {
    int sum = 0;
    sum = first + second;
    return sum;
}
void main() {
    int x = 1;
    int y = 2;
    func(x,y);
    return;
}

  • Component Layout & Concepts:
  • Parameters โ†’\rightarrowโ†’ Where parameters are stored
  • Local variable โ†’\rightarrowโ†’ Where local variables in subprograms are stored
  • Where we return โ†’\rightarrowโ†’ Where we return after the subprogram call
  • Stack
  • Heap
  • Registers
  • โ€ฆ
  • Environment pointer (EP)
  • Data
  • Program counter (PC)
  • Code

โ€œSimpleโ€ Subprograms

  • No nested and all local variables are static (or no recursion)
  • Semantic of call
  1. Create an activation record instance
  2. Save the execution status of the current program unit. (done by caller or callee)
  3. Compute and pass the parameters. (done by caller)
  4. Pass the return address to the called. (done by caller)
  5. Transfer control to the called. (done by caller)
  • Allocation and binding for stack-dynamic local variables

  • Mechanism for nonlocal variable for nested subprograms

  • Semantic of return

  1. For out-mode parameters, the values of those parameters are moved to the corresponding actual parameters. (done by callee)
  2. If the subprogram is a function, the functional value is moved to a place accessible to the caller. (done by callee)
  3. The execution status of the caller is restored. (done by caller or callee)
  4. Control is transferred back to the caller. (done by callee)
  • Deallocate of stack-dynamic local variables in subprograms

  • Simple subprogram code example:

// [C++]
int func(int first, int second) {
    static int sum = 0;
    sum = first + second;
    return sum; // โ‘ก
}
void main() {
    static int x = 1;
    static int y = 2;
    // โ‘ 
    func(x,y);
    return;
}

  • An activation record for simple subprograms
  • โ‘  Caller action
  1. Create an activation record instance.
  2. Save the execution status of the current program unit.
  3. Compute and pass the parameters.
  4. Pass the return address to the called.
  5. Transfer control to the called.
  • โ‘ก Callee action
  • Epilogue (end of execution)
  1. For out-mode parameters, the values of values of those parameters are moved to the corresponding actual parameters.
  2. If the subprogram is a function, the functional value is moved to a place accessible to the caller.
  3. Restore the execution status of the caller.
  4. Transfer control back to the caller.
  • ์žฌ๊ท€ ์—†์Œ ํ•˜๋‚˜์˜ ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ๋งŒ ์Šคํƒ์— ์˜ฌ๋ผ๊ฐ€์„œ ์‹คํ–‰ ์ค‘

  • The call and return actions require storage for the following:

  • Status information about the caller

  • Parameters

  • Return address

  • Return value for functions

  • Temporaries used by the code of the subprograms

  • Linkage action of callee can occur at two different times

  • Prologue: beginning of its execution (Caller action)

  • Epilogue: end of its execution (Callee action)

  • -Prologue (beginning of execution)

  • -Epilogue (end of execution)

  • Consists of two separate parts:

  • Actual codes (constant)

  • ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ์˜ ์‹ค์ œ ๊ธฐ๊ณ„์–ด ๋ช…๋ น์–ด๋“ค

  • ํ”„๋กœ๊ทธ๋žจ ์ž‘์„ฑ ์‹œ ์ด๋ฏธ ๊ณ ์ •๋œ Constant

  • ์‹คํ–‰ ์ค‘์— ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์Œ

  • Non-code: local variable and data (can change)

  • ์ง€์—ญ ๋ณ€์ˆ˜(Local variables), ์ž„์‹œ ๊ฐ’(Temporary values), ๋งค๊ฐœ๋ณ€์ˆ˜(Parameters) ๋“ฑ

  • ์‹คํ–‰ ์ค‘์— ๊ฐ’์ด ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์Œ

  • Fixed size in simple subprogram

  • ์ค‘์ฒฉ์ด ์—†๊ณ , ์ง€์—ญ ๋ณ€์ˆ˜์™€ ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ํฌ๊ธฐ๊ฐ€ ๊ณ ์ •๋˜์–ด ์žˆ์œผ๋ฉด โ†’\rightarrowโ†’ ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ๋งˆ๋‹ค ํ•„์š”ํ•œ Non-Code ์˜์—ญ์˜ ํฌ๊ธฐ๊ฐ€ ๊ณ ์ •(fixed)

  • ํ˜ธ์ถœํ•  ๋•Œ๋งˆ๋‹ค ์ด ํฌ๊ธฐ๋งŒํผ ์Šคํƒ์— ๊ณต๊ฐ„์„ ์žก์œผ๋ฉด ๋จ

  • Activation record (non-code):

  • Format, or layout, of the noncode part of a subprogram

  • Activation Record๋ž€ Non-Code ๋ถ€๋ถ„์˜ ๋ ˆ์ด์•„์›ƒ์„ ์ •์˜

  • ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ์„ ํ˜ธ์ถœํ•  ๋•Œ ์Šคํƒ์— ์Œ“์ด๋Š” ํ”„๋ ˆ์ž„์˜ ๊ตฌ์กฐ

  • Activation Record๊ฐ€ ํฌํ•จํ•˜๋Š” ๊ฒƒ๋“ค ์˜ˆ์‹œ:

  • ๋งค๊ฐœ๋ณ€์ˆ˜(Parameter values)

  • ์ง€์—ญ ๋ณ€์ˆ˜(Local variables)

  • ๋ณต๊ท€ ์ฃผ์†Œ(Return address)

  • ๋™์  ๋งํฌ(Dynamic link, caller์˜ frame pointer)

  • ์ •์  ๋งํฌ(Static link, ์ƒ์œ„ lexical scope๋กœ ์ ‘๊ทผํ•˜๋Š” ํฌ์ธํ„ฐ)

  • ์ž„์‹œ ์ €์žฅ๊ณต๊ฐ„(Temporary storage)

  • ARI (Activation record instance): Instance created according to this format

  • Activation Record์˜ ์‹ค์ œ ์ธ์Šคํ„ด์Šค

  • AR ํฌ๋งท์— ๋”ฐ๋ผ ์‹ค์ œ๋กœ ๋ฉ”๋ชจ๋ฆฌ์— ํ• ๋‹น๋˜๋Š” ์Šคํƒ ํ”„๋ ˆ์ž„์ด ARI

  • ARI of simple subprogram has fixed size โ†’\rightarrowโ†’ can be statically allocated and attached to code part

  • No recursion โ†’\rightarrowโ†’ only one ARI is active

  • Single activation record per subprogram

  • Code Example for Code and Non-Code mapping:

int add(int a, int b) {
    int sum = a + b;
    return sum;
}
int main() {
    int result = add(3, 5);
}

  • Actual Code:

  • add ํ•จ์ˆ˜์˜ ์ปดํŒŒ์ผ๋œ ๋ช…๋ น์–ด๋“ค (ex. ๋ง์…ˆ ๋ช…๋ น, ๋ฐ˜ํ™˜ ๋ช…๋ น ๋“ฑ)

  • ํ”„๋กœ๊ทธ๋žจ ์‹œ์ž‘ ๋•Œ ๋ฉ”๋ชจ๋ฆฌ์— ๊ณ ์ •

  • Non-Code (Activation Record Format):

  • ๋งค๊ฐœ๋ณ€์ˆ˜ a, b

  • ์ง€์—ญ๋ณ€์ˆ˜ sum

  • ๋ณต๊ท€ ์ฃผ์†Œ

  • [EX] Main program with three subprograms A, B and C

  • Simple Subprogram ํ™˜๊ฒฝ์—์„œ ๋ฉ”๋ชจ๋ฆฌ ๋ฐฐ์น˜(๋ฉ”๋ชจ๋ฆฌ ๊ตฌ์กฐ) ๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ์Œ

  • Data ์˜์—ญ๊ณผ Code ์˜์—ญ ๋‘ ๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋จ„

  • Data ์˜์—ญ (์œ„์ชฝ):

  • ๊ฐ ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ (MAIN, A, B, C)์— ๋Œ€ํ•ด Activation Record (AR) ๊ฐ€ ๋ฏธ๋ฆฌ(static) ์ค€๋น„๋˜์–ด ์žˆ์Œ

  • ์ด Activation Record๋“ค์€ ํ”„๋กœ๊ทธ๋žจ์ด ์‹œ์ž‘ํ•  ๋•Œ ๊ณ ์ •๋œ ๋ฉ”๋ชจ๋ฆฌ(Data Segment)์— ํ• ๋‹น๋˜๊ณ , ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ๋งˆ๋‹ค ์ƒˆ๋กœ ๋งŒ๋“ค์ง€ ์•Š๊ณ  ์žฌ์‚ฌ์šฉ

  • Code ์˜์—ญ (์•„๋ž˜์ชฝ)

  • MAIN, A, B, C ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ์˜ ๊ธฐ๊ณ„์–ด ์ฝ”๋“œ(๋ช…๋ น์–ด) ๊ฐ€ ์ €์žฅ๋œ ์˜์—ญ

  • Code๋Š” ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๊ณ  ํ”„๋กœ๊ทธ๋žจ ๋‚ด๋‚ด ๊ณ ์ •

  • ์ปดํŒŒ์ผ๋œ ๋ช…๋ น์–ด๋“ค์€ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์‹œ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ

  • Format of AR is static

  • โ†’\rightarrowโ†’ Activation Record์˜ ๋ ˆ์ด์•„์›ƒ์ด ์ปดํŒŒ์ผ ์‹œ์ ์— ๊ณ ์ •๋˜์–ด ์žˆ์Œ

  • โ†’\rightarrowโ†’ ๋Ÿฐํƒ€์ž„์— ํฌ๊ธฐ๊ฐ€ ๋ณ€ํ•˜์ง€ ์•Š์Œ

  • Each program can be compiled at different time

  • MAIN, A, B, C ๊ฐ๊ฐ ๋”ฐ๋กœ AR์ด ์กด์žฌ โ†’\rightarrowโ†’ ๊ฐ๊ฐ์˜ ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ(MAIN, A, B, C)์€ ๋…๋ฆฝ์ ์œผ๋กœ ์ปดํŒŒ์ผํ•  ์ˆ˜ ์žˆ์Œ

  • Linker can put together

  • โ†’\rightarrowโ†’ ์ดํ›„ Linker๊ฐ€ ์ด ์ปดํŒŒ์ผ ๊ฒฐ๊ณผ๋“ค์„ ํ•˜๋‚˜๋กœ ํ•ฉ์นจ

Subprograms with Stack-Dynamic Local Variables

  • Stack-Dynamic Local Variable

  • Advantage of stack-dynamic local variable

  • Support for recursion

  • ๊ฐ ํ•จ์ˆ˜ ํ˜ธ์ถœ๋งˆ๋‹ค ์ƒˆ๋กœ์šด Activation Record(์Šคํƒ ํ”„๋ ˆ์ž„)๋ฅผ ๋งŒ๋“ค์–ด ์ €์žฅํ•  ์ˆ˜ ์žˆ์Œ

  • ์žฌ๊ท€ ํ˜ธ์ถœ ์‹œ, ํ•จ์ˆ˜์˜ ๋‹ค๋ฅธ ํ˜ธ์ถœ๋“ค์ด ์„œ๋กœ ๋…๋ฆฝ์ ์ธ ์ง€์—ญ๋ณ€์ˆ˜ ์ง‘ํ•ฉ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ

  • ๊ฒฐ๊ณผ์ ์œผ๋กœ ํ•œ ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ์ด ๋™์‹œ์— ์—ฌ๋Ÿฌ activation์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ

  • But, more complex activation records

  • Compiler generates code for implicit allocation/deallocation for local variables

  • Activation Record๊ฐ€ ๋‹จ์ˆœํžˆ "๊ณ ์ •๋œ ๋ฉ”๋ชจ๋ฆฌ"๊ฐ€ ์•„๋‹ˆ๋ผ, ๋งค ํ˜ธ์ถœ๋งˆ๋‹ค ์ƒˆ๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•จ

  • ์ปดํŒŒ์ผ๋Ÿฌ๋Š” ์ง€์—ญ๋ณ€์ˆ˜๋“ค์„ ํ•จ์ˆ˜ ์ง„์ž… ์‹œ ์ž๋™์œผ๋กœ ์ƒ์„ฑ(allocate), ํ•จ์ˆ˜ ์ข…๋ฃŒ ์‹œ ์ž๋™์œผ๋กœ ์†Œ๋ฉธ(deallocate) ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž๋™ ์‚ฝ์ž…ํ•ด์•ผ ํ•จ

  • Multiple simultaneous activations of subprograms (limited by memory size)

  • Usually, format of an activation record is known at compile time

  • Activation record instances (ARI) must be created dynamically

  • Return address, dynamic link and parameters are placed in ARI by caller

  • Return address: usually consists of point to instruction following the call

  • Dynamic link: pointer to the base of the activation record instance of the caller

  • Statically-scoped languages โ€” used for debugging

  • Dynamically-scoped languages โ€” also used to find variables in scope

  • Actual parameters: values or addresses provided by the caller

  • Local variable

  • Scalar variables are bound to storage within ARI

  • Structure variables are allocated elsewhere (pointer is in ARI)

  • ARI ์ƒ์„ฑ๊ณผ์ •

    1. Caller
  • Return address, Dynamic link, Actual parameters๋ฅผ ๋จผ์ € ARI์— ์ฑ„์›€

    1. Callee
  • Local variables (์ง€์—ญ ๋ณ€์ˆ˜)์„ ARI์— ์ฑ„์šฐ๊ฑฐ๋‚˜ ์ดˆ๊ธฐํ™”

๊ตฌ์„ฑ ์š”์†Œ์„ค๋ช…๋ˆ„๊ฐ€ ์„ค์ •ํ•˜๋Š”๊ฐ€
Return addressํ˜ธ์ถœ์ด ๋๋‚˜๋ฉด ๋ณต๊ท€ํ•  ์ฝ”๋“œ์˜ ์ฃผ์†Œ (ํ˜ธ์ถœํ•œ ๋‹ค์Œ ๋ช…๋ น์–ด ์œ„์น˜)Caller
Dynamic linkCaller์˜ ARI๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐCaller
Actual parameters์ธ์ž ๊ฐ’ ๋˜๋Š” ์ธ์ž ์ฃผ์†Œ (๊ฐ’ ํ˜ธ์ถœ pass-by-value or ์ฃผ์†Œ ํ˜ธ์ถœ pass-by-reference)Caller
Local variables์ง€์—ญ ๋ณ€์ˆ˜ ๊ณต๊ฐ„ (์ดˆ๊ธฐํ™”๋Š” ํ•„์š”์— ๋”ฐ๋ผ)Callee
  • Example of C code and corresponding ARI
  • ARI is created on run-time stack
  • Run-time stack provides separate copies of the parameters, local variables, and return address
void sub(float total, int part) {
    int list[5];
    float sum;
    ...
}

  • Environment pointer (EP) is required to control execution of subprogram

  • Point current activation record base (initially main programโ€™s ARโ€™s base)

  • ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ์˜ Activation Record (ARI) ์˜ ๊ธฐ์ค€(base) ์œ„์น˜๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ

  • When subprogram is called, current EP is saved in the new ARI as dynamic link

  • Then, EP is set to point at base of new ARI

  • Upon return from subprogram, stack top โ†’\rightarrowโ†’ EP - 1

  • EP is set to dynamic link in executed ARI

  • โ†’\rightarrowโ†’ ํ˜ธ์ถœ ์ „ ํ•จ์ˆ˜์˜ ARI๋ฅผ ๋‹ค์‹œ ๊ฐ€๋ฆฌํ‚ค๋„๋ก

  • New actions in linkage process

// [C++]
int func(int first, int second) {
    // โ‘ก
    int sum = 0;
    sum = first + second;
    return sum; // โ‘ข
}
void main() {
    int x = 1;
    int y = 2;
    // โ‘ 
    func(x,y);
    return;
}

  • โ‘  Caller action
  1. Create an activation record instance.
  2. Save the execution status of the current program unit.
  3. Compute and pass the parameters.
  4. Pass the return address to the called.
  5. Transfer control to the called.
  • (โ‘ก โ‘ข) Callee action
  • โ‘ก Prologue (beginning of execution)
  1. Save the old EP in the stack as the dynamic link and create the new value.
  2. Allocate local variables.
  • โ‘ข Epilogue (end of execution)
  1. For out-mode parameters, the values of values of those parameters are moved to the corresponding actual parameters.
  2. If the subprogram is a function, the functional value is moved to a place accessible to the caller.
  3. Restore the stack pointer by setting it to the value of the current EP minus one and set the EP to the old dynamic link.
  4. Restore the execution status of the caller.
  5. Transfer control back to the caller.
  • Example without recursion

  • P1, ARI for main and fun1

  • P2, ARI for fun2 is added

  • P3. ARI for fun3 is added

  • Dynamic chain (call chain): collection of dynamic links

  • Local offset: distance from beginning of ARI

  • Determined in compile time

  • [EX] local offset of s is 3, t is 4

  • Example with recursion

  • Functional value๋Š” ์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ(ํŠนํžˆ ํ•จ์ˆ˜)์ด ๋ฐ˜ํ™˜ํ•  ๊ฐ’(return value) ์„ ์ž„์‹œ๋กœ ์ €์žฅํ•ด๋‘๋Š” ๊ณต๊ฐ„

  • Activation record for factorial

  • Figure show position 1 in each call

  • Functional value undefined

  • First callโ€™s return address is main

  • Other callโ€™s return address is factorial

  • Figure shows position2 for each execution

  • Code Example & Memory Analysis:

// [C++]
#include <iostream>
using namespace std;
int g = 0;
int func1(int first, int second) {
    int sum = 0;
    cout << "Address of first: " << &first << endl;
    cout << "Address of second: " << &second << endl;
    cout << "Address of sum: " << &sum << endl;
    g = g + 1;
    sum = first + second;
    return sum;
}
void func2(int first, int second) {
    func1(first,second);
    return;
}
int main() {
    int x = 1;
    int y = 2;
    cout << "Address of g: " << &g << endl;
    func1(x,y);
    cout << "Address of g: " << &g << endl;
    func1(x,y);
    cout << "Address of g: " << &g << endl;
    func2(x,y);
    cout << "Address of g: " << &g << endl;
    return 0;
}

  • Outputs/Addresses:

  • Address of first: 0x7ffcb9dc19bc

  • Address of second: 0x7ffcb9dc19b8

  • Address of sum: 0x7ffcb9dc19cc

  • Address of first: 0x7ffcb9dc199c

  • Address of second: 0x7ffcb9dc1998

  • Address of sum: 0x7ffcb9dc19ac

  • // Address of g: 0x404194

  • // Address of g: 0x404194

  • // Address of g: 0x404194

  • // Address of g: 0x404194

  • Stack Visualization:

  • Sum (0xโ€ฆcc)

  • โ€ฆ

  • First (0xโ€ฆbc)

  • Second (0xโ€ฆb8)

  • โ€ฆ

  • (func2)

  • Sum (0xโ€ฆac)

  • โ€ฆ

  • First (0xโ€ฆ9c)

  • Second (0xโ€ฆ98)

Nested subprograms

  • For nested subprograms, two steps are required for access

  • First, find ARI in stack in which the variable is allocated

  • ํ˜„์žฌ ์Šคํƒ ์œ„์— ์Œ“์ธ ARI๋“ค ์ค‘์—์„œ ๋ณ€์ˆ˜๊ฐ€ ์‹ค์ œ๋กœ ์„ ์–ธ๋œ Activation Record๋ฅผ ์ฐพ์•„์•ผ ํ•จ

  • Second, use local offset of the variable

  • Finding correct ARI is more interesting

  • Only static ancestor scopes are visible (accessible)

  • A subprogram is callable only when all of its static ancestor subprograms are active

  • Need to find all ARI from the closely nested one

  • Static chains

  • Chain of static links

  • Static link is added in ARI

  • Called as a static scope pointer

  • Located below parameters in ARI

  • Point to bottom of ARI of static parent

  • Used to implement the accesses to nonlocal variables in static-scoped languages

  • Static depth

  • How deeply it is nested in the outermost scope

  • Nesting depth (chain offset)

  • Length of static chain needed to reach correct ARI

# Global scope ...
# Static depth of the global, f1, f2 and f3 are 0,1, 2 and 3, respectively
def f1():
    def f2():
        # f3 refer f1 โ†’ chain offset is 2
        def f3():
            # f3 refer f2 โ†’ chain offset is 1
            ...
        # end of f3 โ€ฆ
    # end of f2
    ...
# end of f1

  • Nonlocal access using static chains

  • In position 1

  • Reference to A (local variable A in Sub1): chain_offset/local_offset (0,3)

  • why local_offset is 3?, because A is the first local variable

  • Reference to B (nonlocal variable B in Bigsub): chain_offset/local_offset (1,4)

  • Reference to C (nonlocal variable C in Bigsub): chain_offset/local_offset (1,5)

  • Variable B in Sub2 is not accessible

  • After Sub1 complete, control returns to Sub3

  • In position 2

  • Reference to E (local variable E in Sub3): chain_offset/local_offset (0,4)

  • Reference to B (nonlocal variable B in Sub2): chain_offset/local_offset (1,4)

  • why local_offset is 4?, because B is the first local variable, but Sub2 has one parameter

  • Reference to A (nonlocal variable A in Bigsub): chain_offset/local_offset (2,3)

  • After Sub3 complete, control returns to Sub2

  • In position 3

  • Reference to A (nonlocal variable A in Bigsub): chain_offset/local_offset (1,3)

  • Reference to D โ†’\rightarrowโ†’ static semantic error because there is no visible D

  • Reference to E (local variable E in Sub2): chain_offset/local_offset (0,5)

  • For variable A

  • Position 1: (0,3) local

  • Position 2: (2,3) two levels away

  • Position 3: (1,3) one level away

  • When return, ARI at top of stack is removed.

  • When call, how to decide static link?

  • Can use dynamic link to find until static parent of called program

  • Perform search

  • Or when Sub3 call Sub1, static parent of Sub1 is Bigsub and if compiler decide that Sub3 is two-level inside Bigsub โ†’\rightarrowโ†’ find second static link from Sub3

  • Execution traces:

  • Bigsub calls A

  • A calls C

  • C calls B

  • Criticism

  • Referencing nonlocal variable beyond static parent: more cost required

  • For time-critical program, it is difficult to estimate costs

  • Static Chain์˜ ๋ฌธ์ œ์ : ๋ถ€๋ชจ ํ•จ์ˆ˜์— ๊ฐ€๊นŒ์šด ๋ณ€์ˆ˜๋Š” ๋น ๋ฅด๊ฒŒ ์ฐพ์ง€๋งŒ, ์กฐ์ƒ ํ•จ์ˆ˜(Static Grandparent)๊นŒ์ง€ ์—ฌ๋Ÿฌ ๋‹จ๊ณ„ ๊ฑฐ์Šฌ๋Ÿฌ ์˜ฌ๋ผ๊ฐ€์•ผ ํ•˜๋ฉด โ†’\rightarrowโ†’ ๋น„์šฉ ์ฆ๊ฐ€ (Static Link jump ๋งŽ์•„์ง)

  • Display: ๊ฐ Static Level๋งˆ๋‹ค ํ˜„์žฌ ํ™œ์„ฑํ™”๋œ Activation Record์˜ ํฌ์ธํ„ฐ๋ฅผ ํ…Œ์ด๋ธ”(๋ฐฐ์—ด) ํ˜•ํƒœ๋กœ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ• โ†’\rightarrowโ†’ ํ•œ ๋ฒˆ์— ๋ฐ”๋กœ ์ ‘๊ทผ

  • O(1)O(1)O(1) ์‹œ๊ฐ„์— ์กฐ์ƒ ๋ธ”๋ก ๋ณ€์ˆ˜ ์ ‘๊ทผ ๊ฐ€๋Šฅ (ํ•œ ๋ฒˆ์˜ table lookup)

  • ํŠนํžˆ ์ค‘์ฒฉ์ด ๊นŠ์€ ํ”„๋กœ๊ทธ๋žจ์—์„œ ๋ณ€์ˆ˜ ์ ‘๊ทผ ๋น„์šฉ์ด ํ™• ์ค„์–ด๋“ฆ

  • Real-time ์‹œ์Šคํ…œ(์‹œ๊ฐ„ ์˜ˆ์ธก์ด ํ•„์š”ํ•œ ํ”„๋กœ๊ทธ๋žจ)์—๋„ ์œ ๋ฆฌ

Blocks

  • User-specified local scopes

  • Advantage: cannot interfere with any other variable with the same name

  • ๋‹ค๋ฅธ ์ด๋ฆ„์ด ๊ฐ™์€ ๋ณ€์ˆ˜๋“ค๊ณผ ์ถฉ๋Œ์„ ํ”ผํ•  ์ˆ˜ ์žˆ์Œ

  • Treated as parameterless subprograms and called from the same place

  • subprogram์ฒ˜๋Ÿผ "ํ˜ธ์ถœ"๋˜๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ, "๊ทธ ์ž๋ฆฌ์—" ์‹คํ–‰๋จ (์ˆœ์ฐจ์‹คํ–‰)

  • Every block has an activation record

{ 
    int temp;
    temp = list[upper];
    list[upper] = list[lower];
    list[lower] = temp;
}

  • ๋™์ž‘ ํ๋ฆ„
  1. { ๋ฅผ ๋งŒ๋‚˜๋ฉด
  • ์ƒˆ๋กœ์šด Activation Record๊ฐ€ ๋งŒ๋“ค์–ด์ง.
  • ์ด Activation Record์—๋Š” temp ๋ฅผ ์œ„ํ•œ ๊ณต๊ฐ„์ด ํฌํ•จ.
  1. ๋ธ”๋ก ๋‚ด๋ถ€ ์ฝ”๋“œ ์‹คํ–‰.
  2. } ๋ฅผ ๋งŒ๋‚˜๋ฉด
  • ์ด Activation Record๊ฐ€ ์Šคํƒ์—์„œ ์ œ๊ฑฐ๋œ๋‹ค.

  • Function(subprogram) vs block

๊ตฌ๋ถ„ํ•จ์ˆ˜ ํ˜ธ์ถœ (Function Call)๋ธ”๋ก ์Šค์ฝ”ํ”„ (Block Scope)
Local variables์žˆ์Œ์žˆ์Œ
Parameters์žˆ์Œ์—†์Œ (๋งค๊ฐœ๋ณ€์ˆ˜ ์—†์Œ)
Dynamic link์žˆ์Œ (๋‹ค์Œ ํ˜ธ์ถœ์„ ์œ„ํ•ด)์žˆ์„ ์ˆ˜๋„ ์žˆ์Œ (์ค‘์ฒฉ๋œ ๋ธ”๋ก์—์„œ ์ƒ์œ„ ๋ธ”๋ก ์ฐธ์กฐ)
Return addressํ•ญ์ƒ ์žˆ์Œ (ํ˜ธ์ถœ ์ดํ›„ ๋ณต๊ท€๋ฅผ ์œ„ํ•ด)๊ฑฐ์˜ ์—†์Œ (๋ธ”๋ก์€ "ํ˜ธ์ถœ"์ด ์•„๋‹ˆ๋ผ "์ˆœ์ฐจ ์‹คํ–‰"์ด๋ผ ํ•„์š” ์—†์Œ)
  • Blocks can be implemented somewhat simpler and more efficient way
  • Allocated after the local variables
  • Block variables can be addressed exactly as if they were local variables
  • The maximum amount of storage required for block variables can be statically determined โ†’\rightarrowโ†’ f and g occupy the same memory locations as a and b, because a and b are popped off the stack when their block is exited (before f and g are allocated)c
  • Static Chain of block
  • ๋ธ”๋ก์ด๋‚˜ ํ•จ์ˆ˜ ์•ˆ์—์„œ ๋ฐ”๊นฅ์ชฝ์— ์žˆ๋Š” ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ Static Link๋ฅผ ํƒ€๊ณ  ์ฐพ์•„๊ฐ
void main() {
    int x, y, z; // main locals
    while (...) {
        int a, b, c; // block1 locals
        while (...) {
            int d, e; // block2 locals
            ...
            a = d + 1; // block2์—์„œ block1์˜ a์— ์ ‘๊ทผ
        }
    }
}

  • ํ˜„์žฌ ์œ„์น˜: block2 (d, e)
  • ์ ‘๊ทผํ•˜๋ ค๋Š” ๋ณ€์ˆ˜: block1์— ์žˆ๋Š” a
  • ๊ณผ์ •:
  1. block2์˜ Activation Record์—์„œ ์‹œ์ž‘
  2. Static Link๋ฅผ ๋”ฐ๋ผ block1์˜ Activation Record๋กœ ์ด๋™
  3. block1 ARI ์•ˆ์—์„œ a ๋ฅผ local offset์œผ๋กœ ์ฐพ์•„์„œ ์ ‘๊ทผ

Dynamic Scoping

  • Deep access and shallow access

  • Not concepts related to deep and shallow binding

  • Deep Access / Shallow Access๋Š” โ†’\rightarrowโ†’ "๋ณ€์ˆ˜์— ์ ‘๊ทผ(access)"ํ•  ๋•Œ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์–ด๋–ป๊ฒŒ ์ฐพ๋Š”๊ฐ€์— ๊ด€๋ จ.

  • Deep Binding / Shallow Binding์€ โ†’\rightarrowโ†’ "subprogram์„ ํ˜ธ์ถœ(call)"ํ•  ๋•Œ ํ™˜๊ฒฝ(environment) ์„ ์–ด๋–ป๊ฒŒ ๋ฌถ๋Š”๊ฐ€์— ๊ด€๋ จ

  • Deep and shallow accesses do not result in different semantics

  • ์ตœ์ข…์ ์œผ๋กœ ์ฐพ์•„์„œ ์ฝ๋Š” ๋ณ€์ˆ˜๋Š” ๋™์ผ

  • ๋‹ฌ๋ผ์ง€๋Š” ๊ฒƒ์€ ์„ฑ๋Šฅ(performance)

  • Deep access

  • Searching through the ARI of active subprogram from most recently activated

  • Dynamic chain is used

  • Access may require searches deep into stack

  • No static link

  • Reference to x in Sub3 โ†’\rightarrowโ†’ searching for all ARI in stack (follow 4 dynamic links, examine 10 variable)

  • Reference to v in Sub3 โ†’\rightarrowโ†’ found in recent Sub1

  • Deep access (two differences from static scope)

  • There is no way to determine at compile time the length of the chain

  • Slower execution speeds than static-scoped languages

  • Activation records must store the names of variables for the search

ํ•ญ๋ชฉ์„ค๋ช…
๊ฒ€์ƒ‰ ๋Œ€์ƒํ˜„์žฌ ํ™œ์„ฑํ™”๋œ ARI๋“ค
๊ฒ€์ƒ‰ ๋ฐฉํ–ฅ์ตœ๊ทผ ํ™œ์„ฑํ™”๋œ ARI โ†’\rightarrowโ†’ ์˜ค๋ž˜๋œ ARI ์ˆœ์„œ
๋งํฌ ๊ตฌ์กฐDynamic Chain ์‚ฌ์šฉ
๊ฒ€์ƒ‰ ๋น„์šฉ๋ณ€์ˆ˜ ์œ„์น˜์— ๋”ฐ๋ผ O(depth)O(\text{depth})O(depth) ๋งŒํผ ๊ฑธ๋ฆผ
๋ฉ”๋ชจ๋ฆฌ ์˜ค๋ฒ„ํ—ค๋“œ์—†์Œ (์ถ”๊ฐ€ ํ…Œ์ด๋ธ” ํ•„์š” ์—†์Œ)
Semantics ๋ณ€ํ™”์—†์Œ (์ฐพ๋Š” ๊ฒฝ๋กœ๋งŒ ๋‹ค๋ฅผ ๋ฟ ๊ฒฐ๊ณผ๋Š” ๊ฐ™์Œ)
  • Shallow access

  • Semantics of deep access and shallow access are identical

  • Variables declared in subprograms are not stored in the ARI of those subprograms

  • Have a separate stack for each variable name

  • โ†’\rightarrowโ†’ ์ตœ๊ทผ์— ํ• ๋‹น๋œ ๊ฐ’์„ ๋น ๋ฅด๊ฒŒ ์ฐพ์•„ ์“ฐ๋Š” ๋ฐฉ์‹

  • Fast references to variables

  • But maintaining the stacks at the entrances and exits of subprograms is costly

  • ๋ณ€์ˆ˜ ์ €์žฅ ์œ„์น˜ โ†’\rightarrowโ†’ ๋ณ€์ˆ˜ ์ด๋ฆ„๋งˆ๋‹ค ๋ณ„๋„์˜ ์Šคํƒ

  • ํ™œ์„ฑํ™”๋œ ๊ฐ’ โ†’\rightarrowโ†’ ์Šคํƒ์˜ ์ตœ์ƒ๋‹จ(top)์— ์กด์žฌ

  • ์ƒˆ๋กœ์šด subprogram ํ˜ธ์ถœ ์‹œ โ†’\rightarrowโ†’ ํ•„์š”ํ•œ ๋ณ€์ˆ˜ ์ด๋ฆ„ ์Šคํƒ์— ์ƒˆ๋กœ์šด ๊ฐ’์„ push

  • subprogram ์ข…๋ฃŒ ์‹œ โ†’\rightarrowโ†’ ๋ณ€์ˆ˜ ์ด๋ฆ„ ์Šคํƒ์—์„œ ๊ฐ’์„ pop

  • ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ โ†’\rightarrowโ†’ ๋ณ€์ˆ˜ ์ด๋ฆ„๋ณ„๋กœ ๋ณ„๋„๋กœ ๊ด€๋ฆฌ

  • Deep access: fast subprogram linkage but costly for nonlocal referencing

  • Shallow access: faster references to nonlocals but costly in terms of subprogram linkage

ํ•ญ๋ชฉDeep AccessShallow Access
์ ‘๊ทผ ๊ฒฝ๋กœDynamic Link ํƒ€๊ณ  ์˜ฌ๋ผ๊ฐ๋ณ€์ˆ˜ ์ด๋ฆ„๋ณ„ ๋ณ„๋„ ์Šคํƒ ์ตœ์ƒ๋‹จ
์ ‘๊ทผ ์‹œ๊ฐ„O(depth)O(\text{depth})O(depth)O(1)O(1)O(1)
ํ”„๋กœ๊ทธ๋žจ ๊ตฌ์กฐ ๋ณต์žก๋„๋‹จ์ˆœ๋ณต์žก (๊ฐ ๋ณ€์ˆ˜๋งˆ๋‹ค ์Šคํƒ ํ•„์š”)
์„œ๋ธŒํ”„๋กœ๊ทธ๋žจ ๊ด€๋ฆฌ ๋น„์šฉ์ž‘์Œํผ (stack push/pop ํ•„์š”)
Semantics ๋ณ€ํ™”์—†์Œ (๋™์ž‘์€ ๋™์ผ)์—†์Œ (๋™์ž‘์€ ๋™์ผ)
์ตœ๊ทผ ์ˆ˜์ •: 26. 6. 12. ์˜คํ›„ 3:28
Contributors: kmbzn, Claude Sonnet 4.6
Prev
8. Subprogram
Next
10.1. Abstract Data Types and Encapsulation Constructs

BUILT WITH

CloudflareNode.jsGitHubGitVue.jsJavaScriptVSCodenpm

All trademarks and logos are property of their respective owners.
ยฉ 2026 kmbzn ยท MIT License