PmDriver.icl 71.3 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1
2
3
4
5
6
7
8
9
implementation module PmDriver

import StdArray, StdBool, StdList, StdMisc, StdEnum
import StdPSt, StdSystem, StdPStClass, StdTimer
import StdWindow

import UtilNewlinesFile, UtilIO

import IdeState
10

11
from typewin import updateTypeWindow, tw_safe_close, class Typer, :: TypeWinInfo
Diederik van Arkel's avatar
Diederik van Arkel committed
12
from typeatt import typeWinKeyboard, typeWinMouse
13
from errwin  import updateErrorWindow, ew_safe_close
Diederik van Arkel's avatar
Diederik van Arkel committed
14
from messwin import showInfo, :: InfoMessage(..)
Diederik van Arkel's avatar
Diederik van Arkel committed
15
from projwin import pm_update_project_window
16
17
18
19
20

import PmCleanSystem
import PmPath
import PmProject
from PmDialogues import doPathsDialog
21
import PmAbcMagic
Diederik van Arkel's avatar
Diederik van Arkel committed
22
23
import PmFileInfo
import PmDirCache
24

Diederik van Arkel's avatar
Diederik van Arkel committed
25
import interrupt,Platform
26
from Directory import :: DateTime(..), :: Date`(..), :: Time`(..)
Diederik van Arkel's avatar
Diederik van Arkel committed
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

//from dodebug import trace_n`
trace_n _ g :== g

//--

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

:: SetMadeProjectFun :== (Bool -> Bool -> Project -> (PSt General) -> PSt General)

//	Compile /Check Syntax of the designated module
CompileProjectModule ::	!CompileOrCheckSyntax !Pathname !Project !SetMadeProjectFun !*(PSt General) -> *(PSt General)
CompileProjectModule compilerOrCheckSyntax path project setproject ps
74
	#! (_,ps)				= ClearCompilerCache ps
Diederik van Arkel's avatar
Diederik van Arkel committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	# (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,_,_)
							= CompileTheProjectModule True compilerOrCheckSyntax path fileinfo dircache abccache project ps
	# ps					= setABCCache abccache ps
	# ps					= setFICache fileinfo ps
	= setproject ok newpaths project ps

GenAsmProjectModule :: !.Pathname !Project !SetMadeProjectFun !*(PSt General) -> *(PSt *General)
GenAsmProjectModule path project setproject ps
92
	#! (_,ps)				= ClearCompilerCache ps
Diederik van Arkel's avatar
Diederik van Arkel committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
	# (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,_)
							= CompileTheProjectModule True Compilation path fileinfo dircache abccache project ps
	| 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

114
:: CleanupCont :== Pathname Bool Bool *(PSt *General) -> *(PSt *General)
Diederik van Arkel's avatar
Diederik van Arkel committed
115
116
117
118
119
120
121
122
123
124
125

BringProjectUptoDate :: !Bool CleanupCont !*(PSt *General) -> *PSt *General
BringProjectUptoDate force continuation ps
	#  (project,ps)		= getProject ps

	#	ps				= ew_safe_close ps							// close error window
	#	ps				= tw_safe_close ps							// close types window

	#	ps				= PrecompileFase project ps

	#	ps				= showInfo (Level1 "Bring up to date...") ps
126
	#! (_,ps)			= ClearCompilerCache ps
Diederik van Arkel's avatar
Diederik van Arkel committed
127
128

	#!	(intr_info,ps) 	= getInterrupt ps
Diederik van Arkel's avatar
Diederik van Arkel committed
129
//		(interact,ps) 	= getInteract ps
Diederik van Arkel's avatar
Diederik van Arkel committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
		ini_step		= DInit force project cleanup
	#	ps				= StartIntr intr_info ini_step step ps
	= ps
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???
			= trace_n ("PRE",ok,ec) ps
		= trace_n "NO-PRE" ps
	
	PostlinkFase project ps
		# (postlink,project)	= PR_GetPostlink project
		| isJust postlink
			# ps				= showInfo (Level1 "Postlink...") ps
			# (ok,ec,ps)		= Execute` (fromJust postlink) ps
			= ps
		= ps
	
	cleanup :: !Bool !Bool !Bool !FileInfoCache !StaticLibInfo !(List Modulename) !Project !Bool (!*ABCCache,!(PSt *General)) -> *(!*DriverState,!PSt *General)
	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
155
			# (_,ps)		= ClearCompilerCache ps
Diederik van Arkel's avatar
Diederik van Arkel committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
			= MakeTheProject False fileinfo libsinfo abccache project cleanup` ps

		# ps				= PostlinkFase project ps
		
		# 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

Diederik van Arkel's avatar
Diederik van Arkel committed
173
:: MTPContinuation :== Bool Bool Bool FileInfoCache StaticLibInfo (List Modulename) Project Bool *(*ABCCache,(PSt *General)) -> *(*DriverState,PSt *General)
Diederik van Arkel's avatar
Diederik van Arkel committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

MakeTheProject :: !Bool !FileInfoCache !StaticLibInfo !*ABCCache !Project !MTPContinuation !(PSt General) -> (!*DriverState,!PSt General)
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
	# compinfo = case method of
				CompileSync			-> Sync
206
207
208
//				(CompileAsync cmax)	-> PlatformDependant
//										(AsyncWin cmax [])								// win
//										(Async [] cmax 0 NoUnknownFinishedProcessors)	// mac
Diederik van Arkel's avatar
Diederik van Arkel committed
209
				CompilePers			-> Pers InitCompilingInfo
210
211
212
213
214
215
216
217
218
219
220
	# 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
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
	}

//--

cont :: !*(.a,*(PSt *General)) -> *(.a,*(PSt *General));
cont (ls,ps)
	# (intr_info,ps) 	= getInterrupt ps
	# ps				= ContIntr intr_info ps
	= (ls,ps)

stop :: !*(.a,*(PSt *General)) -> *(.a,*(PSt *General));
stop (ls,ps)
	# (intr_info,ps) 	= getInterrupt ps
	# ps				= StopIntr intr_info ps
	= (ls,ps)

Diederik van Arkel's avatar
Diederik van Arkel committed
248
step :: !Bool !*DriverState !*(PSt General) -> (!*DriverState,!*(PSt General))
Diederik van Arkel's avatar
Diederik van Arkel committed
249
step intr (DInit force project setproject) ps
250
//	# ps				= showInfo (Level1 "Make the project...") ps
Diederik van Arkel's avatar
Diederik van Arkel committed
251
252
253
254
255
	# libsinfo			= PR_GetStaticLibsInfo project
	# (abccache,ps)		= getABCCache ps
	# (fileinfo,ps)		= getFICache` ps
	= MakeTheProject force fileinfo libsinfo abccache project setproject ps

