PmDriver.icl 79 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
Diederik van Arkel's avatar
Diederik van Arkel committed
4 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 53 54 55

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

traceInfo _ ps :== ps
//traceInfo i ps :== showInfo i ps

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

56
:: SetMadeProjectFun :== Bool -> Bool -> Project -> GeneralSt -> GeneralSt
Diederik van Arkel's avatar
Diederik van Arkel committed
57 58

//	Compile /Check Syntax of the designated module
59
CompileProjectModule ::	!CompileOrCheckSyntax !Pathname !Project !SetMadeProjectFun !*GeneralSt -> *GeneralSt
Diederik van Arkel's avatar
Diederik van Arkel committed
60
CompileProjectModule compilerOrCheckSyntax path project setproject ps
61
	# ps					= ClearCompilerCache` ps
Diederik van Arkel's avatar
Diederik van Arkel committed
62 63 64 65 66 67 68 69 70 71
	# (syspaths,ps)			= getCurrentPaths ps
	# prjpaths				= PR_GetPaths project
	# srcpaths				= AppendLists prjpaths syspaths
	#! (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
	#! (ps,fileinfo,_,abccache,project,ok,newpaths,_,_)
72
							= CompileTheProjectModule compilerOrCheckSyntax path fileinfo dircache abccache project ps
Diederik van Arkel's avatar
Diederik van Arkel committed
73 74 75 76
	# ps					= setABCCache abccache ps
	# ps					= setFICache fileinfo ps
	= setproject ok newpaths project ps

77
GenAsmProjectModule :: !.Pathname !Project !SetMadeProjectFun !*GeneralSt -> *GeneralSt
Diederik van Arkel's avatar
Diederik van Arkel committed
78
GenAsmProjectModule path project setproject ps
79
	# ps					= ClearCompilerCache` ps
Diederik van Arkel's avatar
Diederik van Arkel committed
80 81 82 83 84 85 86 87 88 89
	# (syspaths,ps)			= getCurrentPaths ps
	# prjpaths				= PR_GetPaths project
	# srcpaths				= AppendLists prjpaths syspaths
	# (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
	# (ps,fileinfo,_,abccache,project,ok,newpaths,abcpath,_)
90
							= CompileTheProjectModule Compilation path fileinfo dircache abccache project ps
Diederik van Arkel's avatar
Diederik van Arkel committed
91 92 93 94 95 96 97 98 99 100
	| not ok || newpaths
		# ps				= setABCCache abccache ps
		# ps				= setFICache fileinfo ps
		= setproject True False project ps
	#	(ps,abccache,fileinfo,project,ok,_)
							= GenCodeTheProjectModule True False AsmGeneration abcpath abccache fileinfo project ps
	# ps					= setABCCache abccache ps
	# ps					= setFICache fileinfo ps
	= setproject True ok project ps

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

103 104
:: *DriverCompilingInfo
	= Sync
105
	| AsyncWin ![CurrentlyCompiled] !AsyncWinCompilingInfo
106 107 108
	| Async	![CurrentlyCompiled] !AsyncCompilingInfo
	| Pers	!*CompilingInfo

109 110 111 112 113
::	AsyncWinCompilingInfo = {
		win_max_n_processes :: !Int,
		win_compiler_process_ids :: !CompilerProcessIds
	};

114 115 116 117 118 119
::	AsyncCompilingInfo = {
		max_n_processes :: !Int,
		compiler_process_ids :: !CompilerProcessIds,
		unknown_finished_processors :: !UnknownFinishedProcessors
	};

120 121 122 123
:: *DriverState
	= DInit !Bool !Project !MTPContinuation
	| DComp !Bool !*DirCache !DriverCompilingInfo !(List String) !DriverStateRecord
	| DGene !(List String) !DriverCodeGenerationInfo !DriverStateRecord
124
	| DQuitCompilers !(List String) !DriverCompilingInfo !DriverStateRecord
125 126 127 128 129 130 131 132 133 134 135 136 137 138
	| DLink !DriverStateRecord
	| DDone

:: *DriverStateRecord =
	{ project	:: !Project
	, continue	:: !MTPContinuation
	, fileinfo	:: !FileInfoCache
	, abccache	:: !*ABCCache
	, libsinfo	:: !StaticLibInfo
	, ok		:: !Bool
	, newpaths	:: !Bool
	, modpaths	:: !List String
	}

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

	#	ps				= PrecompileFase project ps

	#	ps				= showInfo (Level1 "Bring up to date...") ps
146
	#	ps				= ClearCompilerCache` ps
Diederik van Arkel's avatar
Diederik van Arkel committed
147
		ini_step		= DInit force project cleanup
148
	= start ini_step step ps
Diederik van Arkel's avatar
Diederik van Arkel committed
149 150 151 152 153 154 155
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???
156 157 158
			= ps
		= ps

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

174
	cleanup :: !Bool !Bool !Bool !FileInfoCache !StaticLibInfo !(List Modulename) !Project !Bool (!*ABCCache,!GeneralSt) -> *(!*DriverState,!*GeneralSt)
Diederik van Arkel's avatar
Diederik van Arkel committed
175 176 177
	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
178
			# ps			= ClearCompilerCache` ps
Diederik van Arkel's avatar
Diederik van Arkel committed
179 180
			= MakeTheProject False fileinfo libsinfo abccache project cleanup` ps

181
		# ps				= PostlinkFase ok project ps
Diederik van Arkel's avatar
Diederik van Arkel committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195
		
		# 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

196
:: MTPContinuation :== Bool Bool Bool FileInfoCache StaticLibInfo (List Modulename) Project Bool *(*ABCCache,GeneralSt) -> *(*DriverState,*GeneralSt)
Diederik van Arkel's avatar
Diederik van Arkel committed
197

198
MakeTheProject :: !Bool !FileInfoCache !StaticLibInfo !*ABCCache !Project !MTPContinuation !GeneralSt -> (!*DriverState,!*GeneralSt)
Diederik van Arkel's avatar
Diederik van Arkel committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
MakeTheProject force fileinfo libsinfo abccache project continue ps
	# (syspaths,ps)			= getCurrentPaths ps
	# prjpaths				= PR_GetPaths project
	# srcpaths				= AppendLists prjpaths syspaths
	# ((errs,warns,dircache),ps)
							= accFiles (DC_Setup srcpaths) ps
	# ({be_verbose},ps)		= getPrefs ps
	# ps					= HandleDCErrors be_verbose errs warns ps
	# (root,project)		= PR_GetRootPathName project
	# root					= MakeDefPathname root	// avoid double compilation...
	# inidone				= Nil
	# (env_static_libs,ps)	= getCurrentSlibs ps
	# sfiles				= (StrictListToList(Concat (SL_Libs libsinfo) env_static_libs))
	# (err,ps)				= check_exists sfiles ps
	| isJust err
		# line				= Level3 ["Error: Unable to find static library: '" +++ fromJust err +++ "'."]
		# ps				= showInfo line ps
		= continue False False False fileinfo libsinfo Nil project False (abccache, ps)
	# ((errs,slibs),ps)		= accFiles (getLibs sfiles) ps
	| not (isEmpty errs)
		# line				= Level3 ["Error: Failed reading static libraries: '" :errs]
		# ps				= showInfo line ps
		= continue False False False fileinfo libsinfo Nil project False (abccache, ps)
	# slibs					= ListToStrictList slibs
	# libsinfo				= SL_SetDcls slibs libsinfo
	# ps					= showInfo (Level1 "Compiling...") ps
	# rest					= root :! Nil
	# (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 243 244 245
	# ds = 
		{ project	= project
		, continue	= continue
		, fileinfo	= fileinfo
		, abccache	= abccache
		, libsinfo	= libsinfo
		, ok		= True
		, newpaths	= False
		, modpaths	= inidone
		}
	= step False (DComp force dircache compinfo rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
246 247 248 249 250 251 252 253 254 255 256 257 258
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 =
	{ iclModule	:: !String
	, options	:: CompilerOptions
	, slot		:: !Int
	}

259 260 261
:: *DriverCodeGenerationInfo
	= SyncCodeGeneration
	| ASyncCodeGeneration ![(Int,String,String)] !AsyncCompilingInfo // [(busy_process_number,abc_path,obj_path)]
262 263 264 265 266 267 268 269 270 271
	| 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,
272
	wcgp_abc_path :: !Pathname,
273 274 275 276 277 278 279 280 281 282 283 284
	wcgp_obj_path :: !Pathname
   }

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
285

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

294
step True (DComp force dircache compinfo rest ds) ps
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
	# 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
310

311
step intr (DComp force dircache Sync Nil ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
312
	// compile phase finished: remove all modules not (indirectly) imported by main module
313
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
Diederik van Arkel's avatar
Diederik van Arkel committed
314
	# (modpaths,project)	= PR_GetModulenames True IclMod project
315
	# ds					= {ds & modpaths = modpaths, project = project}
Diederik van Arkel's avatar
Diederik van Arkel committed
316
	# ps					= showInfo (Level1 "Generating...") ps
317 318
	# (paths,ds)			= ds!modpaths
	= step intr (DGene paths SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
319

320
step intr (DComp force dircache Sync (next :! rest) ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
321
	// compile phase: check module 'next'
322
	| StringOccurs next ds.modpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
323
		// if already done then skip
324
		= step intr (DComp force dircache Sync rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
325
	# modname					= GetModuleName next
326 327 328 329 330 331
	| isProjLibraryModule modname ds.libsinfo
		// 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
332
	| not ok
333 334 335 336
		# (paths,ds)		= ds!modpaths
		= step intr (DGene paths SyncCodeGeneration ds) ps
	# ds	= {ds & modpaths = next :! ds.modpaths}
	= cont (DComp force dircache compinfo rest ds,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
337

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

349
step intr (DComp force dircache compinfo=:(Pers _) (next :! rest) ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
350
	// compile phase: check module 'next'
351
	| StringOccurs next ds.modpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
352
		// if already done then skip
353
		= step intr (DComp force dircache compinfo rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
354
	# modname					= GetModuleName next
355 356
	| isProjLibraryModule modname ds.libsinfo
		// instead of testing explicitly put libmodules in done <= conflicts with other administration
357
		= step intr (DComp force dircache compinfo rest ds) ps
358 359 360
	# (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
361
	| not ok
362
		# (Pers inf)		= compinfo
363
		# (_,ps)			= ExitCleanCompiler (inf,ps)
364 365 366 367
		# (paths,ds)		= ds!modpaths
		= step intr (DGene paths SyncCodeGeneration ds) ps
	# ds	= {ds & modpaths = next :! ds.modpaths}
	= cont (DComp force dircache compinfo rest ds,ps)
368

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

379
step intr (DComp force dircache (AsyncWin [] {win_compiler_process_ids,win_max_n_processes}) Nil ds) ps
380 381 382 383
	// compile phase finished: remove all modules not (indirectly) imported by main module
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
	# (modpaths,project)	= PR_GetModulenames True IclMod project
	# ds					= {ds & modpaths = modpaths, project = project}
384
	# ps = app_world_instead_of_ps (QuitCleanCompiler True win_compiler_process_ids) ps;
385 386
	# ps					= showInfo (Level1 "Generating...") ps
	# (paths,ds)			= ds!modpaths
387
	= step intr (DGene paths (IF_MACOSX SyncCodeGeneration (ASyncCodeGenerationWin [] win_max_n_processes)) ds) ps
388

389
step intr state=:(DComp force _ (Async _ _) _ _) ps
390 391
	# (state, ps)			= check_completed state ps
	# (state, ps)			= start_compilations state ps
Diederik van Arkel's avatar
Diederik van Arkel committed
392 393
	= cont (state, ps)
	where
394
		check_completed :: !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
395 396
		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
397 398 399 400
				(NoFinishedCompiler,ps)
					-> check_unknow_processors_are_known state ps
				(UnknownFinishedCompiler,ps)
					-> case state of
401
						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
402
							# unknown_finished_processors = add_unknown_finished_processor unknown_finished_processors
403
							# 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
404 405 406 407 408 409 410
							-> 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

411 412 413
		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
414 415 416
				# (state,ps) = handle_completed_processes 0 state ps
					with
						handle_completed_processes process_n state ps
417
							| process_n>=max_n_processes
Diederik van Arkel's avatar
Diederik van Arkel committed
418 419 420 421 422 423 424 425 426 427 428 429 430
								= (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)

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

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

		currently_compiled :: String [CurrentlyCompiled] -> Bool
		currently_compiled next current
480
			=	or [c.iclModule == next	\\ c <- current]
Diederik van Arkel's avatar
Diederik van Arkel committed
481 482 483 484 485 486

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
487
		check_completed :: !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
488 489
		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
490 491 492 493
					(NoFinishedCompiler, ps)
						-> (state, ps)
					(FinishedCompiler completedSlot exitcode, ps)
						#! (state,ps) = process_completed completedSlot exitcode state ps
494 495 496
						-> IF_BATCHBUILD_OR_IDE
								(state,ps)
								(check_completed state ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
497 498 499 500 501
					(UnknownFinishedCompiler,ps)
						-> (state, ps)	// -> doesn't occur on win
		check_completed state ps
			=	(state, ps)

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

521
		start_compilations :: !*DriverState !*GeneralSt -> (!*DriverState,!*GeneralSt)
522 523 524
		start_compilations state=:(DComp force dircache (AsyncWin current {win_max_n_processes,win_compiler_process_ids}) (next :! rest) ds) ps
			| length current >= win_max_n_processes
				# ps = DelayEventLoop ps;			
Diederik van Arkel's avatar
Diederik van Arkel committed
525 526
				= (state, ps)
		// compile phase: check module 'next'
527 528 529
			# next_icl = dcl_to_icl_file_name next;
			| StringOccurs next ds.modpaths || currently_compiled next_icl current
				= 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
Diederik van Arkel's avatar
Diederik van Arkel committed
530 531 532
			# modname = GetModuleName next
			| isProjLibraryModule modname ds.libsinfo
				// instead of testing explicitly put libmodules in done <= conflicts with other administration
533
				= (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
534
			# (ps,dircache,ok,_,rest,compinfo,ds,_)
535
				= 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
536 537 538
			# ds = {ds & ok = ok}
			| not ok
				#! (paths,ds)	= ds!modpaths
539
				= (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
540
			= start_compilations (DComp force dircache compinfo rest ds) ps
541 542
		start_compilations state=:(DComp force dircache (AsyncWin [] _) Nil ds) ps
			= (state, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
543
		start_compilations state ps
544
			# ps = DelayEventLoop ps;
Diederik van Arkel's avatar
Diederik van Arkel committed
545 546 547 548 549
			= (state, ps)

		currently_compiled :: String [CurrentlyCompiled] -> Bool
		currently_compiled next current
			=	or [c.iclModule == next \\ c <- current]
550

551 552 553 554 555 556 557 558 559 560 561 562 563
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

564
step intr (DGene Nil SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
565
	#! ps	= showInfo (Level1 "Linking...") ps
566
	= step intr (DLink ds) ps
567

568 569
step intr (DGene Nil (ASyncCodeGeneration [] {unknown_finished_processors=NoUnknownFinishedProcessors,compiler_process_ids}) ds) ps
	# ps = setCompilerProcessIds compiler_process_ids ps
Diederik van Arkel's avatar
Diederik van Arkel committed
570
	#! ps	= showInfo (Level1 "Linking...") ps
571
	= step intr (DLink ds) ps
572

573 574 575 576
step intr (DGene Nil (ASyncCodeGenerationWin [] _) ds) ps
	#! ps	= showInfo (Level1 "Linking...") ps
	= step intr (DLink ds) ps

577 578 579 580 581 582 583
step intr (DGene (path:!rest) SyncCodeGeneration ds) ps
	| not ds.ok || intr
		# ds = {ds & ok = False}
		= step intr (DLink ds) ps
	# (ps,abccache,fileinfo,gen,abcpath)	= CheckABCOutOfDate False path ds.abccache ds.fileinfo ds.project ps
	# (ps,abccache,fileinfo,project,ok,_)	= GenCodeTheProjectModule gen False CodeGeneration abcpath abccache fileinfo ds.project ps
	# ds = {ds & abccache = abccache, fileinfo = fileinfo, project = project, ok = ok}
Diederik van Arkel's avatar
Diederik van Arkel committed
584
	| not ok
585 586
		= step intr (DLink ds) ps
	= cont (DGene rest SyncCodeGeneration ds, ps)
587

588
step intr (DGene paths (ASyncCodeGeneration busy_processes {max_n_processes,compiler_process_ids,unknown_finished_processors}) ds) ps
589 590
	# (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
591 592
		with
			handle_finished_code_generators busy_processes=:[_:_] unknown_finished_processors project fileinfo ps
593
				= case (CompilePollCompleted compiler_process_ids ps) of
Diederik van Arkel's avatar
Diederik van Arkel committed
594 595 596 597 598 599 600 601 602 603
					(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
604
						# (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
605
							with
606
								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
607 608
									| finished_cg_slot_n==slot
										= (abc_path,obj_path,rest)
609
										# (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
610
										= (abc_path,obj_path,[busy_process:rest])
611
								get_paths_and_remove_process_from_list finished_cg_slot_n []
Diederik van Arkel's avatar
Diederik van Arkel committed
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
									= abort "driver.icl: unknown code generator id"
						| exit_code==0
							# (fileinfo,ps) = accFiles (FI_UpdateObjDate abc_path obj_path fileinfo) ps
							# project = PR_SetCodeGenerated (GetModuleName abc_path) project
							-> 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
633
									# (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
634
										with
635
											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
636 637
												| process_n==slot
													= (abc_path,obj_path,rest)
638
													# (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
639
													= (abc_path,obj_path,[busy_process:rest])
640
											get_paths_and_remove_process_from_list finished_cg_slot_n []
Diederik van Arkel's avatar
Diederik van Arkel committed
641 642 643 644 645 646 647 648
												= 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)
649 650
	# ds = {ds & fileinfo = fileinfo, project = project, ok = ds.ok && ok && not intr}
	| not ds.ok
651 652 653 654
		= 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)
	| (length busy_processes>=max_n_processes || (case paths of Nil -> True ; _ -> False))
		# 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)
655
	# (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
656
		with
657
			start_code_generators :: (List {#Char}) [(Int,{#Char},{#Char})] FileInfoCache *ABCCache !*GeneralSt -> *(.Bool,(List {#Char}),[(Int,{#Char},{#Char})],FileInfoCache,*ABCCache,!*GeneralSt)
Diederik van Arkel's avatar
Diederik van Arkel committed
658 659
			start_code_generators paths=:(path :! rest) busy_processes fileinfo abccache ps
				| length busy_processes>=max_n_processes
660
		 			# ps = DelayEventLoop ps
Diederik van Arkel's avatar
Diederik van Arkel committed
661
					= (True,paths,busy_processes,fileinfo,abccache,ps)
662 663 664
				# (ps,abccache,fileinfo,gen,abc_path)
									= CheckABCOutOfDate False path abccache fileinfo project ps
				# cgo				= PR_GetCodeGenOptions project
665
				# (proc,ps)			= getCurrentProc ps
666
				# ((abccache,fileinfo,info), ps)
667
									= FI_GetFileInfo proc abc_path abccache fileinfo ps
Diederik van Arkel's avatar
Diederik van Arkel committed
668 669
				| not gen
					= start_code_generators rest busy_processes fileinfo abccache ps
670
				# ps				= showInfo (Level2 (
Diederik van Arkel's avatar
Diederik van Arkel committed
671 672 673 674 675 676 677 678 679 680 681 682
													(foldl (+++) ("Generating code for "
																	+++ RemovePath abc_path) [" "+++RemovePath abc_path \\ (_,abc_path,_)<-busy_processes])
													)) ps
				# (startupdir,ps)	= getStup ps
				# (cgen,ps)			= getCurrentCgen ps
				# ao				= PR_GetApplicationOptions project
				# (prefs,ps)		= getPrefs ps
				# defaultCO			= prefs.compopts
				# modname			= GetModuleName abc_path
				# co				= case (PR_GetModuleInfo modname project) of
										Just modinfo	-> modinfo.compilerOptions
										_				-> defaultCO
683
				# timeprofile		= ao.profiling && (not co.neverTimeProfile)
684
				# free_slot			= hd (removeMembers [0..max_n_processes-1] [slot \\ (slot,_,_) <- busy_processes])
Diederik van Arkel's avatar
Diederik van Arkel committed
685

686
				# (res,obj_path,compiler_process_ids,ps) = StartCodeGenerator cgen updateErrorWindow CodeGeneration abc_path free_slot timeprofile cgo proc ao startupdir compiler_process_ids ps
Diederik van Arkel's avatar
Diederik van Arkel committed
687 688 689 690 691
				| not res				
					= (False,rest,busy_processes,fileinfo,abccache,ps)
				# busy_processes	= [(free_slot,abc_path,obj_path):busy_processes]
				= start_code_generators rest busy_processes fileinfo abccache ps
			start_code_generators Nil busy_processes fileinfo abccache ps
692
				# ps = DelayEventLoop ps
Diederik van Arkel's avatar
Diederik van Arkel committed
693
				= (True,Nil,busy_processes,fileinfo,abccache,ps)
694
	# ds = {ds & fileinfo = fileinfo, abccache = abccache, ok = ok}
695
	= 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)
696

697 698 699 700 701 702
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}
703
				# (i,exit_code,ps) = wait_for_finished_code_generator process_handles ps
704 705 706 707 708 709 710 711 712
				| 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])
713
					# (ok,ps) = finish_code_generator finished_process.wcgp_process_handle finished_process.wcgp_scg exit_code updateErrorWindow ps
714 715 716
					| ok
						# module_name = finished_process.wcgp_module_name
						  obj_path = finished_process.wcgp_obj_path
717 718
						  abc_path = finished_process.wcgp_abc_path
						# (fileinfo,ps) = accFiles (FI_UpdateObjDate abc_path obj_path fileinfo) ps
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
						# 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)
	| length busy_processes>=win_max_n_processes || (case paths of Nil -> True ; _ -> False)
		= 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
			start_code_generators :: (List {#Char}) [WinCodeGeneratorProcess] FileInfoCache *ABCCache !*GeneralSt
						   -> *(Bool,(List {#Char}),[WinCodeGeneratorProcess],FileInfoCache,*ABCCache,!*GeneralSt )
			start_code_generators paths=:(mdn:!rest) busy_processes fileinfo abccache ps
				| length busy_processes>=win_max_n_processes
					= (True,paths,busy_processes,fileinfo,abccache,ps)
				# (ps,abccache,fileinfo,gen,abc_path)
									= CheckABCOutOfDate False mdn abccache fileinfo project ps
				# (proc,ps)			= getCurrentProc ps
				# ((abccache,fileinfo,_), ps) = FI_GetFileInfo proc mdn abccache fileinfo ps
				| not gen
					= start_code_generators rest busy_processes fileinfo abccache ps
				# module_name		= GetModuleName mdn
				# 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)
				# obj_path = MakeObjSystemPathname proc mdn
760 761
				# abc_path = MakeABCSystemPathname 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,wcgp_abc_path=abc_path}
762 763 764 765 766 767 768
				# busy_processes = [new_process:busy_processes]
				= start_code_generators rest busy_processes fileinfo abccache ps
			start_code_generators Nil busy_processes fileinfo abccache ps
				= (True,Nil,busy_processes,fileinfo,abccache,ps)
	# ds = {ds & fileinfo = fileinfo, abccache = abccache, ok = ok}
	= cont (DGene paths (ASyncCodeGenerationWin busy_processes win_max_n_processes) ds, ps)

769
step intr (DLink ds=:{ok, newpaths, fileinfo, libsinfo, modpaths, abccache, project, continue}) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
770 771
	//	Check whether executable is out of date and relink it	if required.
	| intr || not ok
772
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
773
	# lo						= PR_GetLinkOptions project
774
	# (prj_path,ps)				= getProjectFilePath ps
Diederik van Arkel's avatar
Diederik van Arkel committed
775 776 777 778 779 780 781 782 783 784 785 786
	# (app_path,ps)				= getStup ps
	# (defpaths,ps)				= getCurrentPaths ps
	# prjpaths					= PR_GetPaths project
	# srcpaths					= AppendLists prjpaths defpaths

	// set up dircache for 'Clean System Files'
	# ((errs,warns,abcPathsCache),ps)	= accFiles (DC_Setup (Map MakeSystemPathname srcpaths)) ps
	// need to handle this differently? Now barfs on paths without Clean System File subdirs
	// maybe use variant DC_Setup which ignores nonexistent CSF-dirs...
	# ({be_verbose},ps)			= getPrefs ps
	# ps						= HandleDCErrors be_verbose errs warns ps
	# (ok,full_sys0,_,abcPathsCache) = DC_Search (MakeABCPathname System) abcPathsCache
787
	# full_sys					= full_sys0 +++ DirSeparatorString +++ (MakeABCPathname System)
Diederik van Arkel's avatar
Diederik van Arkel committed
788 789 790 791 792
	# full_sys`					= MakeImpPathname full_sys
	
	# ao						= PR_GetApplicationOptions project
	// possibly patch _system to correct profiling settings...

