Skip to content

Instantly share code, notes, and snippets.

@zeptometer
Created August 7, 2026 03:59
Show Gist options
  • Select an option

  • Save zeptometer/2cef7fd60ad9e1a0fcf4774a1788de84 to your computer and use it in GitHub Desktop.

Select an option

Save zeptometer/2cef7fd60ad9e1a0fcf4774a1788de84 to your computer and use it in GitHub Desktop.
input and output of tcc
void cspec
spower(int n)
{
int vspec x;
int cspec f;
int i;
if (n < 0) {
return `{ return 0; };
}
x = param(int, 0);
f = `@x;
for (i = 1; i<n; i++) {
f = `(@x * @f);
}
return `{ return @f; };
}
main(int argc, char** argv)
{
int n;
int (*f)(int);
n = 10;
f = compile(spower(n), int);
printf("%d\n", (*f)(2));
}
void _tc_cvi_0code(void *__c_arg);
struct _tc_cvi_0
{
void (*code)(void *);
unsigned int lab;
};
unsigned long _tc_cvi_1code(void *__c_arg);
struct _tc_cvi_1
{
unsigned long (*code)(void *);
unsigned int lab;
_tc_vspec_t _x;
};
unsigned long _tc_cvi_2code(void *__c_arg);
struct _tc_cvi_2
{
unsigned long (*code)(void *);
unsigned int lab;
_tc_vspec_t _x;
_tc_cspec_t _spec__2_0;
};
void _tc_cvi_3code(void *__c_arg);
struct _tc_cvi_3
{
void (*code)(void *);
unsigned int lab;
_tc_cspec_t _spec__3_0;
};
_tc_cspec_t spower(int n)
{
_tc_closure_t _tc_cspec;
_tc_vspec_t x;
_tc_cspec_t f;
int i;
if (n < 0)
{
return ((_tc_cspec = ((void *)tc_aalloc(16))),
(*((void (**)(void *))((char *)((unsigned long)_tc_cspec))) = (void (*)(void *))_tc_cvi_0code),
(*((unsigned int *)(((char *)((unsigned long)_tc_cspec)) + 8)) = (unsigned int)0),
_tc_cspec);
}
x = _tc_paramf(4, 0, 0);
f = ((_tc_cspec = ((void *)tc_aalloc(24))),
(*((unsigned long (**)(void *))((char *)((unsigned long)_tc_cspec))) = (unsigned long (*)(void *))_tc_cvi_1code),
(*((unsigned int *)(((char *)((unsigned long)_tc_cspec)) + 8)) = (unsigned int)0),
(*((_tc_vspec_t *)(((char *)((unsigned long)_tc_cspec)) + 16)) = (_tc_vspec_t)x),
_tc_cspec);
for (i = 1;
i < n;
i++)
{
f = ((_tc_cspec = ((void *)tc_aalloc(32))),
(*((unsigned long (**)(void *))((char *)((unsigned long)_tc_cspec))) = (unsigned long (*)(void *))_tc_cvi_2code),
(*((unsigned int *)(((char *)((unsigned long)_tc_cspec)) + 8)) = (unsigned int)0),
(*((_tc_vspec_t *)(((char *)((unsigned long)_tc_cspec)) + 16)) = (_tc_vspec_t)x),
(*((_tc_cspec_t *)(((char *)((unsigned long)_tc_cspec)) + 24)) = (_tc_cspec_t)f),
_tc_cspec);
}
return ((_tc_cspec = ((void *)tc_aalloc(24))),
(*((void (**)(void *))((char *)((unsigned long)_tc_cspec))) = (void (*)(void *))_tc_cvi_3code),
(*((unsigned int *)(((char *)((unsigned long)_tc_cspec)) + 8)) = (unsigned int)0),
(*((_tc_cspec_t *)(((char *)((unsigned long)_tc_cspec)) + 16)) = (_tc_cspec_t)f),
_tc_cspec);
}
int main(int argc, char **argv)
{
_tc_closure_t _tc_cspec;
int n;
int (*f)(int);
n = 10;
f = _tc_compilef(spower(n), 4, 0);
printf("%d\n", (*f)(2));
}
void _tc_cvi_0code(void *c_arg)
{
struct _tc_cvi_0 *c = c_arg;
/* declare and init labels */
/* declare and init locals */
/* declare and init c/vspecs and run-time constants */
/* declare and init statics */
/* declare and init free vars */
/* init more locals */
/* create label, if necessary */
if (c->lab)
v_label(c->lab);
/* code */
comment(begin forest);
v_retii(0);
comment(end forest);
}
unsigned long _tc_cvi_1code(void *c_arg)
{
struct _tc_cvi_1 *c = c_arg;
/* declare and init labels */
/* declare and init locals */
v_reg_type il31;
/* declare and init c/vspecs and run-time constants */
v_reg_type _x = (v_reg_type)c->_x;
/* declare and init statics */
/* declare and init free vars */
/* init more locals */
/* create label, if necessary */
if (c->lab)
v_label(c->lab);
/* code */
comment(begin forest);
v_getreg(&il31, I_I, V_VAR);
if (_tc_stackp(_x))
{
v_ldii(il31, v_lp, _tc_offset(_x));
}
else
{
v_movi(il31, _tc_reg(_x));
}
return il31;
v_putreg(il31, I_I);
comment(end forest);
}
unsigned long _tc_cvi_2code(void *c_arg)
{
struct _tc_cvi_2 *c = c_arg;
/* declare and init labels */
/* declare and init locals */
v_reg_type il30;
v_reg_type il31;
/* declare and init c/vspecs and run-time constants */
v_reg_type _x = (v_reg_type)c->_x;
_tc_closure_t _spec__2_0 = (_tc_closure_t)c->_spec__2_0;
/* declare and init statics */
/* declare and init free vars */
/* init more locals */
/* create label, if necessary */
if (c->lab)
v_label(c->lab);
/* code */
comment(begin forest);
il31 = _spec__2_0->code((void *)_spec__2_0);
v_getreg(&il30, I_I, V_VAR);
if (_tc_stackp(_x))
{
v_ldii(il30, v_lp, _tc_offset(_x));
}
else
{
v_movi(il30, _tc_reg(_x));
}
v_putreg(il30, I_I);
v_muli(il31, il31, il30);
return il31;
v_putreg(il31, I_I);
comment(end forest);
}
void _tc_cvi_3code(void *c_arg)
{
struct _tc_cvi_3 *c = c_arg;
/* declare and init labels */
/* declare and init locals */
v_reg_type il31;
/* declare and init c/vspecs and run-time constants */
_tc_closure_t _spec__3_0 = (_tc_closure_t)c->_spec__3_0;
/* declare and init statics */
/* declare and init free vars */
/* init more locals */
/* create label, if necessary */
if (c->lab)
v_label(c->lab);
/* code */
comment(begin forest);
il31 = _spec__3_0->code((void *)_spec__3_0);
v_reti(il31);
comment(end forest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment