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

//	File I/O routines for the project.

import StdArray, StdFunc, StdInt
import UtilNewlinesFile, UtilOptions, UtilStrictLists
import PmProject
import UtilDate
9
from PmPath import convert_path_separators,convert_exec_path_separators_and_extension
Diederik van Arkel's avatar
Diederik van Arkel committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

ProjectFileVersion :== "1.4"

:: ProjectGlobalOptions =
	{ pg_built				:: !Bool
	, pg_codegen			:: CodeGenOptions
	, pg_application		:: ApplicationOptions
	, pg_link				:: LinkOptions
	, pg_projectPaths		:: List Pathname
	, pg_otherModules		:: List ModInfoAndName
	, pg_mainModuleInfo		:: ModInfoAndName
	, pg_staticLibInfo		:: StaticLibInfo
	, pg_target				:: String
	, pg_execpath			:: String
	, pg_dynamic			:: !ProjectDynamicInfo
25
	, pg_root_directory		:: !String
Diederik van Arkel's avatar
Diederik van Arkel committed
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
	, pg_precompile			:: !Maybe String
	, pg_postlink			:: !Maybe String
	}

:: ProjectDynamicInfo =
	{ dyn_syms				:: !List UndefSymbol
	, dyn_mods				:: !List UndefModule
	, dyn_objs				:: !List Pathname
	, dyn_slibs				:: !List Pathname
	, dyn_dlibs				:: !List Pathname
	, dyn_paths				:: !List Pathname
	}

EmptyDynamicInfo :: ProjectDynamicInfo
EmptyDynamicInfo =
	{ dyn_syms				= Nil
	, dyn_mods				= Nil
	, dyn_objs				= Nil
	, dyn_slibs				= Nil
	, dyn_dlibs				= Nil
	, dyn_paths				= Nil
	}


:: UndefSymbol =
	{ symbol_name	:: !String
	, path			:: !String
	}
 
:: UndefModule =
	{ module_name	:: !String
	, path			:: !String
	}

EmptyUndefSymbol	:: UndefSymbol
EmptyUndefSymbol =
	{ symbol_name	= ""
	, path			= ""
	}
 
EmptyUndefModule	:: UndefModule
EmptyUndefModule =
	{ module_name	= ""
	, path			= ""
	}

72
project_root_option = SimpleOption	"ProjectRoot"							(\a->a.pg_root_directory)   (\v a->{a & pg_root_directory = v})
Diederik van Arkel's avatar
Diederik van Arkel committed
73 74 75

ProjectGlobalOptionsTable :: OptionsTable ProjectGlobalOptions
ProjectGlobalOptionsTable =
76 77
	{	project_root_option
	,	SimpleOption	"Built"									(\a->a.pg_built)			(\v a->{a & pg_built=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
78
	,	SimpleOption	"Target"								(\a->a.pg_target)			(\v a->{a & pg_target=v})
79
	,	SimpleWithStringConversionOption convert_exec_path_separators_and_extension "Exec" (\a->a.pg_execpath) (\v a->{a & pg_execpath=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
	,	GroupedOption	"CodeGen"		CodeGenOptionsTable		(\a->a.pg_codegen)			(\v a->{a & pg_codegen=v})
	,	GroupedOption	"Application"	ApplicationOptionsTable	(\a->a.pg_application)		(\v a->{a & pg_application=v})
	,	GroupedOption	"Link"			LinkOptionsTable		(\a->a.pg_link)				(\v a->{a & pg_link=v})
	,	ListOption		"Paths"			PathName ""				(\a->a.pg_projectPaths)		(\v a->{a & pg_projectPaths=v})
	,	GroupedOption	"Static"		StaticLibsInfoTable		(\a->a.pg_staticLibInfo)	(\v a->{a & pg_staticLibInfo=v})
	,	SimpleOption	"Precompile"							(\a->unwrap a.pg_precompile)(\v a->{a & pg_precompile = wrap v})
	,	SimpleOption	"Postlink"								(\a->unwrap a.pg_postlink)	(\v a->{a & pg_postlink = wrap v})
	}
where
	// Making Precompile & Postlink 'List' options is probably prettier...
	unwrap Nothing = ""
	unwrap (Just s) = s
	
	wrap "" = Nothing
	wrap s = Just s

instance fromString Bool
where
	fromString "False"
		=	False
	fromString _ 
		=	True


ModInfoAndNameTable :: OptionsTable ModInfoAndName
ModInfoAndNameTable =
	{ SimpleOption	"Name"									(\a->a.name)				(\v a->{a & name=v})
107
	, SimpleWithStringConversionOption convert_path_separators "Dir" (\a->a.info.dir)	(\v a->{a & info.dir=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
	, GroupedOption	"Compiler"		CompilerOptionsTable	(\a->a.info.compilerOptions)(\v a->{a & info.compilerOptions=v})
	, GroupedOption	"Dcl"			EditWdOptionsTable		(\a->a.info.defeo)			(\v a->{a & info.defeo=v})
	, SimpleOption	"DclOpen"								(\a->a.info.defopen)		(\v a->{a & info.defopen=v})
	, GroupedOption	"Icl"			EditWdOptionsTable		(\a->a.info.impeo)			(\v a->{a & info.impeo=v})
	, SimpleOption	"IclOpen"								(\a->a.info.impopen)		(\v a->{a & info.impopen=v})
	, ListOption	"NeededObjFiles" ObjectFile ""			(\a->a.info.abcLinkInfo.linkObjFileNames)
																(\v a->{a & info.abcLinkInfo.linkObjFileNames=v})
	, ListOption	"NeededLibraries" Library   ""			(\a->a.info.abcLinkInfo.linkLibraryNames)
																(\v a->{a & info.abcLinkInfo.linkLibraryNames=v}) 
	}

ModInfoAndNameEntry =
		GroupedOption "Module" ModInfoAndNameTable id const

ProjectTable :: OptionsTable ProjectGlobalOptions
ProjectTable =	// +++ order is important here
	{	GroupedOption	"Global"		ProjectGlobalOptionsTable	id							const
	,	GroupedOption	"MainModule"	ModInfoAndNameTable			(\a->a.pg_mainModuleInfo)	(\v a->{a & pg_mainModuleInfo=v})
	,	ListOption		"OtherModules"	ModInfoAndNameEntry 		{info=EmptyModInfo,name=""}	(\a->a.pg_otherModules)	(\v a->{a & pg_otherModules=v})
	,	GroupedOption	"Dynamic"		DynamicInfoTable			(\a->a.pg_dynamic)			(\v a->{a & pg_dynamic=v})
	}
where
	EmptyModInfo :: ModInfo
	EmptyModInfo = {	dir		= EmptyPathname,
					compilerOptions		= DefaultCompilerOptions,
133 134
					defeo 	= {eo=DefaultEditOptions,pos_size=NoWindowPosAndSize},
					impeo	= {eo=DefaultEditOptions,pos_size=NoWindowPosAndSize},
Diederik van Arkel's avatar
Diederik van Arkel committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
					defopen = False,
					impopen = False,
					abcLinkInfo = {linkObjFileNames = Nil, linkLibraryNames = Nil} }
	DefaultEditOptions :: EditOptions;
	DefaultEditOptions =
		{	newlines	= HostNativeNewlineConvention
/*		{	tabs		= 4
		,	fontname	= "Courier"
		,	fontsize	= 9
		,	autoi		= True
		,	newlines	= HostNativeNewlineConvention
		,	showtabs	= False
		,	showlins	= False
		,	showsync	= True
*/		}

CompilerOptionsTable :: OptionsTable CompilerOptions
CompilerOptionsTable =
	{
		SimpleOption "NeverMemoryProfile"	(\a->a.neverMemoryProfile)	(\v a->{a & neverMemoryProfile=v}),
		SimpleOption "NeverTimeProfile"		(\a->a.neverTimeProfile)	(\v a->{a & neverTimeProfile=v}),
		SimpleOption "StrictnessAnalysis"	(\a->a.sa)					(\v a->{a & sa=v}),
		SimpleOption "ListTypes"			(\a->a.listTypes)			(\v a->{a & listTypes=v}),
		SimpleOption "ListAttributes"		(\a->a.attr)				(\v a->{a & attr=v}),
		SimpleOption "Warnings"				(\a->a.gw)					(\v a->{a & gw=v}),
		SimpleOption "Verbose"				(\a->a.bv)					(\v a->{a & bv=v}),
		SimpleOption "ReadableABC"			(\a->a.gc)					(\v a->{a & gc=v}),
162 163
		SimpleOption "ReuseUniqueNodes"		(\a->a.reuseUniqueNodes)	(\v a->{a & reuseUniqueNodes=v}),
		SimpleOption "Fusion"				(\a->a.fusion)				(\v a->{a & fusion=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
164 165 166 167 168 169
	}

CodeGenOptionsTable :: OptionsTable CodeGenOptions
CodeGenOptionsTable	=
	{
		SimpleOption "CheckStacks"		(\a->a.cs)		(\v a->{a & cs=v}),
170
		SimpleOption "CheckIndexes" 	(\a->a.ci)		(\v a->{a & ci=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
171
//		SimpleOption "KeepABC" 			(\a->a.kaf)		(\v a->{a & kaf=v}),
172
//		SimpleOption "TargetProcessor"	(\a->a.tp)		(\v a->{a & tp=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
173 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 206 207 208 209 210 211 212 213
	}

instance fromString Int
where
	fromString s
		=	toInt s

ApplicationProfiletOptionsTable :: OptionsTable ApplicationOptions
ApplicationProfiletOptionsTable	=
	{
		SimpleOption "Memory"					(\a->a.memoryProfiling)					(\v a->{a & memoryProfiling=v}),
		SimpleOption "MemoryMinimumHeapSize"	(\a->a.memoryProfilingMinimumHeapSize)	(\v a->{a & memoryProfilingMinimumHeapSize=v}),
		SimpleOption "Time"						(\a->a.profiling)						(\v a->{a & profiling=v}),
		SimpleOption "Stack"					(\a->a.stack_traces)					(\v a->{a & stack_traces=v})
	}

ApplicationOutputOptionsTable :: OptionsTable ApplicationOptions
ApplicationOutputOptionsTable	=
	{
		SimpleOption "Output"		(\a->a.o)						(\v a->{a & o=v}),
		SimpleOption "Font"			(\a->a.fn)						(\v a->{a & fn=v}),
		SimpleOption "FontSize"		(\a->a.fs)						(\v a->{a & fs=v}),
		SimpleOption "WriteStdErr"	(\a->a.write_stderr_to_file)	(\v a->{a & write_stderr_to_file=v})
	}

ApplicationOptionsTable :: OptionsTable ApplicationOptions
ApplicationOptionsTable	=
	{
		SimpleOption "HeapSize"						(\a->a.hs)					(\v a->{a & hs=v}),
		SimpleOption "StackSize"					(\a->a.ss)					(\v a->{a & ss=v}),
		SimpleOption "ExtraMemory"					(\a->a.em)					(\v a->{a & em=v}),
		SimpleOption "IntialHeapSize"				(\a->a.initial_heap_size)	(\v a->{a & initial_heap_size=v}),
		SimpleOption "HeapSizeMultiplier"			(\a->a.heap_size_multiple)	(\v a->{a & heap_size_multiple=v}),
		SimpleOption "ShowExecutionTime"			(\a->a.set)					(\v a->{a & set=v}),
		SimpleOption "ShowGC"						(\a->a.sgc)					(\v a->{a & sgc=v}),
		SimpleOption "ShowStackSize"				(\a->a.pss)					(\v a->{a & pss=v}),
		SimpleOption "MarkingCollector"				(\a->a.marking_collection)	(\v a->{a & marking_collection=v}),
		SimpleOption "StandardRuntimeEnv"			(\a->a.standard_rte)		(\v a->{a & standard_rte=v}),
		GroupedOption "Profile"	ApplicationProfiletOptionsTable	id				const,
		GroupedOption "Output"	ApplicationOutputOptionsTable	id				const
	}
214

Diederik van Arkel's avatar
Diederik van Arkel committed
215 216
PathName :: OptionsTableEntry {#Char}
PathName
217
	=	SimpleWithStringConversionOption convert_path_separators "Path"	id const
Diederik van Arkel's avatar
Diederik van Arkel committed
218 219 220 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 248

ModuleName :: OptionsTableEntry {#Char}
ModuleName
	=	SimpleOption "Module" id const

ObjectFile :: OptionsTableEntry {#Char}
ObjectFile
	=	SimpleOption "ObjectFile" id const

Library :: OptionsTableEntry {#Char}
Library
	=	SimpleOption "Library" id const

StaticLibsInfoTable :: OptionsTable StaticLibInfo
StaticLibsInfoTable =
	{ ListOption	"StaticLibs"			PathName ""		(\a->SL_Libs a)				(\v a->SL_SetLibs v a)
	, ListOption	"StaticDcls"			ModuleName ""	(\a->SL_Dcls a)				(\v a->SL_SetDcls v a)
	, ListOption	"StaticDeps"			ModuleName ""	(\a->SL_Deps a)				(\v a->SL_SetDeps v a)
	}

LinkOptionsTable :: OptionsTable LinkOptions
LinkOptionsTable	=
	{ ListOption	"ExtraObjects"			PathName ""	(\a->a.extraObjectModules)		(\v a->{a & extraObjectModules=v})
	, ListOption	"ExtraLibraries"		PathName ""	(\a->a.libraries)				(\v a->{a & libraries=v})
	, SimpleOption	"LinkMethod"						(\a->a.method)					(\v a->{a & method = v})
	, SimpleOption	"GenerateRelocations"				(\a->a.generate_relocations)	(\v a->{a & generate_relocations = v})
	, SimpleOption	"GenerateLinkMap"					(\a->a.generate_link_map)		(\v a->{a & generate_link_map = v})
	, SimpleOption	"LinkResources"						(\a->a.link_resources)			(\v a->{a & link_resources = v})
	, SimpleOption	"ResourceSource"					(\a->a.resource_source)			(\v a->{a & resource_source = v})
	, SimpleOption	"GenerateDLL"						(\a->a.generate_dll)			(\v a->{a & generate_dll = v})
	, SimpleOption	"ExportedNames"						(\a->a.dll_export_list_name)	(\v a->{a & dll_export_list_name = v})
Diederik van Arkel's avatar
Diederik van Arkel committed
249
//	, SimpleOption	"AddCarbResource"					(\a->a.add_carb_resource)		(\v a->{a & add_carb_resource = v})
Diederik van Arkel's avatar
Diederik van Arkel committed
250 251 252 253 254 255
	}

EditWdOptionsTable :: OptionsTable EditWdOptions
EditWdOptionsTable	=
	{
		GroupedOption "Editor"			EditOptionsTable	(\a->a.eo)			(\v a->{a & eo=v}),
256
		OptionalGroupedOption "WindowPosition" is_no_position_and_size WindowPositionTable (\a->a.pos_size) (\v a->{a & pos_size=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
257 258
	}

259 260 261 262 263
is_no_position_and_size NoWindowPosAndSize
	= True
is_no_position_and_size _
	= False

Diederik van Arkel's avatar
Diederik van Arkel committed
264 265 266 267 268 269 270 271 272 273 274
EditOptionsTable :: OptionsTable EditOptions
EditOptionsTable	=
	{}
/*	{ SimpleOption "TabSize"		(\a->a.EditOptions.tabs)		(\v a->{EditOptions | a & tabs=v})
	, SimpleOption "Font"			(\a->a.EditOptions.fontname)	(\v a->{EditOptions | a & fontname=v})
	, SimpleOption "FontSize"		(\a->a.EditOptions.fontsize)	(\v a->{EditOptions | a & fontsize=v})
	, SimpleOption "AutoIndent"	(\a->a.EditOptions.autoi)		(\v a->{EditOptions | a & autoi=v})
	, SimpleOption "ShowTabs"	(\a->a.EditOptions.showtabs)		(\v a->{EditOptions | a & showtabs=v})
	, SimpleOption "ShowLins"	(\a->a.EditOptions.showlins)		(\v a->{EditOptions | a & showlins=v})
	}
*/
275
WindowPositionTable :: OptionsTable OptionalWindowPosAndSize
Diederik van Arkel's avatar
Diederik van Arkel committed
276 277
WindowPositionTable	=
	{
278 279 280 281
		SimpleOption "X"		(\a->(getWindowPosAndSize a).posx)	(\v a->WindowPosAndSize {getWindowPosAndSize a & posx=v}),
		SimpleOption "Y"		(\a->(getWindowPosAndSize a).posy)	(\v a->WindowPosAndSize {getWindowPosAndSize a & posy=v}),
		SimpleOption "SizeX"	(\a->(getWindowPosAndSize a).sizex)	(\v a->WindowPosAndSize {getWindowPosAndSize a & sizex=v}),
		SimpleOption "SizeY"	(\a->(getWindowPosAndSize a).sizey)	(\v a->WindowPosAndSize {getWindowPosAndSize a & sizey=v})
Diederik van Arkel's avatar
Diederik van Arkel committed
282 283
	}

284 285 286
getWindowPosAndSize (WindowPosAndSize wps) = wps
getWindowPosAndSize NoWindowPosAndSize = DefWindowPos_and_Size

Diederik van Arkel's avatar
Diederik van Arkel committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
DynamicInfoTable =
	{ ListOption	"Syms"	Usym esym	(\a->a.dyn_syms)	(\v a->{a & dyn_syms=v})
	, ListOption	"Mods"	Umod emod	(\a->a.dyn_mods)	(\v a->{a & dyn_mods=v})
	, ListOption	"Objs"	PathName ""	(\a->a.dyn_objs)	(\v a->{a & dyn_objs=v})
	, ListOption	"Slib"	PathName ""	(\a->a.dyn_slibs)	(\v a->{a & dyn_slibs=v})
	, ListOption	"Dlib"	PathName ""	(\a->a.dyn_dlibs)	(\v a->{a & dyn_dlibs=v})
	, ListOption	"Pths"	PathName ""	(\a->a.dyn_paths)	(\v a->{a & dyn_paths=v})
	}

esym = {symbol_name = "", path = ""}
emod = {module_name = "", path = ""}

Usym = GroupedOption "usym" USTable id const
Umod = GroupedOption "umod" UMTable id const

USTable =
	{ SimpleOption "name" (\a->a.symbol_name)		(\v a -> {a & symbol_name = v})
	, SimpleOption "path" (\a->a.UndefSymbol.path)	(\v a -> {UndefSymbol | a & path = v})
	}
 
UMTable =
	{ SimpleOption "name" (\a->a.module_name)		(\v a -> {a & module_name = v})
	, SimpleOption "path" (\a->a.UndefModule.path)	(\v a -> {UndefModule | a & path = v})
	}