793
	# (tp,ps)					= getCurrentProc ps
Diederik van Arkel's avatar
Diederik van Arkel committed
794 795 796 797 798 799 800 801
	# ((abccache,fileinfo,modinfo),ps)
								= FI_GetFileInfo tp  full_sys` abccache fileinfo ps
	
	# wantstp					= ao.profiling //&& (not co.neverTimeProfile)
	# compile					= /*mp <> info.abcOptions.abcMemoryProfile ||*/ wantstp <> modinfo.abcOptions.abcTimeProfile
	# lines						= if (be_verbose && compile)
									(Level3 ["["+++(MakeABCPathname System)+++",]: compiled with different options"])
									(Level3 [])
802
	# ps						= verboseInfo be_verbose lines ps
Diederik van Arkel's avatar
Diederik van Arkel committed
803 804 805 806 807
	# (version,ps)				= getCurrentVers ps
	# (patched, ps)				= accFiles (PatchSystemABC version compile full_sys /*ao.memoryProfiling*/ wantstp) ps
	| not patched
		# line					= Level3 ["Error: ["+++(MakeABCPathname System)+++",]: could not be patched."]
		# ps					= showInfo line ps
808 809
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
	# ((abcdate,fileinfo), ps)	= accFiles (FI_UpdateAbcDate full_sys` full_sys wantstp fileinfo) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
