Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #66 - predefined constants refactored to be closer to gcc/clang…
… ones New predefineds in this commit: __INCLUDE_LEVEL__, __BASE_FILE__, __FILE__, __LINE__, __COUNTER__
- Loading branch information
Showing
11 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
; the __FILE__ and __LINE__ values are raw without quotes, so they are currently | ||
; difficult to use with sjasmplus, the Lua script can manipulate them well | ||
; but sjasmplus itself would need maybe some string operators... or even more? | ||
OUTPUT "predefined_base_file.bin" | ||
|
||
DB 0, 1, 2, 3, 255, 254, 253, 252, 10, 10, 10 ; make sure git doesn't treat this as text file | ||
DB "Main file before INCLUDE:\n" | ||
LUA ALLPASS | ||
_pc("DB \"base: " .. sj.get_define("__BASE_FILE__") .. "\\n\"") | ||
_pc("DB \"file: " .. sj.get_define("__FILE__") .. "\\n\"") | ||
_pc("DB \"ENDLUA line: " .. sj.get_define("__LINE__") .. "\\n\"") | ||
ENDLUA | ||
|
||
INCLUDE "predefined_base_file.i.asm" | ||
|
||
DB "Main file after INCLUDE:\n" | ||
LUA ALLPASS | ||
_pc("DB \"base: " .. sj.get_define("__BASE_FILE__") .. "\\n\"") | ||
_pc("DB \"file: " .. sj.get_define("__FILE__") .. "\\n\"") | ||
_pc("DB \"ENDLUA line: " .. sj.get_define("__LINE__") .. "\\n\"") | ||
ENDLUA |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
IF 1 == __INCLUDE_LEVEL__ | ||
|
||
DB "Before second INCLUDE:\n" | ||
LUA ALLPASS | ||
_pc("DB \"base: " .. sj.get_define("__BASE_FILE__") .. "\\n\"") | ||
_pc("DB \"file: " .. sj.get_define("__FILE__") .. "\\n\"") | ||
_pc("DB \"ENDLUA line: " .. sj.get_define("__LINE__") .. "\\n\"") | ||
ENDLUA | ||
|
||
INCLUDE "predefined_base_file.i.asm" | ||
|
||
DB "After second INCLUDE:\n" | ||
LUA ALLPASS | ||
_pc("DB \"base: " .. sj.get_define("__BASE_FILE__") .. "\\n\"") | ||
_pc("DB \"file: " .. sj.get_define("__FILE__") .. "\\n\"") | ||
_pc("DB \"ENDLUA line: " .. sj.get_define("__LINE__") .. "\\n\"") | ||
ENDLUA | ||
|
||
ELSE | ||
|
||
DB "Inside second INCLUDE:\n" | ||
LUA ALLPASS | ||
_pc("DB \"base: " .. sj.get_define("__BASE_FILE__") .. "\\n\"") | ||
_pc("DB \"file: " .. sj.get_define("__FILE__") .. "\\n\"") | ||
_pc("DB \"ENDLUA line: " .. sj.get_define("__LINE__") .. "\\n\"") | ||
ENDLUA | ||
|
||
ENDIF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
DB __COUNTER__ | ||
|
||
TestLabel__COUNTER__: | ||
; ^^ does NOT work, because "_" at beginning of __COUNTER__ | ||
; prevents sub-word substitution = TODO for sjasmplus v2.x | ||
|
||
LUA ALLPASS ; as usually, lua for the rescue | ||
sj.insert_label("lua_label_" .. sj.get_define("__COUNTER__"), sj.current_address) | ||
sj.add_byte(sj.get_define("__COUNTER__")) | ||
sj.insert_label("lua_label_" .. sj.get_define("__COUNTER__"), sj.current_address) | ||
sj.add_byte(sj.get_define("__COUNTER__")) | ||
sj.insert_label("lua_label_" .. sj.get_define("__COUNTER__"), sj.current_address) | ||
sj.add_byte(sj.get_define("__COUNTER__")) | ||
ENDLUA | ||
|
||
DB __COUNTER__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# file opened: predefined_counter.asm | ||
1 0000 00 DB 0 | ||
2 0001 | ||
3 0001 TestLabel__COUNTER__: | ||
4 0001 ; ^^ does NOT work, because "_" at beginning of __COUNTER__ | ||
5 0001 ; prevents sub-word substitution = TODO for sjasmplus v2.x | ||
6 0001 | ||
7 0001 LUA ALLPASS ; as usually, lua for the rescue | ||
8 0001 ~ sj.insert_label("lua_label_" .. sj.get_define("__COUNTER__"), sj.current_address) | ||
9 0001 ~ sj.add_byte(sj.get_define("__COUNTER__")) | ||
10 0001 ~ sj.insert_label("lua_label_" .. sj.get_define("__COUNTER__"), sj.current_address) | ||
11 0001 ~ sj.add_byte(sj.get_define("__COUNTER__")) | ||
12 0001 ~ sj.insert_label("lua_label_" .. sj.get_define("__COUNTER__"), sj.current_address) | ||
13 0001 ~ sj.add_byte(sj.get_define("__COUNTER__")) | ||
14 0001 02 04 06 ENDLUA | ||
15 0004 | ||
16 0004 07 DB 7 | ||
17 0005 | ||
# file closed: predefined_counter.asm | ||
|
||
Value Label | ||
------ - ----------------------------------------------------------- | ||
0x0001 X TestLabel__COUNTER__ | ||
0x0001 X lua_label_1 | ||
0x0002 X lua_label_3 | ||
0x0003 X lua_label_5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
IFNDEF MAIN_FILE | ||
DEFINE MAIN_FILE | ||
OUTPUT "predefined_include_level.bin" | ||
myIncludeLevel = 0 | ||
ENDIF | ||
|
||
; before another INCLUDE | ||
ASSERT __INCLUDE_LEVEL__ == myIncludeLevel | ||
DB __INCLUDE_LEVEL__, myIncludeLevel | ||
|
||
IF myIncludeLevel < 6 | ||
myIncludeLevel = myIncludeLevel + 1 | ||
INCLUDE "predefined_include_level.asm" | ||
myIncludeLevel = myIncludeLevel - 1 | ||
ENDIF | ||
|
||
; after another INCLUDE | ||
ASSERT __INCLUDE_LEVEL__ == myIncludeLevel | ||
DB __INCLUDE_LEVEL__, myIncludeLevel |
Binary file not shown.