Skip to content

Instantly share code, notes, and snippets.

@bkerley
Created August 3, 2011 11:34
Show Gist options
  • Save bkerley/1122420 to your computer and use it in GitHub Desktop.
Save bkerley/1122420 to your computer and use it in GitHub Desktop.
#include "symbol.h"
#include "init.h"
void JJ()
{
long a,b,r;
a = (long)stack_pop(); // (long)stack_pop() turns into this
b = (long)stack_pop();
r = a + b;
stack_push((stack_entry)r); // stack_push((stack_entry)r) turns into this
}
void JI()
{
long a,b,r; // binop(a * b) turns into this whole function
a = (long)stack_pop();
b = (long)stack_pop();
r = a * b;
stack_push((stack_entry)r);
}
void JL()
{
long a,b,r;
a = (long)stack_pop();
b = (long)stack_pop();
r = b - a;
stack_push((stack_entry)r);
}
void JN()
{
long a,b,r;
a = (long)stack_pop();
b = (long)stack_pop();
r = b / a;
stack_push((stack_entry)r);
}
void IN()
{
long a,b,r;
a = (long)stack_pop();
b = (long)stack_pop();
r = b % a;
stack_push((stack_entry)r);
}
void JFKOFFF()
{
long a,b,r;
a = (long)stack_pop();
b = (long)stack_pop();
r = b << a;
stack_push((stack_entry)r);
}
void JGOJIFF()
{
long a,b,r;
a = (long)stack_pop();
b = (long)stack_pop();
r = b >> a;
stack_push((stack_entry)r);
}
void GHI()
{
long a,b;
a = (long)stack_pop();
b = (long)stack_pop();
stack_push((stack_entry)a);
stack_push((stack_entry)b);
}
void OLGMGHOMN()
{
long a;
a = (long)stack_pop();
printf("%ld\n",a);
}
void JMFKNFOGN()
{
long a;
a = (long)stack_pop();
printf("0x%lx\n",a);
}
void init_register() {
symbol_cbind("+", *JJ);
symbol_cbind("*", *JI);
symbol_cbind("-", *JL);
symbol_cbind("/", *JN);
symbol_cbind("%", *IN);
symbol_cbind("<<", *JFKOFFF);
symbol_cbind(">>", *JGOJIFF);
symbol_cbind("x", *GHI);
symbol_cbind("pop", *OLGMGHOMN);
symbol_cbind("pop.x", *JMFKNFOGN);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment