[cpp]
#include "stdlib.h"
#include "stdio.h"
#define CELLSPACE 1024 // 1024 cells
#define MAXLOOPDEPTH 32 // You can open 32 embedded loops, anything after
// this is undefined behavior!
int main(int argc, char **argv)
{
if( !(argc > 1) )
return 1;
unsigned char *progmem = argv[1];
unsigned char *cellmem = malloc(sizeof(char)*CELLSPACE);
if(cellmem == NULL)
return 1;
unsigned char **loopdepth = malloc(sizeof(char*)*MAXLOOPDEPTH);
if(loopdepth == NULL)
return 1;
unsigned char *origcellmem = cellmem;
unsigned char **origloopdepth = loopdepth;
for(;;)
{
switch(*progmem)
{
case '+':
++*cellmem;
break;
case '-':
--*cellmem;
break;
case '>':
cellmem++;
break;
case '<':
cellmem--;
break;
case '[':
*loopdepth = progmem-1;
loopdepth++;
break;
case ']':
loopdepth--;
if(*cellmem)
{
progmem = *loopdepth;
}
break;
case '.':
putc(*cellmem, stdout);
break;
case ',':
*cellmem = getc(stdin);
break;
case '\0':
free(origcellmem);
free(origloopdepth);
return 0;
}
progmem++;
}
}
[/cpp]
Just wrote a BF interpreter, should be fast, wrote it for a StackOverflow answer, figured I'd share it here.
What is a good way to store the salt on a encrypted file?
[img]http://i.imgur.com/SQFz2.png[/img]
:woop: My webserver used to not load all the content due to a bug(only allowing one connection at a time).
It works now, though!
[QUOTE=Jawalt;31432351][cpp]/*C*/[/cpp]
Just wrote a BF interpreter, should be fast, wrote it for a StackOverflow answer, figured I'd share it here.[/QUOTE]
You're leaking memory. That return 0; makes the free(*) stuff never being reached.
[QUOTE=ZeekyHBomb;31432599]You're leaking memory. That return 0; makes the free(*) stuff never being reached.[/QUOTE]
Oh, hmm, you're right thanks. Not a big deal though, on modern OSes as process closure should probably free that mameory and the return 0 ends execution.
(none the less, I'm fixing it.)
Polycode's super function, which calls the parent class's version of the function you are currently defining, causes a stack overflow if it is also used in the parent's version. :geno:
[QUOTE=ZeekyHBomb;31432599]You're leaking memory. That return 0; makes the free(*) stuff never being reached.[/QUOTE]
[QUOTE]
[cpp]
case '\0':
free(origcellmem);
free(origprogmem);
free(origloopdepth);
return 0;
[/cpp]
[/QUOTE]
My brain has been fucked. I'm guessing he did
[cpp]
case '\0':
return 0;
free(origcellmem);
free(origprogmem);
free(origloopdepth);
[/cpp]
? [img]http://www.facepunch.com/fp/ratings/tick.png[/img] or [img]http://www.facepunch.com/fp/ratings/cross.png[/img]
[QUOTE=Night-Eagle;31432911]My brain has been fucked. I'm guessing he did
[cpp]
case '\0':
return 0;
free(origcellmem);
free(origprogmem);
free(origloopdepth);
[/cpp]
? [img]http://www.facepunch.com/fp/ratings/tick.png[/img] or [img]http://www.facepunch.com/fp/ratings/cross.png[/img][/QUOTE]
Nope I unthinkingly put it after the for(;;){ }
[QUOTE=Jawalt;31432955]Nope I unthinkingly put it after the for(;;){ }[/QUOTE]
Smart pointers are great :D. Also you don't do any bounds checking. Which could potentially lead to a brainfuck script being executed and running malicious code. (Yes I know you just wrote it as an example :P)
[QUOTE=high;31433056]Smart pointers are great :D. Also you don't do any bounds checking. Which could potentially lead to a brainfuck script being executed and running malicious code. (Yes I know you just wrote it as an example :P)[/QUOTE]
That's kind of a nil point. That's like giving a user any interpreter, and saying they could run malicious code. You could do malicious things with any interpreter and elevated priveledges.
[editline]30th July 2011[/editline]
Not to mention how much slower error/bounds checking would make it.
[QUOTE=Jawalt;31433109]That's kind of a nil point. That's like giving a user any interpreter, and saying they could run malicious code. You could do malicious things with any interpreter and elevated priveledges.
[editline]30th July 2011[/editline]
Not to mention how much slower error/bounds checking would make it.[/QUOTE]
Bounds checking is not slow at all.
[QUOTE=Fox-Face;31432372]What is a good way to store the salt on a encrypted file?[/QUOTE]
In plain text
[QUOTE=high;31433472]Bounds checking is not slow at all.[/QUOTE]
It's not slow, but when you're executing like thousands of brainfuck commands fast, it adds up. My goal here was to write a fast interpreter that assumed the input was perfect.
Ok I'm working on a web crawler/ file ripper .
I'm up to the point of grabbing all file names, parsing them , making a GET and getting the file, but I'm still either not getting all of the file or getting garbage.
This is all using Winsock and STL no curl.
[URL]http://filebeam.com/acd8e4951e89bb3523d4f49514c23aa8[/URL]
I haven't secured it much so NULL pointers will run ramped if you do anything crazy .
I do not take responsobility for any damage.
Only for educational use!
This is like an alpha version so I'm not posting source code yet ( isn't documented anyway )
I think I'll implement a couple extra features, like a -d command line flag for bounds checking, and infinite loop detection (only possible with a smaller number of cells, the more cells, the less feasible checking for infinite loops is).
And like an -o flag for optimization, it wouldn't just run the input it'd first change it to an intermediate format with run length encoding and a couple other goodies like stripped comments, which at the moment slow the interpreter down slightly. I think interpreting "5+" instead of "+++++" and then just adding five instead of adding one five times is going to be MUCH faster.
[editline]30th July 2011[/editline]
Automerge! :(
[QUOTE=Jawalt;31433515]It's not slow, but when you're executing like thousands of brainfuck commands fast, it adds up. My goal here was to write a fast interpreter that assumed the input was perfect.[/QUOTE]
You would need millions before it becomes even remotely noticeable. (even then it would still only be a few milliseconds difference)
[QUOTE=high;31434104]You would need millions before it becomes even remotely noticeable. (even then it would still only be a few milliseconds difference)[/QUOTE]
You do know what brainfuck looks like right?
[code]
+++[>+++++<-]>>+<[>>++++>++>+++++>+++++>+>>+<++[++<]>---]
>++++.>>>.+++++.>------.<--.+++++++++.>+.+.<<<<---.[>]<<.<<<.-------.>++++.
<+++++.+.>-----.>+.<++++.>>++.>-----.
<<<-----.+++++.-------.<--.<<<.>>>.<<+.>------.-..--.+++.-----<++.<--[>+<-]
>>>>>--.--.<++++.>>-.<<<.>>>--.>.
<<<<-----.>----.++++++++.----<+.+++++++++>>--.+.++<<<<.[>]<.>>
,[>>+++[<+++++++>-]<[<[-[-<]]>>[>]<-]<[<+++++>-[<+++>-[<-->-[<+++>-
[<++++[>[->>]<[>>]<<-]>[<+++>-[<--->-[<++++>-[<+++[>[-[-[-[->>]]]]<[>>]<<-]
>[<+>-[<->-[<++>-[<[-]>-]]]]]]]]]]]]]
<[
-[-[>+<-]>]
<[<<<<.>+++.+.+++.-------.>---.++.<.>-.++<<<<.[>]>>>>>>>>>]
<[[<]>++.--[>]>>>>>>>>]
<[<<++..-->>>>>>]
<[<<..>>>>>]
<[<<..-.+>>>>]
<[<<++..---.+>>>]
<[<<<.>>.>>>>>]
<[<<<<-----.+++++>.----.+++.+>---.<<<-.[>]>]
<[<<<<.-----.>++++.<++.+++>----.>---.<<<.-[>]]
<[<<<<<----.>>.<<.+++++.>>>+.++>.>>]
<.>
]>
,]
<<<<<.<+.>++++.<----.>>---.<<<-.>>>+.>.>.[<]>++.[>]<.
[/code]
Source: [url]http://www.hevanet.com/cristofd/brainfuck/[/url]
In this particular situation:
1. You probably don't even need to free anything because it will be freed at exit anyway.
2. You don't actually have to use malloc/free at all. You can just declare them as "static unsigned char cellmem[CELLSPACE];".
[QUOTE=ROBO_DONUT;31434431]In this particular situation:
1. You probably don't even need to free anything because it will be freed at exit anyway.
2. You don't actually have to use malloc/free at all. You can just declare them as "static unsigned char cellmem[CELLSPACE];".
Also you can just do
"a = (a + 1) % MEMSIZE;" instead of "a++;" if you want safety. I think this is what most BF interpreters do. It's only like one more instruction and it doesn't add any branching.[/QUOTE]
The static compile time cell/loopdepth size is a placeholder, that's why it's malloc'd, it's going to get the cell size and max depth from the command line later, just haven't written it.
Made my .mus converter 1000.4% more user friendly.
Also it can play the .mus on the fly and convert on the fly, and play the oggs it results in.
[media]http://www.youtube.com/watch?v=aymlzP_eG-c[/media]
Normal mapping :D
[b]Big[/b] thanks to Chris220 for help with the shader and Dlaor for the textures!
Next do parallax mapping. I always wonder why so many games don't have parallax mapping.
[QUOTE=esalaka;31436497]Next do parallax mapping. I always wonder why so many games don't have parallax mapping.[/QUOTE]
Crysis does.
[QUOTE=DevBug;31436645]Crysis does.[/QUOTE]
I fail to see why this should be pointed out. It doesn't make up for the games that don't.
So I made a little flowchart app in C#, but I was wondering how I should allow the user to interact with it. It would be really easy to make a sort of text-based IO system, where the user types something like,
[code]
Create: Add, 150, 150, "Add!"
Create: ConstantValue, 250, 250, 25.2, "ConstVal"
Connect: "ConstVal", 0, "Add!", 0
Connect: "ConstVal", 0, "Add!", 1
Get: "Add!",0
The value of output #0 on Operator "Add!" is 50.4
[/code]
Or I could do it the (really) hard way, make some sort of mouse input thing, where the user can drag outputs to inputs and hover the mouse over an output to see the result. That would be much harder.
[img]http://dl.dropbox.com/u/5270951/Pics/FlowchartDerpherpderpflerpnerp.png[/img]
In the end I think mouse input is going to be better for you, and the user.
Go with mouse input.
You just inspired me to take a video of my gui.
The mouse is somehow hidden, but you get the idea.
[media]http://www.youtube.com/watch?v=vCCNRaqPeqQ[/media]
I port forwarded port 80.
<internet breaks>
[editline]30th July 2011[/editline]
And chrome won't load pages served by the webserver.
:downs:
Sorry, you need to Log In to post a reply to this thread.