PmDriver.icl 88.3 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1 2
implementation module PmDriver

3
import StdArray,StdBool,StdList,StdMisc,StdEnum,StdStrictLists,StdTuple
4
from StdOverloadedList import Foldr,++|,Hd,Any
Diederik van Arkel's avatar
Diederik van Arkel committed
5 6 7
import UtilNewlinesFile, UtilIO

import IdeState
8

9
from typeatt import update_type_window
10
from errwin  import updateErrorWindow
Diederik van Arkel's avatar
Diederik van Arkel committed
11
from messwin import showInfo, :: InfoMessage(..)
Diederik van Arkel's avatar
Diederik van Arkel committed
12
from projwin import pm_update_project_window
13

14 15
import PmCallBack

16
import PmCleanSystem,PmPath,PmProject
17
from PmDialogues import doPathsDialog
18
import PmAbcMagic,PmFileInfo,PmDirCache
19

20
import Platform
21
from StdLibMisc import :: Date{..}, :: Time{..}
Diederik van Arkel's avatar
Diederik van Arkel committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

verboseInfo verbose info ps :== verbi verbose info ps
where
	verbi verbose info ps
		| not verbose && level3 info
			= ps
			= showInfo info ps

	level3 (Level3 _) = True
	level3 _ = False

getFICache` ps
	# (_,ps)	= getFICache ps
	# fi		= FI_EmptyCache
	= (fi,ps)

/*--- TO DO:

system module dependancy analysis is possible...

	ie. when you encounter a system module that must be recompiled then check in done list
	and remove those that depend on this system module and put them back into the todo list

should also be possible to detect cycles... -> generate warning dialogue...

---*/

System			:== "_system"

//--- project manager routines

53
:: SetMadeProjectFun :== Bool -> Bool -> Project -> GeneralSt -> GeneralSt
Diederik van Arkel's avatar
Diederik van Arkel committed
54 55

//	Compile /Check Syntax of the designated module
56
CompileProjectModule ::	!CompileOrCheckSyntax !Pathname !Project !SetMadeProjectFun !*GeneralSt -> *GeneralSt
57
CompileProjectModule compileOrCheckSyntax imp_pathname project setproject ps
58
	# ps					= ClearCompilerCache` ps
59
	# (srcpaths,ps)			= get_project_and_environment_paths project ps
60
	# (mdn,hierarchical_imp_pathname) = determine_dir_and_filename imp_pathname srcpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
61 62 63 64 65 66
	#! (abccache,ps)		= getABCCache ps
	#! (fileinfo,ps)		= getFICache` ps
	#! ((errs,warns,dircache),ps)
							= accFiles (DC_Setup srcpaths) ps
	# ({be_verbose},ps)		= getPrefs ps
	#! ps					= HandleDCErrors be_verbose errs warns ps
67
	#! (fileinfo,abccache,project,ok,newpaths,_,_,_,ps)
68
							= CompileTheProjectModule compileOrCheckSyntax mdn hierarchical_imp_pathname fileinfo abccache project dircache ps
Diederik van Arkel's avatar
Diederik van Arkel committed
69 70 71 72
	# ps					= setABCCache abccache ps
	# ps					= setFICache fileinfo ps
	= setproject ok newpaths project ps

73
GenAsmProjectModule :: !.Pathname !Project !SetMadeProjectFun !*GeneralSt -> *GeneralSt
74
GenAsmProjectModule imp_pathname project setproject ps
75
	# ps					= ClearCompilerCache` ps
76
	# (srcpaths,ps)			= get_project_and_environment_paths project ps
77
	# (mdn,hierarchical_imp_pathname) = determine_dir_and_filename imp_pathname srcpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
78 79 80 81 82 83
	# (abccache,ps)			= getABCCache ps
	#! (fileinfo,ps)		= getFICache` ps
	# ((errs,warns,dircache),ps)
							= accFiles (DC_Setup srcpaths) ps
	# ({be_verbose},ps)		= getPrefs ps
	# ps					= HandleDCErrors be_verbose errs warns ps
84
	# (fileinfo,abccache,project,ok,newpaths,abcpath,_,_,ps)
85
							= CompileTheProjectModule Compilation mdn hierarchical_imp_pathname fileinfo abccache project dircache ps
Diederik van Arkel's avatar
Diederik van Arkel committed
86 87 88 89
	| not ok || newpaths
		# ps				= setABCCache abccache ps
		# ps				= setFICache fileinfo ps
		= setproject True False project ps
90
	# (ps,abccache,fileinfo,project,ok,_)
91
							= GenCodeTheProjectModule True False AsmGeneration mdn abcpath abccache fileinfo project ps
Diederik van Arkel's avatar
Diederik van Arkel committed
92 93 94 95
	# ps					= setABCCache abccache ps
	# ps					= setFICache fileinfo ps
	= setproject True ok project ps

96
:: CleanupCont :== Pathname Bool Bool *GeneralSt -> *GeneralSt
Diederik van Arkel's avatar
Diederik van Arkel committed
97

98 99
:: *DriverCompilingInfo
	= Sync
100
	| AsyncWin ![CurrentlyCompiled] !AsyncWinCompilingInfo
101 102 103
	| Async	![CurrentlyCompiled] !AsyncCompilingInfo
	| Pers	!*CompilingInfo

104 105 106 107 108
::	AsyncWinCompilingInfo = {
		win_max_n_processes :: !Int,
		win_compiler_process_ids :: !CompilerProcessIds
	};

109 110 111 112 113 114
::	AsyncCompilingInfo = {
		max_n_processes :: !Int,
		compiler_process_ids :: !CompilerProcessIds,
		unknown_finished_processors :: !UnknownFinishedProcessors
	};

115 116
:: *DriverState
	= DInit !Bool !Project !MTPContinuation
117 118
	| DComp !Bool !*DirCache !DriverCompilingInfo ![!ModuleDirAndName] !DriverStateRecord
	| DQuitCompilers ![!ModuleDirAndName] !DriverCompilingInfo !DriverStateRecord
119
	| DGene ![!ModuleDirAndName] !DriverCodeGenerationInfo !DriverStateRecord
120
	| DOptimiseABC ![!ModuleDirAndName] !DriverStateRecord
121
	| DGenerateByteCode ![!ModuleDirAndName] !DriverStateRecord
122 123 124 125 126 127 128 129 130 131 132
	| DLink !DriverStateRecord
	| DDone

:: *DriverStateRecord =
	{ project	:: !Project
	, continue	:: !MTPContinuation
	, fileinfo	:: !FileInfoCache
	, abccache	:: !*ABCCache
	, libsinfo	:: !StaticLibInfo
	, ok		:: !Bool
	, newpaths	:: !Bool
133
	, modpaths	:: ![!ModuleDirAndName]
134
	, bytecode_version :: !Int
135 136
	}

