v int max int x int y return
- Slides: 53
함수 선언 v 선언 예 int max (int x, int y) { return x > y ? x : y; } fun int max (int x, int y) : if x > y then return x else return y v 호출 예 c = max(a, b); © 숙대 창병모 5
매개변수 전달 방법 v 값 전달(pass by value) v 참조 전달(pass by reference) v 값-결과 전달(pass by value-result) v 이름 전달(pass by name) © 숙대 창병모 9
예제 v intswap의 C 버전 void intswap(int *px; int *py) { int t; t = *px; *px = *py; *py = t; } v 사용 int a, b; intswap(&a, &b); © 숙대 창병모 15
함수 호출 구현 v 재귀 함수 호출 예 fun int fact(int n) : if n <= 1 then return 1 else return n * fact(n-1) … v = fact(3); © 숙대 창병모 27
Simplified Machine Model Registers Code(Text) Runtime Stack Program Counter Heap Environment Pointer Data © 숙대 창병모 30
Memory Layout v Registers, Program counter v Code(Text) segment v Machine instructions (read-only, sharable) v Stack local(automatic) variables, temporary variables, v return address, caller's environment (registers) v v Environment pointer v points to current stack position v v © 숙대 창병모 Block entry: add new activation record to stack Block exit: remove most recent activation record 31
Memory Layout v Data segment Static & Global variables v Initialized data segment v v v e. g. int maxcount = 99; (initialized) Uninitialized data segment v v Heap e. g. long sum[1000]; dynamic memory allocation v malloc() in C, new() in Pascal, Java v © 숙대 창병모 32
Example Return value Control link Return address Parameters Local variables v Function fun fact(n) : if n <= 1 then return 1 else return n * fact(n-1) v Return value v location to put fact(n) v Parameter Environment Pointer © 숙대 창병모 v set to value of n by calling sequence 35
Function call max(3, 5) fun max(x, y) : if x > y then return x else return y max(3, 5) Control link Return addr x 3 y 5 Environment Pointer © 숙대 창병모 36
Function call fact(k) Control link fun fact(n) : if n <= 1 then return 1 else return n * fact(n-1) Return addr n k fact(k-1) Environment Pointer © 숙대 창병모 37
Function call/return fact(3) Control link Return addr fact(2) n 3 fact(2) 2 fun fact(n) : if n <= 1 then return 1 else return n * fact(n-1) Control link Return addr fact(1) n 2 fact(1) 1 Control link Return addr n © 숙대 창병모 1 38
접근 링크를 이용한 정적 스코프 let int x=1, fun g(z): return x+z, fun f(y): let int x = y+1 in return g(y*x) end in f(3); end © 숙대 창병모 x f(3) g(12) 1 control link access link y 3 x 4 control link access link z 12 41
예제 let int a = 0, int b = 0, int c = 0, fun int max(int x, int y): if x > y then return x else return y in read a; read b; c = max(a, b); print c end © 숙대 창병모 46
함수 선언 구현 void stmt(void) { … switch(token) { … case LET: } } © 숙대 창병모 … if (token = FUN) // 함수 선언 fun T f(T x {, T x}): S { match(FUN); match(token); // return type if (token==ID) { // 함수 이름 loc = tokenval; symtable[loc]. token = FUNID; symtable[loc]. val = pc; // 현재 위치 pc 값 matchfun(); // 나머지 선언 부분 skip } } … 48
함수 호출 구현 int factor(void) { … if (token == FUNID) // 함수 호출 f(E {, E}) { loc = tokenval; funstart = symtable[loc]. val; // 함수 시작 위치 token = get. Token(); if (token == ‘(‘) // 실매개변수 계산 { match(‘(‘); 실매개변수 계산하여 임시저장; } Return value Control link Return address Parameters Local variables ep lastentry // set up activation record symtable에 RV, CL 엔트리를 만든다; CL 엔트리 현재 ep 값 // control link 저장 ep 값 갱신 // 새로운 AR 가리키도록 symtable에 RA 엔트리를 만든다; RA 엔트리 현재 pc 값; // return address 저장 match(‘)’); © 숙대 창병모 50
함수 반환 구현 void stmt(void) { … switch(token) { … case RETURN: // return E match(RETURN); result = expr(); symtable[ep-1]. val = result; break; } // 반환 값 계산 // RV 엔트리에 값 저장(반환) } © 숙대 창병모 53
- Int max(int x int y)
- Int sum(int a int n) int sum=0 i
- Int max
- Divideint
- Inheritance calculator
- Public void drawsquare(int x, int y, int len)
- Local maximum
- Int max
- Max int c++
- Int factorial(int n)
- Void swap(int a int b)
- Interface myinterface int foo(int x)
- Arduino constant int
- Void f(int i) int j=0
- Int main(int argc, char** argv)
- Int argc char argv
- Int main int num 4
- Nnxn com
- Return of experience rex template
- Cardiovascular changes
- The crossing of the return threshold
- A a- b b- pneumatic circuit
- Human resources return on investment
- Return on common stockholders' equity ratio formula
- The return of the prodigal son murillo
- Sp annual returns
- Nominal versus real returns
- Carriage inwards in financial statement
- Learning curve ekonomi manajerial
- Return adalah
- Return on common stockholders equity
- Return valve function
- Statistics mathisfun
- Midsummer chaos
- Class diagram netflix
- Rosf ratio
- Eaoi
- Variance of 3 asset portfolio formula
- Expected return
- Gravity return single acting cylinder
- Return on average equity
- Standard deviation of return
- Draw a supply curve for tax return preparation software
- Social rate of return
- Standard life global absolute return strategies
- Ingram
- Risk and return
- Required rate of return
- Difference between risk and return
- Plain vanilla derivatives
- Data centered architecture
- Unlevered return on assets
- Target rate of return pricing
- Tapvc