Commits

Paweł Wieczorek committed b9a60d4

Fixed handling arguments passed in routine call, in the WHILE x86 compiler

  • Participants
  • Parent commits ac88f2f
  • Branches very_simple_while_compiler

Comments (0)

Files changed (2)

samples/WHILE/006_call.while

-# Compiled by Opifex, devel-version, built at Tue Aug 27 01:01:21 CEST 2013 
+procedure fibaux()
+{
+    if (n = 1) {
+        result := fibaux1;
+        throw EXIT;
+    }
+    if (n = 0) {
+        result := fibaux2;
+        throw EXIT;
+    }
+    tmp := fibaux1;
+    fibaux1 := fibaux1 + fibaux2;
+    fibaux2 := tmp;
+    n := n - 1;
+    fibaux();
+}
 
-.global WHILE_fibaux 
-.global WHILE_main 
-.global WHILE_fib 
+procedure fib()
+{
+    fibaux1 := 1;
+    fibaux2 := 0;
+    fibaux();
+}
 
-.section .text 
-
-WHILE_fibaux : 
-    pushl %ebp 
-    movl %esp , %ebp 
-    movl WHILE_VAR_n , %eax 
-    pushl %eax 
-    movl $0 , %eax 
-    pushl %eax 
-    popl %eax 
-    popl %ebx 
-    cmp %eax , %ebx 
-    jne _L0004_if_else 
-    movl WHILE_VAR_fibaux1 , %eax 
-    movl %eax , WHILE_VAR_result 
-    movl $0 , %eax 
-    movl %eax , %eax 
-    jmp _L0000_frame_leave 
-    jmp _L0003_if_after 
-_L0004_if_else : 
-_L0003_if_after : 
-    movl WHILE_VAR_n , %eax 
-    pushl %eax 
-    movl $1 , %eax 
-    pushl %eax 
-    popl %eax 
-    popl %ebx 
-    cmp %eax , %ebx 
-    jne _L0002_if_else 
-    movl WHILE_VAR_fibaux2 , %eax 
-    movl %eax , WHILE_VAR_result 
-    movl $0 , %eax 
-    movl %eax , %eax 
-    jmp _L0000_frame_leave 
-    jmp _L0001_if_after 
-_L0002_if_else : 
-_L0001_if_after : 
-    movl WHILE_VAR_fibaux1 , %eax 
-    movl %eax , WHILE_VAR_tmp 
-    movl WHILE_VAR_fibaux1 , %eax 
-    pushl %eax 
-    movl WHILE_VAR_fibaux2 , %eax 
-    pushl %eax 
-    popl %eax 
-    popl %ebx 
-    addl %eax , %ebx 
-    movl %ebx , WHILE_VAR_fibaux1 
-    movl WHILE_VAR_tmp , %eax 
-    movl %eax , WHILE_VAR_fibaux2 
-    movl WHILE_VAR_n , %eax 
-    pushl %eax 
-    movl $1 , %eax 
-    pushl %eax 
-    popl %eax 
-    popl %ebx 
-    subl %eax , %ebx 
-    movl %ebx , WHILE_VAR_n 
-    call WHILE_fibaux 
-    addl $0 , %esp 
-_L0000_frame_leave : 
-    movl %ebp , %esp 
-    popl %ebp 
-    ret 
-
-WHILE_fib : 
-    pushl %ebp 
-    movl %esp , %ebp 
-    movl $1 , %eax 
-    movl %eax , WHILE_VAR_fibaux1 
-    movl $0 , %eax 
-    movl %eax , WHILE_VAR_fibaux2 
-    call WHILE_fibaux 
-    addl $0 , %esp 
-_L0005_frame_leave : 
-    movl %ebp , %esp 
-    popl %ebp 
-    ret 
-
-WHILE_main : 
-    pushl %ebp 
-    movl %esp , %ebp 
-    call PROSTAK_readint 
-    movl %eax , WHILE_VAR_n 
-    call WHILE_fib 
-    addl $0 , %esp 
-    pushl WHILE_VAR_fibaux1 
-    call PROSTAK_writeint 
-    addl $4 , %esp 
-_L0006_frame_leave : 
-    movl %ebp , %esp 
-    popl %ebp 
-    ret 
-
-.section .data 
-
-WHILE_VAR_result : 
-    .int 0 
-
-WHILE_VAR_fibaux2 : 
-    .int 0 
-
-WHILE_VAR_n : 
-    .int 0 
-
-WHILE_VAR_fibaux1 : 
-    .int 0 
-
-WHILE_VAR_tmp : 
-    .int 0 
-
-
+procedure main()
+{
+    read n;
+    fib();
+    write result;
+    
+}

source/Compiler/WhileX86Compiler.ml

                 ; leaving_code
                 ]
 
-        | AST.CMD_Call (routine, args) ->
+        | AST.CMD_Call (routine, arguments) ->
             let routine_symbol = Context.lookup_for_symbol context routine in
-            call_routine_symbol_lv32_args routine_symbol []
+            let (code, _) = call_routine_symbol context routine_symbol arguments in
+            code
 
         | AST.CMD_Assign (variable, arithmetic_expression) ->
             let (expr_code, expr_reg)   = compile_arithmetic_expression context arithmetic_expression in