1818# The options container
1919from . import options
2020from . import global_
21- from .options import ANYTYPE
21+
22+ from .options import ANYTYPE , Actions
2223
2324
2425# ------------------------------------------------------
2526# Common setup and configuration for all tools
2627# ------------------------------------------------------
28+ class ConfigSections :
29+ ZXBC = 'zxbc'
30+ ZXBASM = 'zxbasm'
31+ ZXBPP = 'zxbpp'
32+
33+
2734class OPTION :
2835 OUTPUT_FILENAME = 'output_filename'
2936 INPUT_FILENAME = 'input_filename'
3037 STDERR_FILENAME = 'stderr_filename'
3138 DEBUG = 'debug_level'
39+ PROJECT_FILENAME = 'project_filename'
3240
3341 # File IO
3442 STDIN = 'stdin'
@@ -70,6 +78,10 @@ class OPTION:
7078
7179
7280OPTIONS = options .Options ()
81+ OPTIONS_NOT_SAVED = {
82+ OPTION .STDERR , OPTION .STDIN , OPTION .STDOUT , 'sinclair' , OPTION .INPUT_FILENAME , OPTION .OUTPUT_FILENAME ,
83+ OPTION .PROJECT_FILENAME , 'heap_start_label' , 'heap_size_label'
84+ }
7385
7486
7587def load_config_from_file (filename : str , section : str , options_ : options .Options = None , stop_on_error = True ) -> bool :
@@ -107,7 +119,7 @@ def load_config_from_file(filename: str, section: str, options_: options.Options
107119 }
108120
109121 for opt in cfg .options (section ):
110- options_ [opt ].value = parsing .get (options_ [opt ].type , cfg .get )(option = opt )
122+ options_ [opt ].value = parsing .get (options_ [opt ].type , cfg .get )(section = section , option = opt )
111123
112124 return True
113125
@@ -131,8 +143,8 @@ def save_config_into_file(filename: str, section: str, options_: options.Options
131143 return False
132144
133145 cfg [section ] = {}
134- for opt_name , opt in options . Options . get_options ( options_ ):
135- if opt_name .startswith ('__' ) or opt .value is None or opt_name in ( 'stderr' , 'stdin' , 'stdout' ) :
146+ for opt_name , opt in options_ (). items ( ):
147+ if opt_name .startswith ('__' ) or opt .value is None or opt_name in OPTIONS_NOT_SAVED :
136148 continue
137149
138150 if opt .type == bool :
@@ -164,48 +176,53 @@ def init():
164176 param_byref --Default parameter passing. TRUE => By Reference
165177 """
166178
167- OPTIONS . reset ( )
179+ OPTIONS ( Actions . CLEAR )
168180
169- OPTIONS . add_option ( OPTION .OUTPUT_FILENAME , str )
170- OPTIONS . add_option ( OPTION .INPUT_FILENAME , str )
171- OPTIONS . add_option ( OPTION .STDERR_FILENAME , str )
172- OPTIONS . add_option ( OPTION .DEBUG , int , 0 )
181+ OPTIONS ( Actions . ADD , name = OPTION .OUTPUT_FILENAME , type = str )
182+ OPTIONS ( Actions . ADD , name = OPTION .INPUT_FILENAME , type = str )
183+ OPTIONS ( Actions . ADD , name = OPTION .STDERR_FILENAME , type = str )
184+ OPTIONS ( Actions . ADD , name = OPTION .DEBUG , type = int , default = 0 )
173185
174186 # Default console redirections
175- OPTIONS .add_option (OPTION .STDIN , ANYTYPE , sys .stdin )
176- OPTIONS .add_option (OPTION .STDOUT , ANYTYPE , sys .stdout )
177- OPTIONS .add_option (OPTION .STDERR , ANYTYPE , sys .stderr )
178-
179- OPTIONS .add_option (OPTION .O_LEVEL , int , global_ .DEFAULT_OPTIMIZATION_LEVEL )
180- OPTIONS .add_option (OPTION .CASE_INS , bool , False )
181- OPTIONS .add_option (OPTION .ARRAY_BASE , int , 0 )
182- OPTIONS .add_option (OPTION .DEFAULT_BYREF , bool , False )
183- OPTIONS .add_option (OPTION .MAX_SYN_ERRORS , int , global_ .DEFAULT_MAX_SYNTAX_ERRORS )
184- OPTIONS .add_option (OPTION .STR_BASE , int , 0 )
185- OPTIONS .add_option (OPTION .MEMORY_MAP , str , None )
186- OPTIONS .add_option (OPTION .FORCE_ASM_BRACKET , bool , False )
187-
188- OPTIONS .add_option (OPTION .USE_BASIC_LOADER , bool , False ) # Whether to use a loader
189- OPTIONS .add_option (OPTION .AUTORUN , bool , False ) # Whether to add autostart code (needs basic loader = true)
190- OPTIONS .add_option (OPTION .OUTPUT_FILE_TYPE , str , 'bin' ) # bin, tap, tzx etc...
191- OPTIONS .add_option (OPTION .INCLUDE_PATH , str , '' ) # Include path, like '/var/lib:/var/include'
192-
193- OPTIONS .add_option (OPTION .CHECK_MEMORY , bool , False )
194- OPTIONS .add_option (OPTION .STRICT_BOOL , bool , False )
195- OPTIONS .add_option (OPTION .CHECK_ARRAYS , bool , False )
196-
197- OPTIONS .add_option (OPTION .ENABLE_BREAK , bool , False )
198- OPTIONS .add_option (OPTION .EMIT_BACKEND , bool , False )
199- OPTIONS .add_option ('__DEFINES' , dict , {})
200- OPTIONS .add_option (OPTION .EXPLICIT , bool , False )
201- OPTIONS .add_option ('Sinclair' , bool , False )
202- OPTIONS .add_option (OPTION .STRICT , bool , False ) # True to force type checking
203- OPTIONS .add_option (OPTION .ASM_ZXNEXT , bool , False ) # True to enable ZX Next ASM opcodes
204- OPTIONS .add_option (OPTION .ARCH , str , None ) # Architecture
205- OPTIONS .add_option (OPTION .EXPECTED_WARNINGS , int , 0 ) # Expected Warnings that will be silenced
206- OPTIONS .add_option (OPTION .HIDE_WARNING_CODES , bool , False ) # Whether to show WXXX warning codes or not
207-
208- save_config_into_file ('project.ini' , 'zxbc' , stop_on_error = True )
187+ OPTIONS (Actions .ADD , name = OPTION .STDIN , type = ANYTYPE , default = sys .stdin )
188+ OPTIONS (Actions .ADD , name = OPTION .STDOUT , type = ANYTYPE , default = sys .stdout )
189+ OPTIONS (Actions .ADD , name = OPTION .STDERR , type = ANYTYPE , default = sys .stderr )
190+
191+ OPTIONS (Actions .ADD , name = OPTION .O_LEVEL , type = int , default = global_ .DEFAULT_OPTIMIZATION_LEVEL )
192+ OPTIONS (Actions .ADD , name = OPTION .CASE_INS , type = bool , default = False )
193+ OPTIONS (Actions .ADD , name = OPTION .ARRAY_BASE , type = int , default = 0 )
194+ OPTIONS (Actions .ADD , name = OPTION .DEFAULT_BYREF , type = bool , default = False )
195+ OPTIONS (Actions .ADD , name = OPTION .MAX_SYN_ERRORS , type = int , default = global_ .DEFAULT_MAX_SYNTAX_ERRORS )
196+ OPTIONS (Actions .ADD , name = OPTION .STR_BASE , type = int , default = 0 )
197+ OPTIONS (Actions .ADD , name = OPTION .MEMORY_MAP , type = str , default = None )
198+ OPTIONS (Actions .ADD , name = OPTION .FORCE_ASM_BRACKET , type = bool , default = False )
199+
200+ OPTIONS (Actions .ADD , name = OPTION .USE_BASIC_LOADER , type = bool , default = False ) # Whether to use a loader
201+
202+ # Whether to add autostart code (needs basic loader = true)
203+ OPTIONS (Actions .ADD , name = OPTION .AUTORUN , type = bool , default = False )
204+ OPTIONS (Actions .ADD , name = OPTION .OUTPUT_FILE_TYPE , type = str , default = 'bin' ) # bin, tap, tzx etc...
205+ OPTIONS (Actions .ADD , name = OPTION .INCLUDE_PATH , type = str , default = '' ) # Include path, like '/var/lib:/var/include'
206+
207+ OPTIONS (Actions .ADD , name = OPTION .CHECK_MEMORY , type = bool , default = False )
208+ OPTIONS (Actions .ADD , name = OPTION .STRICT_BOOL , type = bool , default = False )
209+ OPTIONS (Actions .ADD , name = OPTION .CHECK_ARRAYS , type = bool , default = False )
210+
211+ OPTIONS (Actions .ADD , name = OPTION .ENABLE_BREAK , type = bool , default = False )
212+ OPTIONS (Actions .ADD , name = OPTION .EMIT_BACKEND , type = bool , default = False )
213+ OPTIONS (Actions .ADD , name = '__DEFINES' , type = dict , default = {})
214+ OPTIONS (Actions .ADD , name = OPTION .EXPLICIT , type = bool , default = False )
215+ OPTIONS (Actions .ADD , name = 'sinclair' , type = bool , default = False )
216+ OPTIONS (Actions .ADD , name = OPTION .STRICT , type = bool , default = False ) # True to force type checking
217+ OPTIONS (Actions .ADD , name = OPTION .ASM_ZXNEXT , type = bool , default = False ) # True to enable ZX Next ASM opcodes
218+ OPTIONS (Actions .ADD , name = OPTION .ARCH , type = str , default = None ) # Architecture
219+ OPTIONS (Actions .ADD , name = OPTION .EXPECTED_WARNINGS , type = int , default = 0 ) # Expected Warnings that will be silenced
220+
221+ # Whether to show WXXX warning codes or not
222+ OPTIONS (Actions .ADD , name = OPTION .HIDE_WARNING_CODES , type = bool , default = False )
223+
224+ OPTIONS (Actions .ADD , name = OPTION .PROJECT_FILENAME , type = str , default = os .path .join (os .path .abspath (os .path .curdir ),
225+ 'project.ini' ))
209226
210227
211228init ()
0 commit comments