aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-12-17 20:02:02 +0100
committertomsmeding <hallo@tomsmeding.nl>2015-12-17 20:02:02 +0100
commit9f54f2222a180d2563433d267f5505881c69c71b (patch)
treec6ebe150a6ce26744b9daa594ed79a1515421042
parentf35a3c6de1e010042056f2364a3575b193c97128 (diff)
some cripp fixes
-rw-r--r--cripp/Makefile13
-rwxr-xr-xcripp/crippbin0 -> 41064 bytes
-rw-r--r--cripp/cripp.cpp26
3 files changed, 27 insertions, 12 deletions
diff --git a/cripp/Makefile b/cripp/Makefile
index 925e6f7..91015ae 100644
--- a/cripp/Makefile
+++ b/cripp/Makefile
@@ -1,2 +1,13 @@
CXX = g++
-CXXFLAGS = -Wall -Wextra -O2 -std=c++11 -lgmp -lgmpxx \ No newline at end of file
+CXXFLAGS = -Wall -Wextra -O2 -std=c++11 -lgmp -lgmpxx -I/usr/local/include -L/usr/local/lib
+BIN = cripp
+
+.PHONY: all clean remake
+
+all: $(BIN)
+
+clean:
+ rm -f $(BIN)
+
+remake: clean all
+
diff --git a/cripp/cripp b/cripp/cripp
new file mode 100755
index 0000000..780f4dc
--- /dev/null
+++ b/cripp/cripp
Binary files differ
diff --git a/cripp/cripp.cpp b/cripp/cripp.cpp
index 0e193b0..b3e879f 100644
--- a/cripp/cripp.cpp
+++ b/cripp/cripp.cpp
@@ -204,8 +204,8 @@ void runcode(const char *code,const int *jumpmap,Llist<ripint> &stack,const int
stack.pop_back();
break;
case 'S':{
- const ripint b=stack.back(); stack.pop_back();
- const ripint a=stack.back(); stack.pop_back();
+ const ripint b=move(stack.back()); stack.pop_back();
+ const ripint a=move(stack.back()); stack.pop_back();
stack.push_back(b);
stack.push_back(a);
break;
@@ -220,8 +220,8 @@ void runcode(const char *code,const int *jumpmap,Llist<ripint> &stack,const int
stack.back()--;
break;
case 'r':{
- const int n=integral(stack.back()); stack.pop_back();
- const ripint value=stack.back(); stack.pop_back();
+ const int n=integral(move(stack.back())); stack.pop_back();
+ const ripint value=move(stack.back()); stack.pop_back();
if(n==stack.size()+1)stack.push_front(value);
else {
void *const before=stack.itemp(-n);
@@ -230,7 +230,7 @@ void runcode(const char *code,const int *jumpmap,Llist<ripint> &stack,const int
break;
}
case 'R':{
- const int n=integral(stack.back()); stack.pop_back();
+ const int n=integral(move(stack.back())); stack.pop_back();
void *const p=stack.itemp(-n);
stack.push_back(Llist<ripint>::valueof(p));
stack.erase(p);
@@ -240,8 +240,8 @@ void runcode(const char *code,const int *jumpmap,Llist<ripint> &stack,const int
stack.push_back(stack.size());
break;
case 'a': case 's': case 'm': case 'q': case 'G': case 'L': case 'E':{
- const ripint b=stack.back(); stack.pop_back();
- const ripint a=stack.back(); stack.pop_back();
+ const ripint b=move(stack.back()); stack.pop_back();
+ const ripint a=move(stack.back()); stack.pop_back();
switch(code[i]){
case 'a': stack.push_back(a+b); break;
case 's': stack.push_back(a-b); break;
@@ -254,11 +254,11 @@ void runcode(const char *code,const int *jumpmap,Llist<ripint> &stack,const int
break;
}
case 'n':
- stack.back()=!integral(stack.back());
+ stack.back()=!integral(move(stack.back()));
break;
case 'I': {
if(jumpmap[i]==0)riperror("No code block after 'I'");
- const int cond=integral(stack.back()); stack.pop_back();
+ const int cond=integral(move(stack.back())); stack.pop_back();
if(cond){
runcode(code,jumpmap,stack,jumpmap[i]+1);
}
@@ -269,7 +269,7 @@ void runcode(const char *code,const int *jumpmap,Llist<ripint> &stack,const int
if(jumpmap[i]==0)riperror("No code block after 'W'");
int cond;
while(true){
- cond=integral(stack.back()); stack.pop_back();
+ cond=integral(move(stack.back())); stack.pop_back();
//cerr<<"whiling on "<<string(code+i-2,5)<<"; cond="<<cond<<endl;
if(!cond)break;
runcode(code,jumpmap,stack,jumpmap[i]+1);
@@ -278,7 +278,7 @@ void runcode(const char *code,const int *jumpmap,Llist<ripint> &stack,const int
break;
}
case 'o':
- cout<<(char)integral(stack.back());
+ cout<<(char)integral(move(stack.back()));
stack.pop_back();
break;
case 'O':
@@ -311,6 +311,10 @@ int main(int argc,char **argv){
ifstream codef(argv[1]);
codef.seekg(0,ios::end);
const size_t len=codef.tellg();
+ if(len==(size_t)-1){
+ cout<<"Could not open file '"<<argv[1]<<'\''<<endl;
+ return 1;
+ }
codef.seekg(0);
char *code=new char[len+1];
codef.read(code,len);