137
BringProjectUptoDate :: !Bool CleanupCont !*GeneralSt -> *GeneralSt
Diederik van Arkel's avatar
Diederik van Arkel committed
138 139 140 141 142 143
BringProjectUptoDate force continuation ps
	#  (project,ps)		= getProject ps

	#	ps				= PrecompileFase project ps

	#	ps				= showInfo (Level1 "Bring up to date...") ps
144
	#	ps				= ClearCompilerCache` ps
Diederik van Arkel's avatar
Diederik van Arkel committed
145
		ini_step		= DInit force project cleanup
146
	= start ini_step step ps
Diederik van Arkel's avatar
Diederik van Arkel committed
147 148 149 150 151 152 153
where
	PrecompileFase project ps
		# (precompile,project)	= PR_GetPrecompile project
		| isJust precompile
			# ps				= showInfo (Level1 "Precompile...") ps
			# (ok,ec,ps)		= Execute` (fromJust precompile) ps
			// error handling???
154 155 156
			= ps
		= ps

157 158 159
	PostlinkFase ok project ps
		| not ok
			= ps
Diederik van Arkel's avatar
Diederik van Arkel committed
160 161
		# (postlink,project)	= PR_GetPostlink project
		| isJust postlink
162
			# (Just post_link)	= postlink
163
			# (prj_path,ps)		= getProjectFilePath ps
164
			# prj_dir_path  = PR_GetRootDir project
165 166
			# (app_path,ps)		= getStup ps
			# post_link			= fulPath app_path prj_dir_path post_link
Diederik van Arkel's avatar
Diederik van Arkel committed
167
			# ps				= showInfo (Level1 "Postlink...") ps
168
			# (ok,ec,ps)		= Execute` ("\""+++post_link+++"\" \""+++prj_path+++"\"") ps
Diederik van Arkel's avatar
Diederik van Arkel committed
169 170
			= ps
		= ps
171

172
	cleanup :: !Bool !Bool !Bool !FileInfoCache !StaticLibInfo ![!ModuleDirAndName] !Project !Bool (!*ABCCache,!GeneralSt) -> *(!*DriverState,!*GeneralSt)
Diederik van Arkel's avatar
Diederik van Arkel committed
173 174 175
	cleanup ok newpaths linked fileinfo libsinfo modpaths project intr (abccache,ps)
		| newpaths && not intr		// if paths have changed -> try again
			# ps			= showInfo (Level1 "Paths have changed: remaking.") ps
176
			# ps			= ClearCompilerCache` ps
Diederik van Arkel's avatar
Diederik van Arkel committed
177 178
			= MakeTheProject False fileinfo libsinfo abccache project cleanup` ps

179
		# ps				= PostlinkFase ok project ps
Diederik van Arkel's avatar
Diederik van Arkel committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193
		
		# ps				= showInfo (Level1 "Finished making.") ps
		# ps				= setProject project ps
		# ps				= setABCCache abccache ps
		# ps				= setFICache fileinfo ps
		# ps				= pm_update_project_window ps
		# path				= PR_GetExecPath project
		= stop (DDone,continuation path linked ok ps)
	
	cleanup` :: MTPContinuation
	cleanup` = cleanup

//-- Private stuff

194 195 196 197 198 199
get_project_and_environment_paths :: Project *GeneralSt -> *(!List String,!*GeneralSt)
get_project_and_environment_paths project ps
	# (syspaths,ps)			= getCurrentPaths ps
	# prjpaths				= PR_GetPaths project
	= (AppendLists prjpaths syspaths,ps)

200
:: MTPContinuation :== Bool Bool Bool FileInfoCache StaticLibInfo [!ModuleDirAndName] Project Bool *(*ABCCache,GeneralSt) -> *(*DriverState,*GeneralSt)
Diederik van Arkel's avatar
Diederik van Arkel committed
201

202
MakeTheProject :: !Bool !FileInfoCache !StaticLibInfo !*ABCCache !Project !MTPContinuation !GeneralSt -> (!*DriverState,!*GeneralSt)
Diederik van Arkel's avatar
Diederik van Arkel committed
203
MakeTheProject force fileinfo libsinfo abccache project continue ps
204
	# (srcpaths,ps)			= get_project_and_environment_paths project ps
Diederik van Arkel's avatar
Diederik van Arkel committed
205 206 207 208
	# ((errs,warns,dircache),ps)
							= accFiles (DC_Setup srcpaths) ps
	# ({be_verbose},ps)		= getPrefs ps
	# ps					= HandleDCErrors be_verbose errs warns ps
209
	# (root_mdn,project)	= PR_GetRootModuleDirAndName project
Diederik van Arkel's avatar
Diederik van Arkel committed
210
	# (env_static_libs,ps)	= getCurrentSlibs ps
211
	# sfiles				= StrictListToList (Concat (SL_Libs libsinfo) env_static_libs)
Diederik van Arkel's avatar
Diederik van Arkel committed
212 213 214 215
	# (err,ps)				= check_exists sfiles ps
	| isJust err
		# line				= Level3 ["Error: Unable to find static library: '" +++ fromJust err +++ "'."]
		# ps				= showInfo line ps
216
		= continue False False False fileinfo libsinfo [!] project False (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
217 218 219 220
	# ((errs,slibs),ps)		= accFiles (getLibs sfiles) ps
	| not (isEmpty errs)
		# line				= Level3 ["Error: Failed reading static libraries: '" :errs]
		# ps				= showInfo line ps
221
		= continue False False False fileinfo libsinfo [!] project False (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
222 223 224
	# slibs					= ListToStrictList slibs
	# libsinfo				= SL_SetDcls slibs libsinfo
	# ps					= showInfo (Level1 "Compiling...") ps
225
	# rest					= [!root_mdn]
Diederik van Arkel's avatar
Diederik van Arkel committed
226
	# (method,ps)			= getCurrentMeth ps
227 228
	# (compinfo,ps) = case method of
				CompileSync			-> (Sync,ps)
229
				(CompileAsync cmax)	-> PlatformDependant
230
										(AsyncWin [] {win_max_n_processes=cmax,win_compiler_process_ids=NoCompilerProcessIds},ps)								// win
231 232 233 234
										(let (compiler_process_ids,ps2) = getCompilerProcessIds ps
										 in  (Async [] {max_n_processes=cmax,compiler_process_ids=compiler_process_ids,unknown_finished_processors=NoUnknownFinishedProcessors},ps2)	// mac
										)
				CompilePers			-> (Pers InitCompilingInfo,ps)
235 236 237 238 239 240 241 242
	# ds = 
		{ project	= project
		, continue	= continue
		, fileinfo	= fileinfo
		, abccache	= abccache
		, libsinfo	= libsinfo
		, ok		= True
		, newpaths	= False
243
		, modpaths	= [!]
244
		, bytecode_version = -1
245 246
		}
	= step False (DComp force dircache compinfo rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
247 248 249 250 251 252 253 254
where
	check_exists [] ps = (Nothing,ps)
	check_exists [file:rest] ps
		# (ok,ps) = accFiles (FExists file) ps
		| ok = check_exists rest ps
		= (Just file,ps)

:: CurrentlyCompiled =
255
	{ iclModule	:: !ModuleDirAndName
Diederik van Arkel's avatar
Diederik van Arkel committed
256 257 258 259
	, options	:: CompilerOptions
	, slot		:: !Int
	}

260 261
:: *DriverCodeGenerationInfo
	= SyncCodeGeneration
262
	| ASyncCodeGeneration ![CodeGeneratorProcessNAndPaths] !AsyncCompilingInfo
263 264 265 266 267 268 269 270 271 272 273 274 275
	| ASyncCodeGenerationWin ![WinCodeGeneratorProcess] /*max_n_processes*/!Int

:: CodeGeneratorProcessNAndPaths
	= { cgp_process_n :: !Int, cgp_module_name :: !Modulename, cgp_obj_path :: !Pathname }

:: WinCodeGeneratorProcess = {
	wcgp_process_n :: !Int,
	wcgp_process_handle :: !Int,
	wcgp_scg :: !StartedCodeGenerator,
	wcgp_module_name :: !Modulename,
	wcgp_obj_path :: !Pathname
   }

276 277 278 279
module_occurs :: !String ![!ModuleDirAndName] -> Bool
module_occurs s [|x:xs] = x.mdn_name == s || module_occurs s xs
module_occurs s [!] =  False

280 281 282 283 284 285 286 287 288
get_neverTimeProfile_option :: !{#Char} Project !*GeneralSt -> (!Bool,!*GeneralSt)
get_neverTimeProfile_option module_name project ps
	= case (PR_GetModuleInfo module_name project) of
		Just modinfo
			-> (modinfo.compilerOptions.neverTimeProfile,ps)
		_
			# (prefs,ps) = getPrefs ps
			  defaultCO = prefs.compopts
			-> (defaultCO.neverTimeProfile,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
289

290
step :: !Bool !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
Diederik van Arkel's avatar
Diederik van Arkel committed
291
step intr (DInit force project setproject) ps
292
//	# ps				= showInfo (Level1 "Make the project...") ps
Diederik van Arkel's avatar
Diederik van Arkel committed
293 294 295 296 297
	# libsinfo			= PR_GetStaticLibsInfo project
	# (abccache,ps)		= getABCCache ps
	# (fileinfo,ps)		= getFICache` ps
	= MakeTheProject force fileinfo libsinfo abccache project setproject ps

