Question

I'm playing around with making an interpreter that does memory allocation in the style of Chicken Scheme. The basic idea is:

int main() {
    instruction instructions[] = { zero_root, print_root, hello_world,
                    hello_world, stop };

    top_ip.go = &instructions[0];

    setjmp(top);

    (*top_ip.go)(top_ip);

    return 0;
}
                                                          89,10-17      Bot

and

/* The following function is machine dependent */
static bool is_time_to_gc(){
    /* Is allocated on the stack */
    char stack_top;

    /* It's address is therefore the stack's top  */
    return &stack_top >= STACK_LIMIT;
}

static void goto_next_instruction(struct instruction_pointer ip) {
    ++ip.go;

    if (is_time_to_gc()) {
            /*
             * Some complicated garbage collection stuff which I haven't
             * completed yet.
             */

            top_ip.go = ip.go;
            longjmp(top, 0);
    }

    (*ip.go)(ip);
}

and a sample instruction is:

static void hello_world(struct instruction_pointer ip) {
    printf("Hello World!\n");

    goto_next_instruction(ip);
}

What I need to know is what the value for STACK_LIMIT should be (I also need to know if the stack grows up or downwards.) How can I get platform specific information on stack limits?

Était-ce utile?

La solution

man getrlimit. also check the limits imposed by your shell usually in /etc/login.conf (if it's an sh derivative you can view them by typing limit).

:) cheers.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top