TropicSapling/triforce

Possible C implementation of 'return ... from ...'

Opened this issue · 0 comments

#include <stdio.h>
#include <setjmp.h>

jmp_buf buf;

int g() {
  printf("Returned from g()\n");
  longjmp(buf, 123);
}

int f() {
  int r = setjmp(buf);
  if(r == 0) {
    g();
    printf("Returned from f()\n");
    return 456;
  }
  return r;
}

int main(void) {
  printf("%d\n", f());
  return 0;
}

=

func g -> int {
    println "Returned from g()";
    return 123 from f;
}

func f -> int {
    g();
    return 456;
}

func init {
    println f;
}

Both programs would print:

Returned from g()
123