Permalink
Browse files

Removed PP Prefix

  • Loading branch information...
Daniel Holden
Daniel Holden committed Nov 10, 2012
1 parent 887038e commit b050a62e489b07d94afcc930362709fb4ae69de0
Showing with 1,514 additions and 1,507 deletions.
  1. +45 −0 BOOL.h
  2. +148 −0 BRAINFUCK.h
  3. +135 −0 CHAR.h
  4. +17 −0 COMPLETE.h
  5. +12 −0 COND.h
  6. +18 −0 CORE.h
  7. +264 −0 DEC.h
  8. +263 −0 INC.h
  9. +31 −0 INT.h
  10. +51 −0 LIST.h
  11. +0 −3 MAIN.h
  12. +3 −0 MAIN_BF.h
  13. +2 −2 MAIN_TM.h
  14. +0 −12 PP.h
  15. +0 −45 PP_BOOL.h
  16. +0 −150 PP_BRAINFUCK.h
  17. +0 −135 PP_CHAR.h
  18. +0 −12 PP_COND.h
  19. +0 −16 PP_CORE.h
  20. +0 −264 PP_DEC.h
  21. +0 −263 PP_INC.h
  22. +0 −31 PP_INT.h
  23. +0 −51 PP_LIST.h
  24. +0 −227 PP_RECR.h
  25. +0 −220 PP_TEST.h
  26. +0 −74 PP_TURING.h
  27. +2 −2 README.md
  28. +227 −0 RECR.h
  29. +224 −0 TEST.h
  30. +72 −0 TURING.h
