Skip to content

Instantly share code, notes, and snippets.

@utgwkk
Created January 17, 2018 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utgwkk/69455d73c268a8077705d4df5e39e9c3 to your computer and use it in GitHub Desktop.
Save utgwkk/69455d73c268a8077705d4df5e39e9c3 to your computer and use it in GitHub Desktop.
10! を求めるCプログラム
#include <stdio.h>
#include <stdlib.h>
union MLType {
int value;
union MLType (*func)(union MLType, union MLType);
union MLType *tuple;
};
typedef union MLType _t;
_t _b0(_t, _t);
_t _toplevel(_t, _t);
_t _b0(_t _letrec0, _t _letrecarg0) {
const _t _lhs0 = _letrecarg0;
const _t _rhs0 = (_t){1};
const _t _cond0 = (_t){_lhs0.value < _rhs0.value};
if (_cond0.value) {
return (_t){1};
} else {
const _t _lhs1 = _letrecarg0;
const _t _app0 = _letrec0;
const _t _lhs2 = _letrecarg0;
const _t _rhs2 = (_t){-1};
const _t _appval0 = (_t){_lhs2.value + _rhs2.value};
const _t _fp1 = _app0.tuple[0];
const _t _rhs1 = _fp1.func(_app0, _appval0);
return (_t){_lhs1.value * _rhs1.value};
};
}
_t _toplevel(_t p0, _t p1) {
_t _letrec0;
_letrec0.tuple = malloc(1 * sizeof(_t));
_letrec0.tuple[0].func = _b0;
const _t _app1 = _letrec0;
const _t _appval1 = (_t){10};
const _t _fp0 = _app1.tuple[0];
return _fp0.func(_app1, _appval1);
}
int main (void) {
printf("%d\n", _toplevel((_t){0}, (_t){0}).value);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment