Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

JavaScript OS

Name: FrozenVoid 2009-03-04 1:54

Suppose you have all the security crap sorted out.
What would be an obstacle to creating a JavaScript OS?

Name: Anonymous 2009-03-04 18:27

>>87

fact.c

static unsigned long fact_recur(unsigned long n, unsigned long acc)
{
    return n ? fact_recur(n-1, acc*n) : acc;
}

unsigned long fact(unsigned long n)
{
    return fact_recur(n, 1);
}


Compile with gcc -O3 -S fact.c

fact.s

        .file   "fact.c"
        .text
        .p2align 4,,15
.globl fact
        .type   fact, @function
fact:
        pushl   %ebp
        movl    $1, %eax
        movl    %esp, %ebp
        movl    8(%ebp), %edx
        testl   %edx, %edx
        je      .L3
        .p2align 4,,7
        .p2align 3
.L6:
        imull   %edx, %eax
        subl    $1, %edx
        jne     .L6
.L3:
        popl    %ebp
        ret
        .size   fact, .-fact
        .ident  "GCC: (Debian 4.3.2-2) 4.3.3 20090110 (prerelease)"
        .section        .note.GNU-stack,"",@progbits


Notice that the compiled fact function has no recursive calls, because GCC is smart enough the optimize the tail-recursion into a loop.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List