View
45 BOOL.h
@@ -0,0 +1,45 @@
+#ifndef BOOL_H
+#define BOOL_H
+
+#define NOT_0 1
+#define NOT_1 0
+
+#define AND_0_0 0
+#define AND_0_1 0
+#define AND_1_0 0
+#define AND_1_1 1
+
+#define OR_0_0 0
+#define OR_0_1 1
+#define OR_1_0 1
+#define OR_1_1 1
+
+#define XOR_0_0 0
+#define XOR_0_1 1
+#define XOR_1_0 1
+#define XOR_1_1 0
+
+/* Truth Constants */
+#define TRUE 1
+#define FALSE 0
+
+/* Boolean Operators */
+#define NOT(X) JOIN(NOT_, X)
+#define AND(X, Y) JOIN2(AND_, X, Y)
+#define OR(X, Y) JOIN2(OR_, X, Y)
+#define XOR(X, Y) JOIN2(XOR_, X, Y)
+
+/* Cast to Bool */
+#define CHECK_N(X, N, ...) N
+#define CHECK(...) CHECK_N(__VA_ARGS__, 0,)
+
+#define CHECK_ZERO(X) CHECK(JOIN(CHECK_ZERO_, X))
+#define CHECK_ZERO_0 ~, 1,
+
+#define CHECK_EMPTY(X) CHECK(JOIN(CHECK_EMPTY_, X))
+#define CHECK_EMPTY_ ~, 1,
+
+
+#define BOOL(X) NOT(CHECK_ZERO(X))
+
+#endif
View
@@ -0,0 +1,148 @@
+#ifndef BRAINFUCK_H
+#define BRAINFUCK_H
+
+/*!
+ * BRAINFUCK
+ * ============
+ *
+ * About
+ * -----
+ *
+ * Brainfuck in c preprocessor
+ *
+ *
+ * Input
+ * -----
+ *
+ * To ensure valid preprocessor symbols
+ * instructions are mapped to the following
+ * characters, with input disabled.
+ *
+ * + `>` => `R`
+ * + `<` => `L`
+ * + `+` => `U`
+ * + `-` => `D`
+ * + `.` => `O`
+ * + `[` => `F`
+ * + `]` => `B`
+ *
+ *
+ * Structure
+ * ---------
+ *
+ * IP - Brainfuck instr index
+ * DP - Brainfuck data index
+ * IA - Brainfuck instr array
+ * DA - Brainfuck data array
+ *
+ * X - (IP, DP, IA, DA)
+ *
+ */
+
+/* Check if blank symbol */
+#define IS_BLANK(X) JOIN(IS_BLANK_, X)
+#define IS_BLANK_ 1
+#define IS_BLANK_R 0
+#define IS_BLANK_L 0
+#define IS_BLANK_U 0
+#define IS_BLANK_D 0
+#define IS_BLANK_O 0
+#define IS_BLANK_F 0
+#define IS_BLANK_B 0
+
+/* Check if output symbol */
+#define IS_OUTPUT(X) JOIN(IS_OUTPUT_, X)
+#define IS_OUTPUT_ 0
+#define IS_OUTPUT_R 0
+#define IS_OUTPUT_L 0
+#define IS_OUTPUT_U 0
+#define IS_OUTPUT_D 0
+#define IS_OUTPUT_O 1
+#define IS_OUTPUT_F 0
+#define IS_OUTPUT_B 0
+
+/* Check if forward symbol */
+#define IS_FORWARD(X) JOIN(IS_FORWARD_, X)
+#define IS_FORWARD_ 0
+#define IS_FORWARD_R 0
+#define IS_FORWARD_L 0
+#define IS_FORWARD_U 0
+#define IS_FORWARD_D 0
+#define IS_FORWARD_O 0
+#define IS_FORWARD_F 1
+#define IS_FORWARD_B 0
+
+/* Check if backward symbol */
+#define IS_BACKWARD(X) JOIN(IS_BACKWARD_, X)
+#define IS_BACKWARD_ 0
+#define IS_BACKWARD_R 0
+#define IS_BACKWARD_L 0
+#define IS_BACKWARD_U 0
+#define IS_BACKWARD_D 0
+#define IS_BACKWARD_O 0
+#define IS_BACKWARD_F 0
+#define IS_BACKWARD_B 1
+
+/* Get individual parts */
+#define BF_IP(X) FST(X)
+#define BF_DP(X) SND(X)
+#define BF_IA(X) TRD(X)
+#define BF_DA(X) FTH(X)
+#define BF_INSTR($, X) NTH($, BF_IA(X), BF_IP(X))
+#define BF_DATA($, X) NTH($, BF_DA(X), BF_DP(X))
+
+/* Inc/Dec Data Item */
+#define BF_DATA_FST($, X) TAKE($, BF_DA(X), BF_DP(X))
+#define BF_DATA_SND($, X) DROP($, BF_DA(X), INC(BF_DP(X)))
+#define BF_DATA_INCED($, X) ( INC(NTH($, BF_DA(X), BF_DP(X))) )
+#define BF_DATA_DECED($, X) ( DEC(NTH($, BF_DA(X), BF_DP(X))) )
+
+#define BF_DATA_INC($, X) CONCAT( BF_DATA_FST($, X) , CONCAT( BF_DATA_INCED($, X) , BF_DATA_SND($, X) ) )
+#define BF_DATA_DEC($, X) CONCAT( BF_DATA_FST($, X) , CONCAT( BF_DATA_DECED($, X) , BF_DATA_SND($, X) ) )
+
+/* Jump Forward/Back */
+
+// TODO: Make count braces
+#define BF_JUMP_FWD_E_TRD(S, I) IF_ELSE(IS_FOWARD(S), INC(I), IF_ELSE(IS_BACKWARD(S), DEC(I), I) )
+
+#define BF_JUMP_FWD_C($, X) NOT(IS_BACKWARD(HEAD(FST(X))))
+#define BF_JUMP_FWD_M($, X)
+#define BF_JUMP_FWD_U($, X) (TAIL(FST(X)), INC(SND(X)))
+#define BF_JUMP_FWD_E($, X) INC(SND(X))
+#define BF_JUMP_FWD($, X) JOIN(RECR_D, $)(INC($), BF_JUMP_FWD_C, BF_JUMP_FWD_M, BF_JUMP_FWD_U, BF_JUMP_FWD_E, (DROP($, BF_IA(X), BF_IP(X)), BF_IP(X) ) )
+
+// TODO: Make count braces
+#define BF_JUMP_BCK_C($, X) NOT( IS_FORWARD(NTH($, FST(X), SND(X))) )
+#define BF_JUMP_BCK_M($, X)
+#define BF_JUMP_BCK_U($, X) ( FST(X), DEC(SND(X)) )
+#define BF_JUMP_BCK_E($, X) INC(SND(X))
+#define BF_JUMP_BCK($, X) JOIN(RECR_D, $)(INC($), BF_JUMP_BCK_C, BF_JUMP_BCK_M, BF_JUMP_BCK_U, BF_JUMP_BCK_E, (BF_IA(X), BF_IP(X)) )
+
+#define BF_JUMP_F($, X) IF_ELSE(BOOL(BF_DATA($, X)), INC(BF_IP(X)), BF_JUMP_FWD($, X) )
+#define BF_JUMP_B($, X) IF_ELSE(BOOL(BF_DATA($, X)), BF_JUMP_BCK($, X) , INC(BF_IP(X)) )
+
+/* Brainfuck Symbol Update */
+#define BF_UPDATE_SYM($, S, X) JOIN(BF_UPDATE_SYM_, S)($, X)
+#define BF_UPDATE_SYM_R($, X) (INC(BF_IP(X)), INC(BF_DP(X)), BF_IA(X), BF_DA(X))
+#define BF_UPDATE_SYM_L($, X) (INC(BF_IP(X)), DEC(BF_DP(X)), BF_IA(X), BF_DA(X))
+#define BF_UPDATE_SYM_U($, X) (INC(BF_IP(X)), BF_DP(X), BF_IA(X), BF_DATA_INC($, X))
+#define BF_UPDATE_SYM_D($, X) (INC(BF_IP(X)), BF_DP(X), BF_IA(X), BF_DATA_DEC($, X))
+#define BF_UPDATE_SYM_O($, X) (INC(BF_IP(X)), BF_DP(X), BF_IA(X), BF_DA(X))
+#define BF_UPDATE_SYM_F($, X) (BF_JUMP_F($, X), BF_DP(X), BF_IA(X), BF_DA(X))
+#define BF_UPDATE_SYM_B($, X) (BF_JUMP_B($, X), BF_DP(X), BF_IA(X), BF_DA(X))
+#define BF_UPDATE_SYM_($, X) X
+
+
+#define BF_COND($, X) NOT(IS_BLANK(BF_INSTR($, X)))
+#define BF_MACRO($, X) IF(IS_OUTPUT(BF_INSTR($, X)), CHAR(BF_DATA($, X)))
+#define BF_UPDATE($, X) BF_UPDATE_SYM($, BF_INSTR($, X), X)
+#define BF_FINALLY($, X)
+#define BF_RECR($, X) JOIN(RECR_D, $)(INC($), BF_COND, BF_MACRO, BF_UPDATE, BF_FINALLY, X)
+
+#define BF_DATA_EMPTY() (0,0,0,0,0)
+
+/* Perform Brainfuck with input I */
+#define BRAINFUCK(I) BF_RECR($0, (0, 0, I, BF_DATA_EMPTY()))
+
+
+#endif
View
135 CHAR.h
@@ -0,0 +1,135 @@
+#ifndef CHAR_H
+#define CHAR_H
+
+#define CHAR(X) JOIN(CHAR_, X)
+#define CHAR_0 [NUL]
+#define CHAR_1 [SOH]
+#define CHAR_2 [STX]
+#define CHAR_3 [ETX]
+#define CHAR_4 [EOT]
+#define CHAR_5 [ENQ]
+#define CHAR_6 [ACK]
+#define CHAR_7 [BEL]
+#define CHAR_8 [BS]
+#define CHAR_9
+#define CHAR_10 \
+
+#define CHAR_11 [VT]
+#define CHAR_12 [FF]
+#define CHAR_13 [CR]
+#define CHAR_14 [SO]
+#define CHAR_15 [SI]
+#define CHAR_16 [DLE]
+#define CHAR_17 [DC1]
+#define CHAR_18 [DC2]
+#define CHAR_19 [DC3]
+#define CHAR_20 [DC4]
+#define CHAR_21 [NAK]
+#define CHAR_22 [SYN]
+#define CHAR_23 [ETB]
+#define CHAR_24 [CAN]
+#define CHAR_25 [EM]
+#define CHAR_26 [SUB]
+#define CHAR_27 [ESC]
+#define CHAR_28 [FS]
+#define CHAR_29 [GS]
+#define CHAR_30 [RS]
+#define CHAR_31 [US]
+#define CHAR_32
+#define CHAR_33 !
+#define CHAR_34 [DQ]
+#define CHAR_35 #
+#define CHAR_36 $
+#define CHAR_37 %
+#define CHAR_38 &
+#define CHAR_39 [SQ]
+#define CHAR_40 (
+#define CHAR_41 )
+#define CHAR_42 *
+#define CHAR_43 +
+#define CHAR_44 ,
+#define CHAR_45 -
+#define CHAR_46 .
+#define CHAR_47 /
+#define CHAR_48 0
+#define CHAR_49 1
+#define CHAR_50 2
+#define CHAR_51 3
+#define CHAR_52 4
+#define CHAR_53 5
+#define CHAR_54 6
+#define CHAR_55 7
+#define CHAR_56 8
+#define CHAR_57 9
+#define CHAR_58 :
+#define CHAR_59 ;
+#define CHAR_60 <
+#define CHAR_61 =
+#define CHAR_62 >
+#define CHAR_63 ?
+#define CHAR_64 @
+#define CHAR_65 A
+#define CHAR_66 B
+#define CHAR_67 C
+#define CHAR_68 D
+#define CHAR_69 E
+#define CHAR_70 F
+#define CHAR_71 G
+#define CHAR_72 H
+#define CHAR_73 I
+#define CHAR_74 J
+#define CHAR_75 K
+#define CHAR_76 L
+#define CHAR_77 M
+#define CHAR_78 N
+#define CHAR_79 O
+#define CHAR_80 P
+#define CHAR_81 Q
+#define CHAR_82 R
+#define CHAR_83 S
+#define CHAR_84 T
+#define CHAR_85 U
+#define CHAR_86 V
+#define CHAR_87 W
+#define CHAR_88 X
+#define CHAR_89 Y
+#define CHAR_90 Z
+#define CHAR_91 [
+#define CHAR_92 \
+#define CHAR_93 ]
+#define CHAR_94 ^
+#define CHAR_95 _
+#define CHAR_96 `
+#define CHAR_97 a
+#define CHAR_98 b
+#define CHAR_99 c
+#define CHAR_100 d
+#define CHAR_101 e
+#define CHAR_102 f
+#define CHAR_103 g
+#define CHAR_104 h
+#define CHAR_105 i
+#define CHAR_106 j
+#define CHAR_107 k
+#define CHAR_108 l
+#define CHAR_109 m
+#define CHAR_110 n
+#define CHAR_111 o
+#define CHAR_112 p
+#define CHAR_113 q
+#define CHAR_114 r
+#define CHAR_115 s
+#define CHAR_116 t
+#define CHAR_117 u
+#define CHAR_118 v
+#define CHAR_119 w
+#define CHAR_120 x
+#define CHAR_121 y
+#define CHAR_122 z
+#define CHAR_123 {
+#define CHAR_124 |
+#define CHAR_125 }
+#define CHAR_126 ~
+#define CHAR_127 DEL
+
+#endif
View
@@ -0,0 +1,17 @@
+#ifndef COMPLETE_H
+#define COMPLETE_H
+
+#include "CORE.h"
+#include "COND.h"
+#include "RECR.h"
+
+#include "INC.h"
+#include "DEC.h"
+#include "INT.h"
+#include "CHAR.h"
+#include "LIST.h"
+
+#include "BRAINFUCK.h"
+#include "TURING.h"
+
+#endif
View
12 COND.h
@@ -0,0 +1,12 @@
+#ifndef COND_H
+#define COND_H
+
+#include "CORE.h"
+
+#define IF_ELSE(C, T, E) JOIN(IF_ELSE_, C)(T, E)
+#define IF_ELSE_0(T, E) E
+#define IF_ELSE_1(T, E) T
+
+#define IF(C, T) IF_ELSE(C, T, )
+
+#endif
View
18 CORE.h
@@ -0,0 +1,18 @@
+#ifndef CORE_H
+#define CORE_H
+
+#define EMPTY()
+#define DEFER(M) M EMPTY()
+#define OBSTRUCT(M) M DEFER(EMPTY)()
+
+#define APPLY(M, ...) M(__VA_ARGS__)
+
+#define JOIN(X, Y) X##Y
+#define JOIN2(X, Y, Z) X##Y##_##Z
+
+#define EVAL(...) __VA_ARGS__
+#define EAT(...)
+
+#define ERROR() (ERROR)##(ERROR)
+
+#endif
Oops, something went wrong.

0 comments on commit b050a62

Please sign in to comment.