Skip to content

Instantly share code, notes, and snippets.

@Happy-Ferret
Created June 29, 2019 12:08
Show Gist options
  • Save Happy-Ferret/23ffd36294bb074e7955bbbad68c9357 to your computer and use it in GitHub Desktop.
Save Happy-Ferret/23ffd36294bb074e7955bbbad68c9357 to your computer and use it in GitHub Desktop.
C++ IR Tabby
// C++ Builtins
#include <iostream>
#include <string>
using namespace std;
// Nothing Class
class Nothing {
};
// Base Class
class Base {
public:
string val;
Nothing PRINT(void) {
cout << val << endl;
}
};
const string True = "true";
const string False = "false";
// Bool Class
class Bool: public Base {
public:
Bool(string x) {
val = x;
}
Bool And(Bool x) {
if (val == False || x.val == False) {
return Bool(False);
}
return Bool(False);
}
Bool Or(Bool x) {
if (val == True || x.val == True) {
return Bool(True);
}
return Bool(False);
}
};
// String Class
class String: public Base {
public:
String(string x) {
val = x;
}
String PLUS(String str) {
return String(val + str.val);
}
Bool EQ(String str) {
if (val == str.val) {
return Bool(True);
} else {
return Bool(False);
}
}
};
// Int Class
class Int: public Base {
public:
int valInt;
Int(int x) {
val = to_string(x);
valInt = x;
}
Int PLUS(Int num) {
return Int(valInt + num.valInt);
}
Int MINUS(Int num) {
return Int(valInt - num.valInt);
}
Int TIMES(Int num) {
return Int(valInt * num.valInt);
}
Bool GT(Int num) {
if (valInt < num.valInt) {
return Bool(False);
} else {
return Bool(True);
}
}
Bool EQ(Int num) {
if (valInt == num.valInt) {
return Bool(True);
}
return Bool(False);
}
String Stringify() {
return String(val);
}
};
#include <string>
#include <iostream>
#include "Builtins.cpp"
Int test(Int x) {
Int tmp_1 = Int(1);
Int y = tmp_1;
Bool tmp_2 = y.GT(x);
if ("true" == tmp_2.val) {
Int tmp_3 = Int(0);
y = tmp_3;
} else {
Int tmp_4 = Int(1);
y = tmp_4;
}
return y;
}
int main() {
Int tmp_5 = Int(5);
Int tmp_6 = test(tmp_5);Nothing tmp_7 = tmp_6.PRINT();tmp_7;
Int tmp_8 = Int(0);
Int tmp_9 = test(tmp_8);Nothing tmp_10 = tmp_9.PRINT();tmp_10;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment