Skip to content

Commit b28d5ec

Browse files
authored
Merge pull request #2 from jgOhYeah/master
Adding support for more proprocessor directives (ifs, block comments, and other misc features)
2 parents c3e69d2 + e81e98a commit b28d5ec

11 files changed

Lines changed: 506 additions & 124 deletions

File tree

Examples/Ifs/IfTest.bas

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
; Test IFDEF, IFNDEF, ELSE, ELSEIFDEF, ELSEIFNDEF, ENDIF
2+
; PE6: 14M2 is 281 bytes
3+
; Preprocessor with the same compilers: 14M2 is also 281 bytes. Hopefully this means they match.
4+
#REM
5+
This is a block comment. Stuff like
6+
#ERROR "is ignored... hopefully"
7+
#ENDREM
8+
9+
#DEFINE TESTA 12
10+
#IFDEF TESTA ; Should be true
11+
sertxd("TESTA is defined")
12+
#ENDIF
13+
14+
#DEFINE TESTB
15+
#IFDEF TESTB ; Should be true
16+
sertxd("TESTB is defined")
17+
#ENDIF
18+
19+
#IFDEF TESTA ; Should be true
20+
#IFDEF TESTB ; Should be true
21+
sertxd("TESTA and TESTB are defined")
22+
#ENDIF
23+
#IFDEF TESTC ; Should not be true
24+
sertxd("TESTA and TESTC are defined")
25+
#ERROR "TESTC should not be defined"
26+
#ELSEIFDEF TESTD ' Should not be true
27+
sertxd("TESTA and TESTD are defined and TESTC is not")
28+
#ERROR "TESTD should not be defined"
29+
#ELSEIFDEF TESTB ; Should be true
30+
sertxd("TESTA and TESTB are defined and TESTC and TESTD not")
31+
#rem ; #elseifndef is not a standared preprocessor directive, but it was not hard to include seeing as #elseifdef is implemented.
32+
#ELSEIFNDEF TESTZ ; Should not be true
33+
sertxd("TESTA is defined and TESTB, TESTC and TESTD are not defined")
34+
#ERROR "Already should have evaluated something to True in this statement, so should ignore"
35+
#endrem
36+
#ELSEIFDEF TESTA ; Should not be true
37+
sertxd("TESTA is defined and TESTB, TESTC and are not defined")
38+
#ERROR "Already should have evaluated something to True in this statement, so should ignore"
39+
#ENDIF
40+
#ENDIF
41+
42+
; Test with values and comparisons
43+
#DEFINE VALUE 123
44+
#IF VALUE > 12 ; Should be true
45+
sertxd("VALUE > 12")
46+
#IF VALUE = 123 ; Should be true
47+
sertxd("VALUE == 123")
48+
#ELSE ; Should not be true
49+
sertxd("VALUE != 123")
50+
#ERROR "Should not have got here"
51+
#ENDIF
52+
sertxd("VALUE is still > 12")
53+
#ELSEIF VALUE < 200 ; Should not be true
54+
sertxd("12 > VALUE < 200")
55+
#ERROR "Should not have got here"
56+
#ELSE ; Should not de true
57+
sertxd("VALUE <= 12 or VALUE >= 200")
58+
#ERROR "Should not have got here"
59+
#ENDIF
60+
61+
#IF VALUE <> 2 ; Should be true
62+
sertxd("VALUE <> 2")
63+
#ELSEIFDEF VALUE ' Should be false
64+
sertxd("VALUE is defined and != 2")
65+
#ERROR "Should not have got here"
66+
#ENDIF
67+
68+
#rem ; Even though #undef is in the manual, it does not appear to be implemented in PE6. Uncomment to test with
69+
#UNDEF TESTA
70+
#IFDEF TESTA ; Should no longer be defined
71+
sertxd("TESTA is defined")
72+
#ERROR "TESTA should not be still defined"
73+
#ENDIF
74+
75+
#IFNDEF TESTA ; Should be true
76+
sertxd("TESTA is NOT defined")
77+
#ENDIF
78+
#endrem

Examples/Ifs/compiled.bas

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
'-----PREPROCESSED BY picaxepreprocess.py-----
2+
'----UPDATED AT 02:41PM, December 27, 2020----
3+
'----SAVING AS .\Examples\Ifs\compiled.bas ----
4+
5+
'---BEGIN .\Examples\Ifs\IfTest.bas ---
6+
; Test IFDEF, IFNDEF, ELSE, ELSEIFDEF, ELSEIFNDEF, ENDIF
7+
; PE6: 14M2 is 281 bytes
8+
; Preprocessor with the same compilers: 14M2 is also 281 bytes. Hopefully this means they match.
9+
; #REM [Commented out]
10+
; This is a block comment. Stuff like [Commented out]
11+
; #ERROR "is ignored... hopefully" [Commented out]
12+
; #ENDREM [Commented out]
13+
14+
; #DEFINE TESTA 12
15+
; #IFDEF TESTA ; Should be true
16+
sertxd("TESTA is defined")
17+
; #ENDIF
18+
19+
; #DEFINE TESTB
20+
; #IFDEF TESTB ; Should be true
21+
sertxd("TESTB is defined")
22+
; #ENDIF
23+
24+
; #IFDEF TESTA ; Should be true
25+
; #IFDEF TESTB ; Should be true
26+
sertxd("TESTA and TESTB are defined")
27+
; #ENDIF
28+
; ; #IFDEF TESTC ; Should not be true [#IF CODE REMOVED]
29+
; sertxd("TESTA and TESTC are defined") [#IF CODE REMOVED]
30+
; #ERROR "TESTC should not be defined" [#IF CODE REMOVED]
31+
; ; #ELSEIFDEF TESTD ' Should not be true [#IF CODE REMOVED]
32+
; sertxd("TESTA and TESTD are defined and TESTC is not") [#IF CODE REMOVED]
33+
; #ERROR "TESTD should not be defined" [#IF CODE REMOVED]
34+
; #ELSEIFDEF TESTB ; Should be true
35+
sertxd("TESTA and TESTB are defined and TESTC and TESTD not")
36+
; #rem ; #elseifndef is not a standared preprocessor directive, but it was not hard to include seeing as #elseifdef is implemented. [Commented out]
37+
; #ELSEIFNDEF TESTZ ; Should not be true [Commented out]
38+
; sertxd("TESTA is defined and TESTB, TESTC and TESTD are not defined") [Commented out]
39+
; #ERROR "Already should have evaluated something to True in this statement, so should ignore" [Commented out]
40+
; #endrem [Commented out]
41+
; ; #ELSEIFDEF TESTA ; Should not be true [#IF CODE REMOVED]
42+
; sertxd("TESTA is defined and TESTB, TESTC and are not defined") [#IF CODE REMOVED]
43+
; #ERROR "Already should have evaluated something to True in this statement, so should ignore" [#IF CODE REMOVED]
44+
; #ENDIF
45+
; #ENDIF
46+
47+
; Test with values and comparisons
48+
; #DEFINE VALUE 123
49+
; #IF 123 > 12 ; Should be true
50+
sertxd("VALUE > 12")
51+
; #IF 123 = 123 ; Should be true
52+
sertxd("VALUE == 123")
53+
; ; #ELSE ; Should not be true [#IF CODE REMOVED]
54+
; sertxd("VALUE != 123") [#IF CODE REMOVED]
55+
; #ERROR "Should not have got here" [#IF CODE REMOVED]
56+
; #ENDIF
57+
sertxd("VALUE is still > 12")
58+
; #ELSEIF 123 < 200 ; Should not be true [#IF CODE REMOVED]
59+
; sertxd("12 > VALUE < 200") [#IF CODE REMOVED]
60+
; #ERROR "Should not have got here" [#IF CODE REMOVED]
61+
; ; #ELSE ; Should not de true [#IF CODE REMOVED]
62+
; sertxd("VALUE <= 12 or VALUE >= 200") [#IF CODE REMOVED]
63+
; #ERROR "Should not have got here" [#IF CODE REMOVED]
64+
; #ENDIF
65+
66+
; #IF 123 <> 2 ; Should be true
67+
sertxd("VALUE <> 2")
68+
; ; #ELSEIFDEF VALUE ' Should be false [#IF CODE REMOVED]
69+
; sertxd("VALUE is defined and != 2") [#IF CODE REMOVED]
70+
; #ERROR "Should not have got here" [#IF CODE REMOVED]
71+
; #ENDIF
72+
73+
; #rem ; Even though #undef is in the manual, it does not appear to be implemented in PE6. Uncomment to test with [Commented out]
74+
; #UNDEF TESTA [Commented out]
75+
; #IFDEF TESTA ; Should no longer be defined [Commented out]
76+
; sertxd("TESTA is defined") [Commented out]
77+
; #ERROR "TESTA should not be still defined" [Commented out]
78+
; #ENDIF [Commented out]
79+
; [Commented out]
80+
; #IFNDEF TESTA ; Should be true [Commented out]
81+
; sertxd("TESTA is NOT defined") [Commented out]
82+
; #ENDIF [Commented out]
83+
; #endrem [Commented out]
84+
85+
'---END IfTest.bas---

compiled.bas renamed to Examples/IncludesDefinesMacros/compiled.bas

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'-----PREPROCESSED BY picaxepreprocess.py-----
2-
'----UPDATED AT 01:32PM, December 13, 2020----
2+
'----UPDATED AT 12:27AM, December 27, 2020----
33
'----SAVING AS compiled.bas ----
44

55
'---BEGIN main.bas ---
@@ -9,9 +9,9 @@
99
goto init
1010
'---BEGIN 2.bas ---
1111

12-
#define MAGIC_NUMBER "83838838" 'DEFINITION PARSED
12+
; #define MAGIC_NUMBER "83838838"
1313

14-
#DEFINE SetBackLedOn b0 =255 : toggle 2 'DEFINITION PARSED
14+
; #DEFINE SetBackLedOn b0 =255 : toggle 2
1515

1616
'---BEGIN 4.bas ---
1717
toggle 2
@@ -27,12 +27,12 @@ SendHeadingSpeed:
2727
'PARSED MACRO SerialMacro
2828
'PARSED MACRO Assign
2929
'--START OF MACRO: Assign
30-
Let w0 = 1 * 2 + 3
30+
Let var = 1 * 2 + 3
3131
'--END OF MACRO: Assign( w0, 1 * 2 + 3 )
3232

3333
testloop:
34-
sertxd("83838838") 'DEFINE: "83838838" SUBSTITUTED FOR MAGIC_NUMBER
35-
b0 =255 : toggle 2 'DEFINE: b0 =255 : toggle 2 SUBSTITUTED FOR SetBackLedOn
34+
sertxd("83838838")
35+
b0 =255 : toggle 2
3636
'--START OF MACRO: SerialMacro
3737

3838
sertxd("this is a macro :)", "37")
@@ -44,10 +44,11 @@ return
4444
'---END 2.bas---
4545
'the following line demonstrates absolute paths. uncomment and set to an absolute path that exists on your system to test.
4646
'#include "/Users/patrickleiser/Documents/Programming/Robotics Club/PicaxeInclude/4.bas
47-
#define testing 'DEFINITION PARSED
48-
#define message sertxd("New Define") 'DEFINITION PARSED
47+
; #define testing
48+
; #define message sertxd("New Define")
4949

50-
#picaxe 18M2 'CHIP VERSION PARSED
50+
'the following line demonstrates specifiying a picaxe variant in-line
51+
'#picaxe 18M2
5152

5253
init:
5354
toggle 1
@@ -66,10 +67,10 @@ main:
6667
Gosub SendHeadingSpeed
6768
'--END OF MACRO: SetHeadingSpeed(92,34)
6869

69-
#ifdef testing
70+
; #ifdef testing
7071
sertxd("Old Defines Still Work")
71-
#endif
72-
sertxd("New Define") 'DEFINE: sertxd("New Define") SUBSTITUTED FOR message
72+
; #endif
73+
sertxd("New Define")
7374

7475
goto main
7576

11.9 KB
Binary file not shown.

compiled.err

Whitespace-only changes.

0 commit comments

Comments
 (0)