810 811 812 813 814 815
	# (ps,abccache,fileinfo,genabc,abcpath)
								// check _system module out of date
								= CheckABCOutOfDate True full_sys` abccache fileinfo project ps
	# (ps,abccache,fileinfo,project,ok,system_obj_path)
								// if out of date regenerate
								= GenCodeTheProjectModule genabc True CodeGeneration abcpath abccache fileinfo project ps
816
	# (sys_date, ps)			= accFiles (FModified full_sys) ps
817
	# sys_obj					= full_sys0 +++ DirSeparatorString +++ (MakeObjPathname tp System)
818 819
	# (sys_obj_date,ps)			= accFiles (FModified sys_obj) ps
	# sys_obj_date_time			= DATEtoDateTime sys_obj_date
Diederik van Arkel's avatar
Diederik van Arkel committed
820
	# (abcPathsCache,ps)		= case genabc of
Diederik van Arkel's avatar
Diederik van Arkel committed
821
									True
822
										-> (DC_Update ((MakeObjPathname tp System),full_sys0,sys_obj_date_time) abcPathsCache,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
823
												// need to check if line above actually works now...
Diederik van Arkel's avatar
Diederik van Arkel committed
824 825
									False
										-> (abcPathsCache,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
826
	| not ok
827
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
828

829 830 831 832 833 834 835
	# ((ok,_,_,_,sys_objs,sys_libs,abccache),ps)
								= accFiles (ParseABCDependencies` abcpath sys_date abccache) ps
	| not ok
		# line					= Level3 ["Error: ["+++(MakeABCPathname System)+++",]: could not be analysed."]
		# ps					= showInfo line ps
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
	
Diederik van Arkel's avatar
Diederik van Arkel committed
836
	# execpath					= PR_GetExecPath project
837
	# prj_path` = PR_GetRootDir project
Diederik van Arkel's avatar
Diederik van Arkel committed
838 839 840
	# execpath					= fulPath app_path prj_path` execpath
	# ps						= showInfo (Level2 ("Linking '"