298
step True (DComp force dircache compinfo rest ds) ps
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
	# ds = {ds & ok = False}
	# (modpaths,ds) = ds!modpaths
	= case compinfo of
		Pers inf
			#! ds = DGene modpaths SyncCodeGeneration ds
			// compile phase finished: kill clean compiler
			# (_,ps) = ExitCleanCompiler (inf,ps)
			-> step True ds ps
		AsyncWin _ _
			#! ds = DQuitCompilers modpaths compinfo ds
			-> step True ds ps
		_
			#! ds = DGene modpaths SyncCodeGeneration ds
			// need async cocl shootdown as well..
			-> step True ds ps
Diederik van Arkel's avatar
Diederik van Arkel committed
314

315
step intr (DComp force dircache Sync [!] ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
316
	// compile phase finished: remove all modules not (indirectly) imported by main module
317
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
318
	# (modpaths,project)	= PR_GetDirAndModulenames project
319
	# ds					= {ds & modpaths = modpaths, project = project}
Diederik van Arkel's avatar
Diederik van Arkel committed
320
	# ps					= showInfo (Level1 "Generating...") ps
321 322
	# (paths,ds)			= ds!modpaths
	= step intr (DGene paths SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
323

324
step intr (DComp force dircache Sync [!next : rest] ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
325
	// compile phase: check module 'next'
326
	| module_occurs next.mdn_name ds.modpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
327
		// if already done then skip
328
		= step intr (DComp force dircache Sync rest ds) ps
329
	| isProjLibraryModule next.mdn_name ds.libsinfo
330 331 332 333 334
		// instead of testing explicitly put libmodules in done <= conflicts with other administration
		= step intr (DComp force dircache Sync rest ds) ps
	# (ps,dircache,ok,newpaths`,rest,compinfo,ds,_)
							= UpdateDependencies force next rest Sync dircache ds ps
	# ds	= {ds & newpaths = ds.newpaths || newpaths`, ok = ok}
Diederik van Arkel's avatar
Diederik van Arkel committed
335
	| not ok
336 337
		# (paths,ds)		= ds!modpaths
		= step intr (DGene paths SyncCodeGeneration ds) ps
338
	# ds & modpaths = [!next : ds.modpaths]
339
	= cont (DComp force dircache compinfo rest ds,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
340

341
step intr (DComp force dircache (Pers inf) [!] ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
342 343 344
	// compile phase finished: kill clean compiler
	# (_,ps)				= ExitCleanCompiler (inf,ps)
	// compile phase finished: remove all modules not (indirectly) imported by main module
345
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
346
	# (modpaths,project)	= PR_GetDirAndModulenames project
347
	# ds					= {ds & modpaths = modpaths, project = project}
Diederik van Arkel's avatar
Diederik van Arkel committed
348
	# ps					= showInfo (Level1 "Generating...") ps
349 350
	# (paths,ds)			= ds!modpaths
	= step intr (DGene paths SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
351

352
step intr (DComp force dircache compinfo=:(Pers _) [!next:rest] ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
353
	// compile phase: check module 'next'
354
	| module_occurs next.mdn_name ds.modpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
355
		// if already done then skip
356
		= step intr (DComp force dircache compinfo rest ds) ps
357
	| isProjLibraryModule next.mdn_name ds.libsinfo
358
		// instead of testing explicitly put libmodules in done <= conflicts with other administration
359
		= step intr (DComp force dircache compinfo rest ds) ps
360 361 362
	# (ps,dircache,ok,newpaths`,rest,compinfo,ds,_)
							= UpdateDependencies force next rest compinfo dircache ds ps
	# ds	= {ds & newpaths = ds.newpaths || newpaths`, ok = ok}
Diederik van Arkel's avatar
Diederik van Arkel committed
363
	| not ok
364
		# (Pers inf)		= compinfo
365
		# (_,ps)			= ExitCleanCompiler (inf,ps)
366 367
		# (paths,ds)		= ds!modpaths
		= step intr (DGene paths SyncCodeGeneration ds) ps
368
	# ds & modpaths = [!next : ds.modpaths]
369
	= cont (DComp force dircache compinfo rest ds,ps)
370

371
step intr (DComp force dircache (Async [] async_compiling_info=:{max_n_processes,compiler_process_ids,unknown_finished_processors=NoUnknownFinishedProcessors}) [!] ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
372
	// compile phase finished: remove all modules not (indirectly) imported by main module
373
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
374
	# (modpaths,project)	= PR_GetDirAndModulenames project
375
	# ds					= {ds & modpaths = modpaths, project = project}
376
	# (os_error,ps)			= ClearCompilerCaches compiler_process_ids ps;
Diederik van Arkel's avatar
Diederik van Arkel committed
377
	# ps					= showInfo (Level1 "Generating...") ps
378
	# (paths,ds)			= ds!modpaths
379
	= step intr (DGene paths (ASyncCodeGeneration [] async_compiling_info) ds) ps
380

381
step intr (DComp force dircache (AsyncWin [] {win_compiler_process_ids,win_max_n_processes}) [!] ds) ps
382 383
	// compile phase finished: remove all modules not (indirectly) imported by main module
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
384
	# (modpaths,project)	= PR_GetDirAndModulenames project
385
	# ds					= {ds & modpaths = modpaths, project = project}
386
	# ps = app_world_instead_of_ps (QuitCleanCompiler True win_compiler_process_ids) ps;
387 388
	# ps					= showInfo (Level1 "Generating...") ps
	# (paths,ds)			= ds!modpaths
John van Groningen's avatar
John van Groningen committed
389
	= step intr (DGene paths (IF_WINDOWS (ASyncCodeGenerationWin [] win_max_n_processes) SyncCodeGeneration) ds) ps
390

391
step intr state=:(DComp force _ (Async _ _) _ _) ps
392 393
	# (state, ps)			= check_completed state ps
	# (state, ps)			= start_compilations state ps
Diederik van Arkel's avatar
Diederik van Arkel committed
394 395
	= cont (state, ps)
	where
396
		check_completed :: !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
397 398
		check_completed state=:(DComp force _ (Async current=:[_:_] {max_n_processes,compiler_process_ids}) _ _)  ps
			= case (CompilePollCompleted compiler_process_ids ps) of
Diederik van Arkel's avatar
Diederik van Arkel committed
399 400 401 402
				(NoFinishedCompiler,ps)
					-> check_unknow_processors_are_known state ps
				(UnknownFinishedCompiler,ps)
					-> case state of
403
						DComp force dircache (Async current {max_n_processes,compiler_process_ids,unknown_finished_processors}) todo ds
Diederik van Arkel's avatar
Diederik van Arkel committed
404
							# unknown_finished_processors = add_unknown_finished_processor unknown_finished_processors
405
							# state = DComp force dircache (Async current {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=unknown_finished_processors}) todo ds
Diederik van Arkel's avatar
Diederik van Arkel committed
406 407 408 409 410 411 412
							-> check_completed state ps
				(FinishedCompiler completedSlot exitcode,ps)
					#! (state,ps) = process_completed completedSlot exitcode state ps
					-> check_completed state ps
		check_completed state ps
			= check_unknow_processors_are_known state ps

413 414 415
		check_unknow_processors_are_known (DComp force dircache (Async current {max_n_processes,compiler_process_ids,unknown_finished_processors=UnknownFinishedProcessors n_unknown_finished_processors known_finished_processors}) todo ds) ps
			| n_unknown_finished_processors+length known_finished_processors>=max_n_processes
				# state = DComp force dircache (Async current {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=NoUnknownFinishedProcessors}) todo ds
Diederik van Arkel's avatar
Diederik van Arkel committed
416 417 418
				# (state,ps) = handle_completed_processes 0 state ps
					with
						handle_completed_processes process_n state ps
419
							| process_n>=max_n_processes
Diederik van Arkel's avatar
Diederik van Arkel committed
420 421 422 423 424 425 426 427 428 429 430 431 432
								= (state,ps)
							| isMember process_n known_finished_processors
								= handle_completed_processes (process_n+1) state ps
								# (_,ps) = SendRepeatResult process_n ps
								/*
								# exitcode = 1
								#! (state,ps) = process_completed process_n exitcode state ps
								*/
								= handle_completed_processes (process_n+1) state ps								
				= (state, ps)
		check_unknow_processors_are_known state ps
			=	(state, ps)

433
		process_completed :: !Int !Int !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
434
		process_completed completedSlot exitcode (DComp force dircache (Async current {max_n_processes,compiler_process_ids,unknown_finished_processors}) todo ds) ps
435 436 437
			# (completed, current)			= removeFromCurrent completedSlot current
			# unknown_finished_processors	= remove_from_unknown_finished_processors completedSlot unknown_finished_processors
			# (startupdir,ps)				= getStup ps
438
			# (interact, ps)				= getInteract ps
439
			# typewin = update_type_window interact completed.iclModule.mdn_name
440
			# ccstring						= "dummy ccstring for now.."
441
			# (abcpath,res,ps)				= CompileHandleExitCode exitcode ccstring startupdir completedSlot updateErrorWindow typewin 
442
												completed.iclModule completed.options.listTypes ps // types param
443
			# (_,(fileinfo,abccache,project,ok,newpaths`,_,deps,dircache,ps))
444
											= ProcessCompilerMsg Nothing Compilation completed.options completed.iclModule abcpath res ds.fileinfo dircache ds.abccache ds.project ps
445
			# ds							= {ds & newpaths = ds.newpaths || newpaths`, fileinfo = fileinfo, abccache = abccache, project = project, ok = ok}
446 447 448 449
			| ok
				# ds & modpaths = [!completed.iclModule : ds.modpaths]
				  todo = deps++|todo
				= (DComp force dircache (Async current {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=unknown_finished_processors}) todo ds, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
450
			// not ok
451
				# (os_error,ps) = ClearCompilerCaches compiler_process_ids ps;
452 453
				# (paths,ds)	= ds!modpaths
				= (DGene paths SyncCodeGeneration ds, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
454

455
		start_compilations :: !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
456
		start_compilations state=:(DComp force dircache (Async current {max_n_processes,compiler_process_ids,unknown_finished_processors}) [!next : rest] ds) ps
457
			// all threads used?
458 459
			| length current >= max_n_processes
				# ps = DelayEventLoop ps;			
Diederik van Arkel's avatar
Diederik van Arkel committed
460
				= (state, ps)
461
			// compile phase: check module 'next'
462
			| module_occurs next.mdn_name ds.modpaths || currently_compiled next.mdn_name current
463
				= start_compilations (DComp force dircache (Async current {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=unknown_finished_processors}) rest ds) ps
464
			| isProjLibraryModule next.mdn_name ds.libsinfo
465
				// instead of testing explicitly put libmodules in done <= conflicts with other administration
466
				= (DComp force dircache (Async current {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=unknown_finished_processors}) rest ds, ps)
467
			# (ps,dircache,ok,_,rest,compinfo,ds,_)
468
				= UpdateDependencies force next rest (Async current {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=unknown_finished_processors}) dircache ds ps
469
			# ds = {ds & ok = ok}
Diederik van Arkel's avatar
Diederik van Arkel committed
470
			| not ok
471
				# (os_error,ps) = ClearCompilerCaches compiler_process_ids ps;
472 473 474
				#! (paths,ds)	= ds!modpaths
				= (DGene paths SyncCodeGeneration ds, ps)
			= start_compilations (DComp force dircache compinfo rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
475
		start_compilations state ps
476
			# ps = DelayEventLoop ps
Diederik van Arkel's avatar
Diederik van Arkel committed
477 478 479 480 481 482 483
			= (state, ps)

step intr state=:(DComp force dircache compinfo=:(AsyncWin _ _) rest ds) ps
	# (state, ps) = check_completed state ps
	# (state, ps) = start_compilations state ps
	= cont (state, ps)
	where
484
		check_completed :: !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
485 486
		check_completed state=:(DComp _ _ (AsyncWin current=:[_:_] {win_compiler_process_ids}) _ _)  ps
			=	case (CompilePollCompleted win_compiler_process_ids ps) of
Diederik van Arkel's avatar
Diederik van Arkel committed
487 488 489 490
					(NoFinishedCompiler, ps)
						-> (state, ps)
					(FinishedCompiler completedSlot exitcode, ps)
						#! (state,ps) = process_completed completedSlot exitcode state ps
491 492 493
						-> IF_BATCHBUILD_OR_IDE
								(state,ps)
								(check_completed state ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
494 495 496 497 498
					(UnknownFinishedCompiler,ps)
						-> (state, ps)	// -> doesn't occur on win
		check_completed state ps
			=	(state, ps)

499
		process_completed :: !Int !Int !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
500
		process_completed completedSlot exitcode (DComp force dircache (AsyncWin current {win_max_n_processes,win_compiler_process_ids}) todo ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
501 502
			# (completed, current)	= removeFromCurrent completedSlot current
			# (startupdir,ps)		= getStup ps
503
			# (interact, ps)		= getInteract ps
504
			# typewin				= update_type_window interact completed.iclModule.mdn_name
Diederik van Arkel's avatar
Diederik van Arkel committed
505
			# ccstring				= "dummy ccstring for now.."
506
			# (abcpath,res,ps)		= CompileHandleExitCode exitcode ccstring startupdir completedSlot updateErrorWindow typewin 
Diederik van Arkel's avatar
Diederik van Arkel committed
507
										completed.iclModule completed.options.listTypes ps // types param
508
			# (_,(fileinfo,abccache,project,ok,newpaths`,_,deps,dircache,ps))
509
				= ProcessCompilerMsg Nothing Compilation completed.options completed.iclModule abcpath res ds.fileinfo dircache ds.abccache ds.project ps
Diederik van Arkel's avatar
Diederik van Arkel committed
510 511
			# ds					= {ds & newpaths = ds.newpaths || newpaths`, fileinfo = fileinfo, abccache = abccache, project = project, ok = ok}
			| ok
512 513 514
				# ds & modpaths = [!completed.iclModule : ds.modpaths]
				  todo = deps++|todo
				= (DComp force dircache (AsyncWin current {win_max_n_processes=win_max_n_processes,win_compiler_process_ids=win_compiler_process_ids}) todo ds, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
515 516
			// not ok
				# (paths,ds)	= ds!modpaths
517
				= (DQuitCompilers paths (AsyncWin current {win_max_n_processes=win_max_n_processes,win_compiler_process_ids=win_compiler_process_ids}) ds,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
518

519
		start_compilations :: !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
520
		start_compilations state=:(DComp force dircache (AsyncWin current {win_max_n_processes,win_compiler_process_ids}) [!next : rest] ds) ps
521 522
			| length current >= win_max_n_processes
				# ps = DelayEventLoop ps;			
Diederik van Arkel's avatar
Diederik van Arkel committed
523
				= (state, ps)
524 525
			// compile phase: check module 'next'
			| module_occurs next.mdn_name ds.modpaths || currently_compiled next.mdn_name current
526
				= start_compilations (DComp force dircache (AsyncWin current {win_max_n_processes=win_max_n_processes,win_compiler_process_ids=win_compiler_process_ids}) rest ds) ps
527
			| isProjLibraryModule next.mdn_name ds.libsinfo
Diederik van Arkel's avatar
Diederik van Arkel committed
528
				// instead of testing explicitly put libmodules in done <= conflicts with other administration
529
				= (DComp force dircache (AsyncWin current {win_max_n_processes=win_max_n_processes,win_compiler_process_ids=win_compiler_process_ids}) rest ds, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
530
			# (ps,dircache,ok,_,rest,compinfo,ds,_)
531
				= UpdateDependencies force next rest (AsyncWin current {win_max_n_processes=win_max_n_processes,win_compiler_process_ids=win_compiler_process_ids}) dircache ds ps
Diederik van Arkel's avatar
Diederik van Arkel committed
532 533 534
			# ds = {ds & ok = ok}
			| not ok
				#! (paths,ds)	= ds!modpaths
535
				= (DQuitCompilers paths (AsyncWin current {win_max_n_processes=win_max_n_processes,win_compiler_process_ids=win_compiler_process_ids}) ds,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
536
			= start_compilations (DComp force dircache compinfo rest ds) ps
537
		start_compilations state=:(DComp force dircache (AsyncWin [] _) [!] ds) ps
538
			= (state, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
539
		start_compilations state ps
540
			# ps = DelayEventLoop ps;
Diederik van Arkel's avatar
Diederik van Arkel committed
541 542
			= (state, ps)

543 544 545 546 547 548 549 550 551 552 553 554 555
step intr (DQuitCompilers modpaths (AsyncWin [] {win_compiler_process_ids}) ds) ps
	# ps = app_world_instead_of_ps (QuitCleanCompiler True win_compiler_process_ids) ps
	= step intr (DGene modpaths SyncCodeGeneration ds) ps
step intr state=:(DQuitCompilers modpaths (AsyncWin current async_win_compiling_info=:{win_compiler_process_ids}) ds) ps
	= case (CompilePollCompleted win_compiler_process_ids ps) of
		(NoFinishedCompiler, ps)
			-> cont (state, ps)
		(FinishedCompiler completedSlot exitcode, ps)
			# (completed, current) = removeFromCurrent completedSlot current
			-> cont (DQuitCompilers modpaths (AsyncWin current async_win_compiling_info) ds, ps)
		(UnknownFinishedCompiler,ps)
			-> cont (state, ps)	// -> doesn't occur on win

556
step intr (DGene [!] SyncCodeGeneration ds) ps
557 558
	# (paths,ds) = ds!modpaths
	= step intr (DOptimiseABC paths ds) ps
559

560
step intr (DGene [!] (ASyncCodeGeneration [] {unknown_finished_processors=NoUnknownFinishedProcessors,compiler_process_ids}) ds) ps
561
	# ps = setCompilerProcessIds compiler_process_ids ps
562 563
	# (paths,ds) = ds!modpaths
	= step intr (DOptimiseABC paths ds) ps
564

565
step intr (DGene [!] (ASyncCodeGenerationWin [] _) ds) ps
566 567
	# (paths,ds) = ds!modpaths
	= step intr (DOptimiseABC paths ds) ps
568

569
step intr (DGene [!mdn:rest] SyncCodeGeneration ds) ps
570 571
	| not ds.ok || intr
		# ds = {ds & ok = False}
572 573
		# (paths,ds) = ds!modpaths
		= step intr (DOptimiseABC paths ds) ps
574
	# (abccache,fileinfo,gen,abcpath,ps)	= check_object_file_out_of_date mdn False ds.abccache ds.fileinfo ds.project ps
575
	# (ps,abccache,fileinfo,project,ok,_)	= GenCodeTheProjectModule gen False CodeGeneration mdn abcpath abccache fileinfo ds.project ps
576
	# ds = {ds & abccache = abccache, fileinfo = fileinfo, project = project, ok = ok}
Diederik van Arkel's avatar
Diederik van Arkel committed
577
	| not ok
578 579
		# (paths,ds) = ds!modpaths
		= step intr (DOptimiseABC paths ds) ps
580
	= cont (DGene rest SyncCodeGeneration ds, ps)
581

582
step intr (DGene paths (ASyncCodeGeneration busy_processes {max_n_processes,compiler_process_ids,unknown_finished_processors}) ds) ps
583 584
	# (ok,busy_processes,unknown_finished_processors,project,fileinfo,ps)
		= handle_finished_code_generators busy_processes unknown_finished_processors ds.project ds.fileinfo ps
Diederik van Arkel's avatar
Diederik van Arkel committed
585 586
		with
			handle_finished_code_generators busy_processes=:[_:_] unknown_finished_processors project fileinfo ps
587
				= case (CompilePollCompleted compiler_process_ids ps) of
Diederik van Arkel's avatar
Diederik van Arkel committed
588 589 590 591 592 593 594 595 596 597
					(NoFinishedCompiler, ps)
						-> check_unknow_processors_are_known busy_processes unknown_finished_processors project fileinfo ps
					(UnknownFinishedCompiler,ps)
						# unknown_finished_processors = add_unknown_finished_processor unknown_finished_processors
						-> (True,busy_processes,unknown_finished_processors,project,fileinfo,ps)
					(FinishedCompiler finished_cg_slot_n exit_code, ps)
//						# ps  = trace ("code generator finished "+++toString finished_cg_slot_n+++" "+++toString exit_code+++"\n") ps
//						# ps  = trace ("f "+++toString finished_cg_slot_n+++" "+++toString exit_code+++" ") ps

						# unknown_finished_processors = remove_from_unknown_finished_processors finished_cg_slot_n unknown_finished_processors
598
						# (module_name,obj_path,busy_processes) = get_paths_and_remove_process_from_list finished_cg_slot_n busy_processes
Diederik van Arkel's avatar
Diederik van Arkel committed
599
							with
600 601 602 603 604
								get_paths_and_remove_process_from_list finished_cg_slot_n [busy_process=:{cgp_process_n,cgp_module_name,cgp_obj_path} : rest]
									| finished_cg_slot_n==cgp_process_n
										= (cgp_module_name,cgp_obj_path,rest)
										# (module_name,obj_path,rest) = get_paths_and_remove_process_from_list finished_cg_slot_n rest
										= (module_name,obj_path,[busy_process:rest])
605
								get_paths_and_remove_process_from_list finished_cg_slot_n []
Diederik van Arkel's avatar
Diederik van Arkel committed
606 607
									= abort "driver.icl: unknown code generator id"
						| exit_code==0
608 609
							# (fileinfo,ps) = accFiles (FI_UpdateObjDate module_name obj_path fileinfo) ps
							# project = PR_SetCodeGenerated module_name project
Diederik van Arkel's avatar
Diederik van Arkel committed
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
							-> handle_finished_code_generators busy_processes unknown_finished_processors project fileinfo ps
							-> (False,busy_processes,unknown_finished_processors,project,fileinfo,ps)
			handle_finished_code_generators [] unknown_finished_processors project fileinfo ps
				= check_unknow_processors_are_known [] unknown_finished_processors project fileinfo ps

			check_unknow_processors_are_known busy_processes (UnknownFinishedProcessors n_unknown_finished_processors known_finished_processors) project fileinfo ps
				| n_unknown_finished_processors+length known_finished_processors>=max_n_processes
					# (busy_processes,project,fileinfo,ps) = handle_completed_processes 0 busy_processes project fileinfo ps
						with
							handle_completed_processes process_n busy_processes project fileinfo ps
								| process_n>=max_n_processes
									= (busy_processes,project,fileinfo,ps)
								| isMember process_n known_finished_processors
									= handle_completed_processes (process_n+1) busy_processes project fileinfo ps
									# (_,ps) = SendRepeatResult process_n ps
									/*
									# unknown_finished_processors = remove_from_unknown_finished_processors finished_cg_slot_n unknown_finished_processors
627
									# (abc_path,obj_path,busy_processes) = get_paths_and_remove_process_from_list finished_cg_slot_n busy_processes
Diederik van Arkel's avatar
Diederik van Arkel committed
628
										with
629
											get_paths_and_remove_process_from_list finished_cg_slot_n [busy_process=:(slot,abc_path,obj_path) : rest]
Diederik van Arkel's avatar
Diederik van Arkel committed
630 631
												| process_n==slot
													= (abc_path,obj_path,rest)
632
													# (abc_path,obj_path,rest) = get_paths_and_remove_process_from_list finished_cg_slot_n rest
Diederik van Arkel's avatar
Diederik van Arkel committed
633
													= (abc_path,obj_path,[busy_process:rest])
634
											get_paths_and_remove_process_from_list finished_cg_slot_n []
Diederik van Arkel's avatar
Diederik van Arkel committed
635 636 637 638 639 640 641 642
												= abort "driver.icl: unknown code generator id"
									# (fileinfo,ps) = accFiles (FI_UpdateObjDate abc_path obj_path fileinfo) ps
									# project = PR_SetCodeGenerated (GetModuleName abc_path) project
									*/
									= handle_completed_processes (process_n+1) busy_processes project fileinfo ps								
					= (True,busy_processes,NoUnknownFinishedProcessors,project,fileinfo,ps)
			check_unknow_processors_are_known busy_processes unknown_finished_processors project fileinfo ps
				= (True,busy_processes,unknown_finished_processors,project,fileinfo,ps)
643 644
	# ds = {ds & fileinfo = fileinfo, project = project, ok = ds.ok && ok && not intr}
	| not ds.ok
645
		= cont (DGene paths (ASyncCodeGeneration busy_processes {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=unknown_finished_processors}) ds,ps)
646
	| length busy_processes>=max_n_processes || (case paths of [!] -> True ; _ -> False)
647 648
		# ps = DelayEventLoop ps
		= cont (DGene paths (ASyncCodeGeneration busy_processes {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=unknown_finished_processors}) ds,ps)
649
	# (ok,paths,busy_processes,fileinfo,abccache,ps) = start_code_generators paths busy_processes ds.fileinfo ds.abccache ps
Diederik van Arkel's avatar
Diederik van Arkel committed
650
		with
651 652
			start_code_generators :: [!ModuleDirAndName] [CodeGeneratorProcessNAndPaths] FileInfoCache *ABCCache !*GeneralSt -> *(.Bool,[!ModuleDirAndName],[CodeGeneratorProcessNAndPaths],FileInfoCache,*ABCCache,!*GeneralSt)
			start_code_generators paths=:[!mdn : rest] busy_processes fileinfo abccache ps
Diederik van Arkel's avatar
Diederik van Arkel committed
653
				| length busy_processes>=max_n_processes
654
		 			# ps = DelayEventLoop ps
Diederik van Arkel's avatar
Diederik van Arkel committed
655
					= (True,paths,busy_processes,fileinfo,abccache,ps)
656 657
				# (abccache,fileinfo,gen,abc_path,ps)
									= check_object_file_out_of_date mdn False abccache fileinfo project ps
658
				# cgo				= PR_GetCodeGenOptions project
659
				# (proc,ps)			= getCurrentProc ps
660
				# ((info,abccache,fileinfo), ps)
661
									= FI_GetFileInfo proc mdn abccache fileinfo ps
Diederik van Arkel's avatar
Diederik van Arkel committed
662 663
				| not gen
					= start_code_generators rest busy_processes fileinfo abccache ps
664
				# module_name		= mdn.mdn_name
665
				# ps				= showInfo (Level2 (
666 667
													(foldl (+++) ("Generating code for " +++ module_name)
															[" "+++cgp_module_name \\ {cgp_module_name}<-busy_processes])
Diederik van Arkel's avatar
Diederik van Arkel committed
668 669
													)) ps
				# (startupdir,ps)	= getStup ps
670 671 672 673
				  (cgen,ps)			= getCurrentCgen ps
				  (neverTimeProfile,ps) = get_neverTimeProfile_option module_name project ps
				  ao				= PR_GetApplicationOptions project
				  timeprofile		= ao.profiling && (not neverTimeProfile)
674
				# free_slot			= hd (removeMembers [0..max_n_processes-1] [cgp_process_n \\ {cgp_process_n} <- busy_processes])
Diederik van Arkel's avatar
Diederik van Arkel committed
675

676
				# (res,obj_path,compiler_process_ids,ps) = StartCodeGenerator cgen updateErrorWindow CodeGeneration abc_path free_slot timeprofile cgo proc ao startupdir compiler_process_ids ps
677
				| not res
Diederik van Arkel's avatar
Diederik van Arkel committed
678
					= (False,rest,busy_processes,fileinfo,abccache,ps)
679
				# busy_processes	= [{cgp_process_n=free_slot,cgp_module_name=module_name,cgp_obj_path=obj_path}:busy_processes]
Diederik van Arkel's avatar
Diederik van Arkel committed
680
				= start_code_generators rest busy_processes fileinfo abccache ps
681
			start_code_generators [!] busy_processes fileinfo abccache ps
682
				# ps = DelayEventLoop ps
683
				= (True,[!],busy_processes,fileinfo,abccache,ps)
684
	# ds = {ds & fileinfo = fileinfo, abccache = abccache, ok = ok}
685
	= cont (DGene paths (ASyncCodeGeneration busy_processes {max_n_processes=max_n_processes,compiler_process_ids=compiler_process_ids,unknown_finished_processors=unknown_finished_processors}) ds, ps)
686

687 688 689 690 691 692
step intr (DGene paths (ASyncCodeGenerationWin busy_processes win_max_n_processes) ds) ps
	# (ok,busy_processes,project,fileinfo,ps)
		= handle_finished_code_generators busy_processes ds.project ds.fileinfo ps
		with
			handle_finished_code_generators busy_processes=:[|_:_] project fileinfo ps
				# process_handles = {wcgp_process_handle \\ {wcgp_process_handle} <- busy_processes}
693
				# (i,exit_code,ps) = wait_for_finished_code_generator process_handles ps
694 695 696 697 698 699 700 701 702
				| i<0
					= (False,busy_processes,project,fileinfo,ps)
					# (finished_process,busy_processes) = remove_finished_process_from_list i busy_processes
						with
							remove_finished_process_from_list i [p:ps]
								| i==0
									= (p,ps)
									# (fp,ps) = remove_finished_process_from_list (i-1) ps;
									= (fp,[p:ps])
703
					# (ok,ps) = finish_code_generator finished_process.wcgp_process_handle finished_process.wcgp_scg exit_code updateErrorWindow ps
704 705 706
					| ok
						# module_name = finished_process.wcgp_module_name
						  obj_path = finished_process.wcgp_obj_path
707
						# (fileinfo,ps) = accFiles (FI_UpdateObjDate module_name obj_path fileinfo) ps
708 709 710 711 712 713 714 715
						# project = PR_SetCodeGenerated module_name project
						= (True,busy_processes,project,fileinfo,ps)
						= (False,busy_processes,project,fileinfo,ps)
			handle_finished_code_generators [|] project fileinfo ps
				= (True,[],project,fileinfo,ps)
	# ds = {ds & fileinfo = fileinfo, project = project, ok = ds.ok && ok && not intr}
	| not ds.ok
		= cont (DGene paths (ASyncCodeGenerationWin busy_processes win_max_n_processes) ds,ps)
716
	| length busy_processes>=win_max_n_processes || (case paths of [!] -> True ; _ -> False)
717 718 719
		= cont (DGene paths (ASyncCodeGenerationWin busy_processes win_max_n_processes) ds,ps)
	# (ok,paths,busy_processes,fileinfo,abccache,ps) = start_code_generators paths busy_processes ds.fileinfo ds.abccache ps
		with
720 721 722
			start_code_generators :: [!ModuleDirAndName] [WinCodeGeneratorProcess] FileInfoCache *ABCCache !*GeneralSt
						   -> *(Bool,[!ModuleDirAndName],[WinCodeGeneratorProcess],FileInfoCache,*ABCCache,!*GeneralSt )
			start_code_generators paths=:[!mdn:rest] busy_processes fileinfo abccache ps
723 724
				| length busy_processes>=win_max_n_processes
					= (True,paths,busy_processes,fileinfo,abccache,ps)
725 726
				# (abccache,fileinfo,gen,abc_path,ps)
									= check_object_file_out_of_date mdn False abccache fileinfo project ps
727
				# (proc,ps)			= getCurrentProc ps
728
				# ((_,abccache,fileinfo), ps) = FI_GetFileInfo proc mdn abccache fileinfo ps
729 730
				| not gen
					= start_code_generators rest busy_processes fileinfo abccache ps
731
				# module_name		= mdn.mdn_name
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
				# ps				= showInfo (Level2 (
													(foldl (+++) ("Generating code for "+++ module_name)
															[" "+++wcgp_module_name \\ {wcgp_module_name}<-busy_processes])
													)) ps
				# (startupdir,ps)	= getStup ps
				  (cgen,ps)			= getCurrentCgen ps
				  (neverTimeProfile,ps) = get_neverTimeProfile_option module_name project ps
				  ao				= PR_GetApplicationOptions project
				  timeprofile		= ao.profiling && (not neverTimeProfile)
				  cgo				= PR_GetCodeGenOptions project
				# free_slot			= hd (removeMembers [0..win_max_n_processes-1] [wcgp_process_n \\ {wcgp_process_n} <- busy_processes])

				# (res,process_handle,scg,ps)
					= start_code_generator cgen updateErrorWindow abc_path free_slot timeprofile cgo proc startupdir ps
				| not res
					= (False,rest,busy_processes,fileinfo,abccache,ps)
748 749
				# obj_path = ModuleDirAndNameToObjSystemPathname proc mdn
				# new_process = {wcgp_process_n=free_slot,wcgp_process_handle=process_handle,wcgp_scg=scg,wcgp_module_name=module_name,wcgp_obj_path=obj_path}
750 751
				# busy_processes = [new_process:busy_processes]
				= start_code_generators rest busy_processes fileinfo abccache ps
752 753
			start_code_generators [!] busy_processes fileinfo abccache ps
				= (True,[!],busy_processes,fileinfo,abccache,ps)
754 755 756
	# ds = {ds & fileinfo = fileinfo, abccache = abccache, ok = ok}
	= cont (DGene paths (ASyncCodeGenerationWin busy_processes win_max_n_processes) ds, ps)

757 758
step intr (DOptimiseABC [!mdn:rest] ds) ps
	# cgo = PR_GetCodeGenOptions ds.project
759
	| not ds.ok || not cgo.optimise_abc
760
		# (paths,ds) = ds!modpaths
761
		= step intr (DGenerateByteCode paths ds) ps
762 763 764 765 766 767 768
	# (tp,ps) = getCurrentProc ps
	# ((modinfo,abccache,fileinfo),ps) = FI_GetFileInfo tp mdn ds.abccache ds.fileinfo ps
	# (ok,ps) = OptimiseABC mdn modinfo.abcpath modinfo.abcdate ps
	# ds & abccache=abccache, fileinfo=fileinfo, ok=ok
	= cont (DOptimiseABC rest ds, ps)
step intr (DOptimiseABC [!] ds) ps
	# (paths,ds) = ds!modpaths
769
	= step intr (DGenerateByteCode paths ds) ps
770

771
step intr (DGenerateByteCode paths ds=:{bytecode_version= -1}) ps
772 773
	| not ds.ok
		= step intr (DLink ds) ps
774 775
	# cgo = PR_GetCodeGenOptions ds.project
	| not cgo.generate_bytecode
776
		# ps = showInfo (Level1 "Linking...") ps
777
		= step intr (DLink ds) ps
778 779 780 781 782 783 784 785 786 787 788 789 790 791
	# (startupdir,ps) = getStup ps
	  (bcgen,ps) = getCurrentBCgen ps
	  bcgen = startupdir +++ DirSeparatorString +++ bcgen
	# (exitcode,err,ps) = RunExternalCommand bcgen ["-V"] startupdir ps
	# ok = exitcode == 0
	# (ok,version) = case err of
		[v] -> case toInt v of
			0 -> (False,0)
			v -> (ok,v)
		_ -> (False,0)
	# ps = if ok ps (updateErrorWindow ["Failed to get bytecode instruction set version"] ps)
	| not ok
		# ps = showInfo (Level1 "Linking...") ps
		= step intr (DLink ds) ps
792 793
	= step intr (DGenerateByteCode paths {ds & bytecode_version=version}) ps
step intr (DGenerateByteCode [!mdn:rest] ds) ps
794 795
	| not ds.ok
		= step intr (DLink ds) ps
796
	# cgo = PR_GetCodeGenOptions ds.project
797 798
	# (tp,ps) = getCurrentProc ps
	# ((modinfo,abccache,fileinfo),ps) = FI_GetFileInfo tp mdn ds.abccache ds.fileinfo ps
799
	# (ok,ps) = ByteCodeGen ds.bytecode_version cgo.optimise_abc mdn modinfo.abcpath ps
800
	# ds & abccache=abccache, fileinfo=fileinfo, ok=ok
801 802
	= cont (DGenerateByteCode rest ds,ps)
step intr (DGenerateByteCode [!] ds) ps
803 804
	| not ds.ok
		= step intr (DLink ds) ps
805 806 807
	#! ps = showInfo (Level1 "Linking...") ps
	= step intr (DLink ds) ps

808
step intr (DLink ds=:{ok, newpaths, fileinfo, libsinfo, modpaths, abccache, project, continue}) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
809 810
	//	Check whether executable is out of date and relink it	if required.
	| intr || not ok
811
		= continue False newpaths