Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

BF Macros, Take 3

Sign in to follow this  


I got the second half of the BF macro preprocessor done, and I now have a collection of useful BF macros:

#define FALSE 0
#define TRUE 1
#define SET(position,value) >(position)[-]+(value)<(position)
#define ZERO(position) SET(position,0)
#define INC(position) >(position)+<(position)
#define DEC(position) >(position)-<(position)
#define IF(position) >(position)[<(position)
#define ENDIF(position) >(position)[-]]<(position)
#define WHILE(position) IF(position)
#define ENDWHILE(position) >(position)]<(position)
#define ADD(from,to) WHILE(from)DEC(from)INC(to)ENDWHILE(from)
#define ADD_N(position,value) >(position)+(value)<(position)
#define SUB_N(position,value) >(position)-(value)<(position)
#define SUB(from,to) WHILE(from)DEC(from)DEC(to)ENDWHILE(from)
#define COPY(original,copy,temp) ZERO(copy)ZERO(temp)WHILE(original)DEC(original)INC(copy)INC(temp)ENDWHILE(original)ADD(temp,original)
#define COMPARE(first,second,temp) ZERO(temp)ADD(first,temp)SUB(second,temp)IF(temp)INC(first)ENDIF(temp)
#define TESTNONZERO(position,temp) ZERO(temp)ADD(position,temp)IF(temp)INC(position)ENDIF(temp)
#define TESTZERO(position,temp) ZERO(temp)ADD(position,temp)INC(position)IF(temp)SET(position,FALSE)ENDIF(temp)

I added a redundancy check on the tail end of my macro utility.

After all of the <(x) have been expanded, it recursively removes any instance of "<>", "><", "+-", and "-+" that it finds within the resulting code. Based on how simple the preprocessor is, I either had to make it do math, or eliminate adjacent pairs of instructions that cancel out. Removing adjacent pairs was simpler.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!