256
257
258
step True (DComp force dircache (Pers inf) rest ds) ps
	# ds			= {ds & ok = False}
	# (paths,ds)	= ds!modpaths
259
260
	// compile phase finished: kill clean compiler
	# (_,ps)				= ExitCleanCompiler (inf,ps)
261
	= step True (DGene paths SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
262

263
step True (DComp force dircache compinfo rest ds) ps
264
	// need async cocl shootdown as well..
265
266
267
	# ds			= {ds & ok = False}
	# (paths,ds)	= ds!modpaths
	= step True (DGene paths SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
268

269
step intr (DComp force dircache Sync Nil ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
270
	// compile phase finished: remove all modules not (indirectly) imported by main module
271
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
Diederik van Arkel's avatar
Diederik van Arkel committed
272
	# (modpaths,project)	= PR_GetModulenames True IclMod project
273
	# ds					= {ds & modpaths = modpaths, project = project}
Diederik van Arkel's avatar
Diederik van Arkel committed
274
	# ps					= showInfo (Level1 "Generating...") ps
275
276
	# (paths,ds)			= ds!modpaths
	= step intr (DGene paths SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
277

278
step intr (DComp force dircache Sync (next :! rest) ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
279
	// compile phase: check module 'next'
280
	| StringOccurs next ds.modpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
281
		// if already done then skip
282
		= step intr (DComp force dircache Sync rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
283
	# modname					= GetModuleName next
284
285
286
287
288
289
	| 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
290
	| not ok
291
292
293
294
		# (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
295

296
step intr (DComp force dircache (Pers inf) Nil ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
297
298
299
	// compile phase finished: kill clean compiler
	# (_,ps)				= ExitCleanCompiler (inf,ps)
	// compile phase finished: remove all modules not (indirectly) imported by main module
300
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
Diederik van Arkel's avatar
Diederik van Arkel committed
301
	# (modpaths,project)	= PR_GetModulenames True IclMod project
302
	# ds					= {ds & modpaths = modpaths, project = project}
Diederik van Arkel's avatar
Diederik van Arkel committed
303
304
	# ps					= showInfo (Level1 "Generating...") ps
//XXX	= step intr (DGene True newpaths fileinfo libsinfo modpaths modpaths abccache project setproject) ps
305
306
	# (paths,ds)			= ds!modpaths
	= step intr (DGene paths SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
307

308
step intr (DComp force dircache compinfo=:(Pers _) (next :! rest) ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
309
	// compile phase: check module 'next'
310
311
	# ps = trace_n ("comp step",next) ps
	| StringOccurs next ds.modpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
312
		// if already done then skip
313
		= step intr (DComp force dircache compinfo rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
314
	# modname					= GetModuleName next
315
316
317
318
319
320
321
	| 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 = trace_n ("update",next) ps
	# (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
322
	| not ok
323
324
325
326
327
328
329
330
		# (Pers inf)		= compinfo
		# (_,ps)			= trace_n "exit compiler!" ExitCleanCompiler (inf,ps)
		# (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)
/*
step intr (DComp force dircache (Async [] max_n_processes n_used_processors NoUnknownFinishedProcessors) Nil ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
331
	// compile phase finished: remove all modules not (indirectly) imported by main module
332
	# project				= PR_SetBuilt ds.modpaths ds.project	// removes unused modules
Diederik van Arkel's avatar
Diederik van Arkel committed
333
	# (modpaths,project)	= PR_GetModulenames True IclMod project
334
335
	# ds					= {ds & modpaths = modpaths, project = project}
	# (os_error,ps)			= ClearCompilerCaches n_used_processors ps;
Diederik van Arkel's avatar
Diederik van Arkel committed
336
	# ps					= showInfo (Level1 "Generating...") ps
337
338
	# (paths,ds)			= ds!modpaths
	= step intr (DGene paths (ASyncCodeGeneration [] max_n_processes NoUnknownFinishedProcessors) ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
339

340
341
342
343
344
345
346
347
348
349
350
step intr (DComp force dircache (AsyncWin _ []) Nil ds) ps
	// 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}
//	# (os_error,ps)			= ClearCompilerCaches n_used_processors ps;
	# ps					= showInfo (Level1 "Generating...") ps
	# (paths,ds)			= ds!modpaths
	= step intr (DGene paths SyncCodeGeneration ds) ps

step intr state=:(DComp force dircache compinfo=:(Async _ _ _ _) rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
351
352
353
354
355
356
357
	# ps					= traceInfo (Level3 ["check_completed..."]) ps
	# (state, ps) = check_completed state ps
	# ps					= traceInfo (Level3 ["start_compilations..."]) ps
	# (state, ps) = start_compilations state ps
	= cont (state, ps)
	where
		check_completed :: !*DriverState !*(PSt General) -> !(!*DriverState,!*PSt General)
358
		check_completed state=:(DComp _ _ (Async current=:[_:_] cmax _ _) _ _)  ps
Diederik van Arkel's avatar
Diederik van Arkel committed
359
360
361
362
363
			= case (CompilePollCompleted ps) of
				(NoFinishedCompiler,ps)
					-> check_unknow_processors_are_known state ps
				(UnknownFinishedCompiler,ps)
					-> case state of
364
						DComp force dircache (Async current cmax n_used_processors unknown_finished_processors) todo ds
Diederik van Arkel's avatar
Diederik van Arkel committed
365
							# unknown_finished_processors = add_unknown_finished_processor unknown_finished_processors
366
							# state = DComp force dircache (Async current cmax n_used_processors unknown_finished_processors) todo ds
Diederik van Arkel's avatar
Diederik van Arkel committed
367
368
369
370
371
372
373
374
							-> check_completed state ps
				(FinishedCompiler completedSlot exitcode,ps)
					# ps = traceInfo (Level3 ["process_completed...",toString completedSlot,toString 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

375
		check_unknow_processors_are_known (DComp force dircache (Async current cmax n_used_processors (UnknownFinishedProcessors n_unknown_finished_processors known_finished_processors)) todo ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
376
			| n_unknown_finished_processors+length known_finished_processors>=cmax
377
				# state = DComp force dircache (Async current cmax n_used_processors NoUnknownFinishedProcessors) todo ds
Diederik van Arkel's avatar
Diederik van Arkel committed
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
				# (state,ps) = handle_completed_processes 0 state ps
					with
						handle_completed_processes process_n state ps
							| process_n>=cmax
								= (state,ps)
							| isMember process_n known_finished_processors
								= handle_completed_processes (process_n+1) state ps
								# (_,ps) = SendRepeatResult process_n ps
								/*
								# exitcode = 1
								# ps = traceInfo (Level3 ["process_completed...",toString process_n,toString exitcode]) ps
								#! (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)

396
397
398
399
400
401
402
403
404
		process_completed :: !Int !Int !*DriverState !*(PSt General) -> !(!*DriverState,!*PSt General)
		process_completed completedSlot exitcode (DComp force dircache (Async current cmax n_used_processors unknown_finished_processors) todo ds) ps
			# (completed, current)			= removeFromCurrent completedSlot current
			# unknown_finished_processors	= remove_from_unknown_finished_processors completedSlot unknown_finished_processors
			# (startupdir,ps)				= getStup ps
			  typewin						= updateTypeWindow (GetModuleName completed.iclModule) [typeWinKeyboard, typeWinMouse]
			# ccstring						= "dummy ccstring for now.."
			# (ps,abcpath,res)				= CompileHandleExitCode exitcode ccstring startupdir completedSlot updateErrorWindow typewin 
												completed.iclModule completed.options.listTypes ps // types param
Diederik van Arkel's avatar
Diederik van Arkel committed
405
			# (ps,fileinfo,dircache,abccache,project,ok,newpaths`,_,deps)
406
407
											= ProcessCompilerMsg Compilation completed.options completed.iclModule abcpath res ds.fileinfo dircache ds.abccache ds.project ps
			# ds							= {ds & newpaths = ds.newpaths || newpaths`, fileinfo = fileinfo, abccache = abccache, project = project, ok = ok}
Diederik van Arkel's avatar
Diederik van Arkel committed
408
			| ok
409
410
				# ds						= {ds & modpaths = completed.iclModule :! ds.modpaths}
				= (DComp force dircache (Async current cmax n_used_processors unknown_finished_processors) (Concat deps todo) ds, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
411
412
			// not ok
				# (os_error,ps) = ClearCompilerCaches n_used_processors ps;
413
414
				# (paths,ds)	= ds!modpaths
				= (DGene paths SyncCodeGeneration ds, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
415
416
417
418
419
420
421
422
423
424
425
426
			where
				removeFromCurrent :: Int [CurrentlyCompiled] -> (CurrentlyCompiled, [CurrentlyCompiled])
				removeFromCurrent _ []
					=	abort "driver.icl: unknown threadId"
				removeFromCurrent completedSlot [current=:{slot} : rest]
					| completedSlot == slot
						=	(current, rest)
					// otherwise
						# (completed, rest) = removeFromCurrent completedSlot rest
						= (completed, [current : rest])

		start_compilations :: !*DriverState !*(PSt General) -> (!*DriverState,!*PSt General)
427
428
		start_compilations state=:(DComp force dircache (Async current cmax n_used_processors unknown_finished_processors) (next :! rest) ds) ps
			// all threads used?
Diederik van Arkel's avatar
Diederik van Arkel committed
429
430
			| length current >= cmax
				= (state, ps)
431
432
433
			// compile phase: check module 'next'
			| StringOccurs next ds.modpaths || currently_compiled next current
				= start_compilations (DComp force dircache (Async current cmax n_used_processors unknown_finished_processors) rest ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
434
			# modname = GetModuleName next
435
436
437
438
439
440
			| isProjLibraryModule modname ds.libsinfo
				// instead of testing explicitly put libmodules in done <= conflicts with other administration
				= (DComp force dircache (Async current cmax n_used_processors unknown_finished_processors) rest ds, ps)
			# (ps,dircache,ok,_,rest,compinfo,ds,_)
				= UpdateDependencies force next rest (Async current cmax n_used_processors unknown_finished_processors) dircache ds ps
			# ds = {ds & ok = ok}
Diederik van Arkel's avatar
Diederik van Arkel committed
441
442
			| not ok
				# (os_error,ps) = ClearCompilerCaches n_used_processors ps;
443
444
445
				#! (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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
		start_compilations state ps
//			# ps = traceInfo (Level3 ["start_compilations no next..."]) ps
			= (state, ps)

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

step intr state=:(DComp force dircache compinfo=:(AsyncWin _ _) rest ds) ps
	# ps					= traceInfo (Level3 ["check_completed..."]) ps
	# (state, ps) = check_completed state ps
	# ps					= traceInfo (Level3 ["start_compilations..."]) ps
	# (state, ps) = start_compilations state ps
	= cont (state, ps)
	where
		check_completed :: !*DriverState !*(PSt General) -> !(!*DriverState,!*PSt General)
462
		check_completed state=:(DComp _ _ (AsyncWin cmax current=:[_:_]) _ _)  ps
Diederik van Arkel's avatar
Diederik van Arkel committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
			=	case (CompilePollCompleted ps) of
					(NoFinishedCompiler, ps)
						-> (state, ps)
					(FinishedCompiler completedSlot exitcode, ps)
						#! (state,ps) = process_completed completedSlot exitcode state ps
						-> check_completed state ps
					(UnknownFinishedCompiler,ps)
						-> (state, ps)	// -> doesn't occur on win
		check_completed state ps
			=	(state, ps)

		process_completed :: !Int !Int !*DriverState !*(PSt General) -> !(!*DriverState,!*PSt General)
		process_completed completedSlot exitcode (DComp force dircache (AsyncWin cmax current) todo ds) ps
			# (completed, current)	= removeFromCurrent completedSlot current
			# (startupdir,ps)		= getStup ps
			  typewin				= updateTypeWindow (GetModuleName completed.iclModule) [typeWinKeyboard, typeWinMouse]
			# ccstring				= "dummy ccstring for now.."
			# (ps,abcpath,res)		= CompileHandleExitCode exitcode ccstring startupdir completedSlot updateErrorWindow typewin 
										completed.iclModule completed.options.listTypes ps // types param
			# (ps,fileinfo,dircache,abccache,project,ok,newpaths`,_,deps)
									= ProcessCompilerMsg Compilation completed.options completed.iclModule abcpath res ds.fileinfo dircache ds.abccache ds.project ps
			# ds					= {ds & newpaths = ds.newpaths || newpaths`, fileinfo = fileinfo, abccache = abccache, project = project, ok = ok}
			| ok
				# ds						= {ds & modpaths = completed.iclModule :! ds.modpaths}
				= (DComp force dircache (AsyncWin cmax current) (Concat deps todo) ds, ps)
			// not ok
				# (paths,ds)	= ds!modpaths
				= (DGene paths SyncCodeGeneration ds, ps)
			where
				removeFromCurrent :: Int [CurrentlyCompiled] -> (CurrentlyCompiled, [CurrentlyCompiled])
				removeFromCurrent _ []
					=	abort "driver.icl: unknown threadId"
				removeFromCurrent completedSlot [current=:{slot} : rest]
					| completedSlot == slot
						=	(current, rest)
					// otherwise
						# (completed, rest) = removeFromCurrent completedSlot rest
						= (completed, [current : rest])

		start_compilations :: !*DriverState !*(PSt General) -> (!*DriverState,!*PSt General)
		start_compilations state=:(DComp force dircache (AsyncWin cmax current) (next :! rest) ds) ps
			| length current >= cmax
				= (state, ps)
		// compile phase: check module 'next'
			| StringOccurs next ds.modpaths || currently_compiled next current
				= start_compilations (DComp force dircache (AsyncWin cmax current) rest ds) ps
			# modname = GetModuleName next
			| isProjLibraryModule modname ds.libsinfo
				// instead of testing explicitly put libmodules in done <= conflicts with other administration
				= (DComp force dircache (AsyncWin cmax current) rest ds, ps)
			# (ps,dircache,ok,_,rest,compinfo,ds,_)
				= UpdateDependencies force next rest (AsyncWin cmax current) dircache ds ps
			# ds = {ds & ok = ok}
			| not ok
				#! (paths,ds)	= ds!modpaths
				= (DGene paths SyncCodeGeneration ds, ps)
			= start_compilations (DComp force dircache compinfo rest ds) ps
		start_compilations state ps
			= (state, ps)

		currently_compiled :: String [CurrentlyCompiled] -> Bool
		currently_compiled next current
			=	or [c.iclModule == next \\ c <- current]
*/
527
step intr (DGene Nil SyncCodeGeneration ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
528
	#! ps	= showInfo (Level1 "Linking...") ps
529
530
531
	= step intr (DLink ds) ps
/*
step intr (DGene Nil (ASyncCodeGeneration [] _ NoUnknownFinishedProcessors) ds) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
532
	#! ps	= showInfo (Level1 "Linking...") ps
533
534
535
536
537
538
539
540
541
	= step intr (DLink ds) ps
*/
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
542
	| not ok
543
544
545
546
547
548
		= step intr (DLink ds) ps
	= cont (DGene rest SyncCodeGeneration ds, ps)
/*
step intr (DGene paths (ASyncCodeGeneration busy_processes max_n_processes unknown_finished_processors) ds) ps
	# (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
549
550
551
552
553
554
555
556
557
558
559
560
561
		with
			handle_finished_code_generators busy_processes=:[_:_] unknown_finished_processors project fileinfo ps
				= case (CompilePollCompleted ps) of
					(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
562
						# (abc_path,obj_path,busy_processes) = get_paths_and_remove_process_from_list busy_processes
Diederik van Arkel's avatar
Diederik van Arkel committed
563
							with
564
								get_paths_and_remove_process_from_list [busy_process=:(slot,abc_path,obj_path) : rest]
Diederik van Arkel's avatar
Diederik van Arkel committed
565
566
									| finished_cg_slot_n==slot
										= (abc_path,obj_path,rest)
567
										# (abc_path,obj_path,rest) = get_paths_and_remove_process_from_list rest
Diederik van Arkel's avatar
Diederik van Arkel committed
568
										= (abc_path,obj_path,[busy_process:rest])
569
								get_paths_and_remove_process_from_list []
Diederik van Arkel's avatar
Diederik van Arkel committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
									= 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
591
									# (abc_path,obj_path,busy_processes) = get_paths_and_remove_process_from_list busy_processes
Diederik van Arkel's avatar
Diederik van Arkel committed
592
										with
593
											get_paths_and_remove_process_from_list [busy_process=:(slot,abc_path,obj_path) : rest]
Diederik van Arkel's avatar
Diederik van Arkel committed
594
595
												| process_n==slot
													= (abc_path,obj_path,rest)
596
													# (abc_path,obj_path,rest) = get_paths_and_remove_process_from_list rest
Diederik van Arkel's avatar
Diederik van Arkel committed
597
													= (abc_path,obj_path,[busy_process:rest])
598
											get_paths_and_remove_process_from_list []
Diederik van Arkel's avatar
Diederik van Arkel committed
599
600
601
602
603
604
605
606
												= 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)
607
608
609
	# ds = {ds & fileinfo = fileinfo, project = project, ok = ds.ok && ok && not intr}
	| not ds.ok
		= cont (DGene paths (ASyncCodeGeneration busy_processes max_n_processes unknown_finished_processors) ds,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
610
	| length busy_processes>=max_n_processes || (case paths of Nil -> True ; _ -> False)
611
612
		= cont (DGene paths (ASyncCodeGeneration busy_processes max_n_processes unknown_finished_processors) ds,ps)
	# (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
613
614
615
616
		with
			start_code_generators paths=:(path :! rest) busy_processes fileinfo abccache ps
				| length busy_processes>=max_n_processes
					= (True,paths,busy_processes,fileinfo,abccache,ps)
617
618
619
620
621
				# (ps,abccache,fileinfo,gen,abc_path)
									= CheckABCOutOfDate False path abccache fileinfo project ps
				# cgo				= PR_GetCodeGenOptions project
				# ((abccache,fileinfo,info), ps)
									= FI_GetFileInfo cgo.tp abc_path abccache fileinfo ps
Diederik van Arkel's avatar
Diederik van Arkel committed
622
623
				| not gen
					= start_code_generators rest busy_processes fileinfo abccache ps
624
				# ps				= showInfo (Level2 (
Diederik van Arkel's avatar
Diederik van Arkel committed
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
													(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
				# tp				= ao.profiling && (not co.neverTimeProfile)
				# free_slot			= hd (removeMembers [0..max_n_processes-1] [slot \\ (slot,_,_) <- busy_processes])				

//				# ps  = trace ("code generator started "+++toString free_slot+++"\n") ps
//				# ps  = trace ("s "+++toString free_slot+++" ") ps

643
				# (res,obj_path,ps)	= StartCodeGenerator cgen updateErrorWindow CodeGeneration abc_path free_slot tp cgo ao startupdir ps
Diederik van Arkel's avatar
Diederik van Arkel committed
644
645
646
647
648
649
				| 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
				= (True,Nil,busy_processes,fileinfo,abccache,ps)
650
651
652
653
	# ds = {ds & fileinfo = fileinfo, abccache = abccache, ok = ok}
	= cont (DGene paths (ASyncCodeGeneration busy_processes max_n_processes unknown_finished_processors) ds, ps)
*/
step intr (DLink ds=:{ok, newpaths, fileinfo, libsinfo, modpaths, abccache, project, continue}) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
654
655
	//	Check whether executable is out of date and relink it	if required.
	| intr || not ok
656
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
	# lo						= PR_GetLinkOptions project
	# (prj_path,ps)				= getPath ps
	# (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
	# full_sys					= full_sys0 +++ {dirseparator} +++ (MakeABCPathname System)
	# full_sys`					= MakeImpPathname full_sys
	
	# ao						= PR_GetApplicationOptions project
	// possibly patch _system to correct profiling settings...

	# tp						= PR_GetProcessor project
	# ((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 [])
686
	# ps						= verboseInfo be_verbose lines ps
Diederik van Arkel's avatar
Diederik van Arkel committed
687
688
689
690
691
	# (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
692
693
		= 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
694
695
696
697
698
699
	# (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
700
701
702
703
	# (sys_date, ps)			= accFiles (FModified full_sys) ps
	# sys_obj					= full_sys0 +++ {dirseparator} +++ (MakeObjPathname tp System)
	# (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
704
	# (abcPathsCache,ps)		= case genabc of
Diederik van Arkel's avatar
Diederik van Arkel committed
705
									True
706
										-> (DC_Update ((MakeObjPathname tp System),full_sys0,sys_obj_date_time) abcPathsCache,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
707
												// need to check if line above actually works now...
Diederik van Arkel's avatar
Diederik van Arkel committed
708
709
									False
										-> (abcPathsCache,ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
710
	| not ok
711
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
712

713
714
715
716
717
718
719
	# ((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
720
721
722
723
724
725
	# prj_path`					= RemoveFilename prj_path
	# execpath					= PR_GetExecPath project
	# execpath					= fulPath app_path prj_path` execpath
	# ps						= showInfo (Level2 ("Linking '" +++ RemovePath execpath +++ "'")) ps
	
	// runtime objects and dynamic libs
726
727
	# stdl						= Concat sys_libs (standardStaticLibraries lo.method)
	# stdo						= Concat sys_objs (standardObjectFiles ao.stack_traces ao.profiling)
Diederik van Arkel's avatar
Diederik van Arkel committed
728
729
730
731
732
733
734
735
736
737
738
	# (stdoOk,ofiles,abcPathsCache)
								= case ao.standard_rte of
									True	-> GetPathNames stdo Nil abcPathsCache
									False	-> (True,Nil,abcPathsCache)
	# (stdlOk,lfiles,abcPathsCache)
								= case ao.standard_rte of
									True	-> GetPathNames stdl Nil abcPathsCache
									False	-> (True,Nil,abcPathsCache)
	| not stdoOk
		# line					= Level3 ["Link error: File: '" +++ (Head ofiles) +++ "' not found."]
		# ps					= showInfo line ps
739
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
740
741
742
	| not stdlOk
		# line					= Level3 ["Link error: File: '" +++ (Head lfiles) +++ "' not found."]
		# ps					= showInfo line ps
743
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
744
745
746
747

	// environment objects and dynamic libs
	# (deflibs,ps)				= getCurrentDlibs ps
	# (defobjs,ps)				= getCurrentObjts ps
748
749
	# ofiles					= Concat defobjs ofiles
	# lfiles					= Concat deflibs lfiles
Diederik van Arkel's avatar
Diederik van Arkel committed
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/* NO: these are stored with full path so need different approach???
	# (defobjsOk,defobjs,abcPathsCache)
								= GetPathNames defobjs Nil abcPathsCache
	# (deflibsOk,deflibs,abcPathsCache)
								= GetPathNames deflibs Nil abcPathsCache
	| not defobjsOk
		# line					= Level3 ["Link error: File: '" +++ (Head defobjs) +++ "' not found."]
		# ps					= showInfo line ps
		= continue False newpaths False fileinfo libsinfo abccache modpaths project intr ps
	| not deflibsOk
		# line					= Level3 ["Link error: File: '" +++ (Head deflibs) +++ "' not found."]
		# ps					= showInfo line ps
		= continue False newpaths False fileinfo libsinfo abccache modpaths project intr ps
*/

	// clean modules
	# (clmodpaths,fileinfo)		= FI_GetCleanModules system_obj_path libsinfo fileinfo
767
768
769
770
	// why couldn't we use ds.modpaths above??? No we need to do trickery to ensure main module is first!
	# (rootpath,project)		= PR_GetRootPathName project
	# rootpath					= MakeObjSystemPathname tp rootpath 
	# clmodpaths				= RemoveStringFromList rootpath clmodpaths
Diederik van Arkel's avatar
Diederik van Arkel committed
771
	# ofiles` = ofiles
772
773
	# ofiles					= rootpath :! ofiles
	
Diederik van Arkel's avatar
Diederik van Arkel committed
774
	# ofiles					= Reverse2 clmodpaths ofiles
Diederik van Arkel's avatar
Diederik van Arkel committed
775
776
777
778

	// module imported objects and dynamic libs
	# abcLinkInfo				= PR_GetABCLinkInfo project
	# (objPathsOk,ofiles,abcPathsCache)
779
								= GetPathNames abcLinkInfo.linkObjFileNames ofiles abcPathsCache
Diederik van Arkel's avatar
Diederik van Arkel committed
780
	# (_,ofiles`,abcPathsCache) = GetPathNames abcLinkInfo.linkObjFileNames ofiles` abcPathsCache
Diederik van Arkel's avatar
Diederik van Arkel committed
781
782
783
784
785
	# (libPathsOk,lfiles,abcPathsCache)
								= GetPathNames abcLinkInfo.linkLibraryNames lfiles abcPathsCache
	| not objPathsOk
		# line					= Level3 ["Link error: File: '" +++ (Head ofiles) +++ "' not found."]
		# ps					= showInfo line ps
786
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
787
788
789
	| not libPathsOk
		# line					= Level3 ["Link error: File: '" +++ (Head lfiles) +++ "' not found."]
		# ps					= showInfo line ps
790
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
791
792
793
794
795
796
797
798
799
800

	// project objects and dynamic libs
/* full paths again...
	# (loobjsOk,ofiles,abcPathsCache)
								= GetPathNames lo.extraObjectModules ofiles abcPathsCache
	# (lolibsOk,lfiles,_)
								= GetPathNames lo.libraries lfiles abcPathsCache
*/
	# loobjsOk					= True
	# lolibsOk					= True
801
802
	# ofiles					= Concat lo.extraObjectModules ofiles
	# ofiles`					= Concat lo.extraObjectModules ofiles`
Diederik van Arkel's avatar
Diederik van Arkel committed
803
804
805
806
807
	# lfiles					= Concat lo.libraries lfiles
	
	| not loobjsOk
		# line					= Level3 ["Link error: File: '" +++ (Head ofiles) +++ "' not found."]
		# ps					= showInfo line ps
808
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
809
810
811
	| not lolibsOk
		# line					= Level3 ["Link error: File: '" +++ (Head lfiles) +++ "' not found."]
		# ps					= showInfo line ps
812
		= continue False newpaths False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
813
814

	# (env_static_libs,ps)		= getCurrentSlibs ps
815
	#! sfiles					= Concat (SL_Libs libsinfo) env_static_libs		// only if really used?
Diederik van Arkel's avatar
Diederik van Arkel committed
816
817
818
819
820
821
822
823
824
825
826
827
	#! ofiles					= Reverse ofiles
	#! lfiles					= Reverse lfiles

//*	
	// .exe or .dat older than module.o
	// martijn also wants comparison with other libs and objs
	// !!! fails to check if console type options have changed...
	// ie. tries with old-fashioned PR_ExecUptoDate...
	// can't really fix this...
//	# (genabc,ps)				= CheckObjsOutOfDate genabc ofiles ps
//	# (genabc,ps) 				= CheckLibsOutOfDate genabc lfiles ps
	# (ood,ps)					= case lo.method of
828
									LM_Static  
Diederik van Arkel's avatar
Diederik van Arkel committed
829
830
										# (ood,ps) = CheckObjsOutOfDate genabc execpath ofiles` ps
										| ood -> (ood,ps)
831
832
										-> CheckExecOutOfDate genabc execpath fileinfo project ps
									LM_Dynamic -> CheckExecOutOfDate genabc  ((RemoveSuffix` execpath) +++. ".bat") fileinfo project ps
Diederik van Arkel's avatar
Diederik van Arkel committed
833
	| not ood
834
		= continue True False False fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
//*/
	# static_info = 
		{ stat_mods				= symPaths app_path prj_path` modpaths
		, stat_objs				= symPaths app_path prj_path` ofiles
		, stat_slibs			= symPaths app_path prj_path` sfiles
		, stat_dlibs			= symPaths app_path prj_path` lfiles
		, stat_paths			= symPaths app_path prj_path` srcpaths
		, stat_app_path			= app_path
		, stat_prj_path			= prj_path`
		}
	# project					= setStaticInfo static_info project
	# (_,ps)					= accFiles (SaveProjectFile prj_path project app_path) ps
	# (linkstr,ps)				= getCurrentLink ps
	# (startupdir,ps)			= getStup ps
		
850
// want to wait with .exe out of date checks till here...
Diederik van Arkel's avatar
Diederik van Arkel committed
851
852
853
854
// ao ok
// lfiles ok
// ofiles ok
// sfiles ok
855
856
// so: chache .exe date with used ao and lfiles,ofiles,sfiles dates...
// can imporve now by Younger checking all objects
Diederik van Arkel's avatar
Diederik van Arkel committed
857

858
859
	# optionspath				= MakeOptionsName prj_path
	# (dynlstr,ps)				= getCurrentDynl ps
Diederik van Arkel's avatar
Diederik van Arkel committed
860
861
862
863
864
865
	# (ps, ok)					= Link linkstr updateErrorWindow execpath ao
									optionspath lfiles ofiles sfiles
									(lo.method == LM_Static)
									lo.generate_relocations
									lo.generate_link_map
									lo.link_resources
866
									(fulPath app_path prj_path` lo.resource_source)
Diederik van Arkel's avatar
Diederik van Arkel committed
867
									lo.generate_dll
868
869
									(fulPath app_path prj_path` lo.dll_export_list_name)
									startupdir dynlstr ps
Diederik van Arkel's avatar
Diederik van Arkel committed
870
	# project					= if ok (PR_SetLinked project) project
871
	= continue ok False ok fileinfo libsinfo modpaths project intr (abccache, ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
872
where
873
874
875
876
	DATEtoDateTime :: !DATE -> DateTime
	DATEtoDateTime {DATE | yy,mm,dd,h,m,s}
		= ({year`=yy,month`=mm,day`=dd,dayNr`=0},{hours`=h,minutes`=m,seconds`=s})

Diederik van Arkel's avatar
Diederik van Arkel committed
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
step intr DDone ps
	= stop (DDone,ps)

//-- Compile Phase...

:: UnknownFinishedProcessors = NoUnknownFinishedProcessors | UnknownFinishedProcessors !Int ![Int]

add_unknown_finished_processor NoUnknownFinishedProcessors
	= UnknownFinishedProcessors 1 []
add_unknown_finished_processor (UnknownFinishedProcessors n_unknown_finished_processors known_finished_processors)
	= UnknownFinishedProcessors (n_unknown_finished_processors+1) known_finished_processors							

remove_from_unknown_finished_processors completedSlot (UnknownFinishedProcessors n_unknown_finished_processors known_finished_processors)
	| not (isMember completedSlot known_finished_processors)
		= UnknownFinishedProcessors n_unknown_finished_processors [completedSlot:known_finished_processors]
remove_from_unknown_finished_processors completedSlot unknown_finished_processors
	= unknown_finished_processors

:: *DriverCodeGenerationInfo
	= SyncCodeGeneration
897
//	| ASyncCodeGeneration ![(Int,String,String)] !Int !UnknownFinishedProcessors // [(busy_process_number,abc_path,obj_path)] max_n_processes unknown_finished_processors
Diederik van Arkel's avatar
Diederik van Arkel committed
898
899
900

:: *DriverState
	= DInit !Bool !Project !MTPContinuation
901
902
//	| DComp !(List String) !DriverCompilingInfo !(List String) !FileInfoCache !*DirCache !*ABCCache !StaticLibInfo !Project !Bool !MTPContinuation
	| DComp !Bool !*DirCache !DriverCompilingInfo !(List String) !DriverStateRecord
Diederik van Arkel's avatar
Diederik van Arkel committed
903
//XXX	| DGene !Bool !Bool !FileInfoCache !StaticLibInfo !(List String) !(List String) !*ABCCache !Project !MTPContinuation
904
905
906
907
//	| DGene !Bool !Bool !FileInfoCache !StaticLibInfo !(List String) !(List String) !DriverCodeGenerationInfo !*ABCCache !Project !MTPContinuation
	| DGene !(List String) !DriverCodeGenerationInfo !DriverStateRecord
//	| DLink !Bool !Bool !FileInfoCache !StaticLibInfo !(List String) !*ABCCache !Project !MTPContinuation
	| DLink !DriverStateRecord
Diederik van Arkel's avatar
Diederik van Arkel committed
908
909
	| DDone

910
911
912
913
914
915
916
917
918
919
920
:: *DriverStateRecord =
	{ project	:: !Project
	, continue	:: !MTPContinuation
	, fileinfo	:: !FileInfoCache
	, abccache	:: !*ABCCache
	, libsinfo	:: !StaticLibInfo
	, ok		:: !Bool
	, newpaths	:: !Bool
	, modpaths	:: !List String
	}

Diederik van Arkel's avatar
Diederik van Arkel committed
921
922
:: *DriverCompilingInfo
	= Sync
923
/*
Diederik van Arkel's avatar
Diederik van Arkel committed
924
925
	| AsyncWin	!Int ![CurrentlyCompiled]
	| Async	![CurrentlyCompiled] !Int !Int !UnknownFinishedProcessors // busy_processors max_n_processes n_used_processors unknown_finished_processors
926
*/
Diederik van Arkel's avatar
Diederik van Arkel committed
927
928
929
	| Pers	!*CompilingInfo

compiling_info :: !DriverCompilingInfo -> (String,DriverCompilingInfo)
930
931
932
/*
compiling_info info=:(AsyncWin _ current)
	=	(compiling_info_async current,info)
Diederik van Arkel's avatar
Diederik van Arkel committed
933
934
compiling_info info=:(Async current _ _ _)
	= (compiling_info_async current,info);
935
*/
Diederik van Arkel's avatar
Diederik van Arkel committed
936
937
938
939
940
941
942
943
944
compiling_info info
	= ("",info)

compiling_info_async []
	= ""
compiling_info_async current
	=	foldl (\s c -> s +++ " "+++(GetModuleName c.iclModule)) "Compiling:" current

//	Scan modified modules and update the dependencies (recompile if necessary).
945
946
947
UpdateDependencies :: !Bool !String !(List String) !DriverCompilingInfo !*DirCache !DriverStateRecord !*(PSt *General)
	-> (*(PSt *General),*DirCache,Bool,Bool,List String,DriverCompilingInfo,DriverStateRecord,Bool)
UpdateDependencies force next rest compinfo dircache ds ps`
Diederik van Arkel's avatar
Diederik van Arkel committed
948
949
	# (version,ps)				= getCurrentVers ps					// lift to DriverState
	# (cinf,compinfo)			= compiling_info compinfo
950
951
	# line						= Level2 ((if verbose ("Analyzing \'" +++  modname +++ "\'. ") ("")) +++ cinf)
	# ps						= verboseInfo verbose line ps
Diederik van Arkel's avatar
Diederik van Arkel committed
952
	# ((abccache,fileinfo,info),ps)
953
954
								= FI_GetFileInfo proc impname ds.abccache ds.fileinfo ps
	# ds						= {ds & abccache = abccache, fileinfo = fileinfo}
Diederik van Arkel's avatar
Diederik van Arkel committed
955
956
	# abcexists					= info.abcdate.exists
	| not abcexists
957
958
		# lines					= Level3 ["["+++modname+++".icl,]: no abc file"]
		#! ps					= showInfo lines ps
Diederik van Arkel's avatar
Diederik van Arkel committed
959
		= case compinfo of
960
961
962
963
			Sync				-> UpdateSyncDependencies rest impname co dircache ds ps
//			async=:(Async _ _ _ _)-> UpdateAsyncDependencies async rest impname co dircache ds ps
//			async=:(AsyncWin _ _)-> UpdateAsyncDependencies async rest impname co dircache ds ps
			(Pers info)			-> UpdatePersDependencies info rest impname co dircache ds ps
Diederik van Arkel's avatar
Diederik van Arkel committed
964
965
966
	| info.sys	// system module
		# wrongVersion			= info.version <> version
		| wrongVersion
967
968
		// add automatic recompilation if system module...
		// check with John what compiler flags we should pass...
Diederik van Arkel's avatar
Diederik van Arkel committed
969
970
			# line				= Level3 ["Error: System file: '" +++ modname +++ "' has incorrect abc version."]
			# ps				= showInfo line ps
971
			= (ps, dircache, False, False, rest, compinfo, ds, False)
Diederik van Arkel's avatar
Diederik van Arkel committed
972
973
974
		# wantstp				= tp && (not co.neverTimeProfile)
		# compile				= /*mp <> info.abcOptions.abcMemoryProfile ||*/ wantstp <> info.abcOptions.abcTimeProfile
		# lines					= (Level3 (if (verbose && compile) ["["+++modname+++".abc,]: System module compiled with different options"] []))
975
		# ps					= verboseInfo verbose lines ps
Diederik van Arkel's avatar
Diederik van Arkel committed
976
977
978
979
		| compile
			# abcPath			= MakeABCSystemPathname next
			# (patched, ps)		= accFiles (PatchSystemABC version True abcPath /*ao.memoryProfiling*/ wantstp) ps
			| patched
980
981
982
983
984
985
				# ((abcdate,fileinfo), ps)
								= accFiles (FI_UpdateAbcDate impname abcPath wantstp ds.fileinfo) ps
				# ds = {ds & fileinfo = fileinfo}
				# ((ok,mods,_,_,objs,libs,abccache),ps)
								= accFiles (ParseABCDependencies` info.abcpath abcdate ds.abccache) ps
				# ds = {ds & abccache = abccache}
Diederik van Arkel's avatar
Diederik van Arkel committed
986
				| not ok
987
					# line		= Level3 ["Error: Strange error parsing dependencies: '" +++ info.abcpath +++ "'."]
Diederik van Arkel's avatar
Diederik van Arkel committed
988
					// can actually only occur when failed to open .abc file...
989
990
					# ps		= showInfo line ps
					= (ps,dircache,False,False,rest,compinfo,ds,False)
Diederik van Arkel's avatar
Diederik van Arkel committed
991
992
993
				# (ok,paths,dircache)
								= LookupModulePaths mods dircache
				| not ok
994
995
996
997
998
999
1000
					# line		= Level3 ["Error: '" +++ (Head paths) +++ "' not found."]
					# ps		= showInfo line ps
					= (ps,dircache,False,False,rest,compinfo,ds,False)
				#! rest			= Concat rest paths
				#! project		= PR_AddABCInfo next objs libs defaultCO defeo impeo ds.project
				   ds = {ds & project = project, modpaths = next :! ds.modpaths}
				=	(ps, dircache, True, False, rest, compinfo, ds, True)
For faster browsing, not all history is shown. View entire blame