Commits

Jason McKesson committed b4332f6

GL Load has most of the stuff needed to load functions.
Just needs the glue now.

  • Participants
  • Parent commits 7c355d7

Comments (0)

Files changed (4)

File modules/StructGLLoad.lua

 	},
 }
 
+local function CoreLoaderStruct(funcFilter)
+	return
+{ type="group",
+	{ type="core-ext-iter",
+		{ type="func-iter",
+			{ type="filter", name= funcFilter .. "(func)",
+				{ type="write", name="LoadFunctionCore(hFile, func, typemap, spec, options)", },
+			},
+		},
+	},
+	{ type="func-iter",
+		{ type="filter", name=funcFilter .. "(func)",
+			{ type="write", name="LoadFunctionCore(hFile, func, typemap, spec, options)", },
+		},
+	},
+}
+end
+
+local source_struct = 
+{ type="group",
+	{ type="write", name="Includes(hFile, spec, options)" },
+	{ type="blank"},
+	{ type="write", name="PointerLoading(hFile, specData, spec, options)" },
+	{ type="blank"},
+	{ type="ext-iter",
+		{ type="write", name="ExtVariable(hFile, extName, spec, options)" },
+	},
+	{ type="blank"},
+	{ type="block", name="ClearExtVars(hFile, spec, options)",
+		{ type="ext-iter",
+			{ type="write", name="ClearExtVar(hFile, extName, spec, options)" },
+		},
+	},
+	{ type="blank"},
+	{ type="func-seen",
+		{ type="ext-iter",
+			{ type="func-iter",
+				{ type="write", name="FuncDef(hFile, func, typemap, spec, options)", },
+			},
+			{ type="blank", cond="func-iter"},
+			{ type="block", name="LoadExtensionFuncs(hFile, extName, spec, options)", cond="func-iter",
+				{ type="func-iter",
+					{ type="write", name="LoadFunction(hFile, func, typemap, spec, options)", },
+				},
+			},
+			{ type="blank", cond="func-iter"},
+		},
+		{ type="version-iter",
+			{ type="func-iter",
+				{ type="write", name="FuncDefCond(hFile, func, typemap, spec, options, funcSeen)", },
+			},
+		},
+		{ type="blank"},
+		{ type="version-iter",
+			{ type="filter", name="VersionHasCoreFuncs(version, specData, spec, options)",
+				{ type="block", name="LoadCoreFuncs(hFile, version, spec, options)",
+					CoreLoaderStruct("CoreFunc"),
+
+				},
+				{ type="blank"},
+			},
+			{ type="filter", name="VersionHasCompFuncs(version, specData, spec, options)",
+				{ type="block", name="LoadCoreFuncsComp(hFile, version, spec, options)",
+					CoreLoaderStruct("CompFunc"),
+				},
+			},
+		},
+	},
+}
+
 
 local my_struct =
 {
 				{ type="block", name="IncludeGuard(hFile, version, spec, options)",
 					{ type="blank"},
 					{ type="block", name="Extern(hFile, spec, options)",
-						common_ext_struct,
+						{ type="enum-iter",
+							{ type="filter", name="CoreEnum(enum)",
+								{ type="write", name="Enumerator(hFile, enum, enumTable, spec, options)", },
+							},
+						},
+						{ type="blank", cond="enum-iter"},
+						{ type="func-iter",
+							{ type="filter", name="CoreFunc(func)",
+								{ type="write", name="FuncTypedef(hFile, func, typemap, spec, options)", },
+							},
+						},
+						{ type="blank", cond="func-iter"},
+						{ type="func-iter",
+							{ type="filter", name="CoreFunc(func)",
+								{ type="write", name="FuncDecl(hFile, func, typemap, spec, options)", },
+							},
+						},
+						{ type="blank", cond="func-iter"},
 					},
 				},
 			},
 				{ type="block", name="IncludeGuardRem(hFile, version, spec, options)",
 					{ type="blank"},
 					{ type="block", name="Extern(hFile, spec, options)",
-						common_ext_struct,
+						{ type="enum-iter",
+							{ type="filter", name="CompEnum(enum)",
+								{ type="write", name="Enumerator(hFile, enum, enumTable, spec, options)", },
+							},
+						},
+						{ type="blank", cond="enum-iter"},
+						{ type="func-iter",
+							{ type="filter", name="CompFunc(func)",
+								{ type="write", name="FuncTypedef(hFile, func, typemap, spec, options)", },
+							},
+						},
+						{ type="blank", cond="func-iter"},
+						{ type="func-iter",
+							{ type="filter", name="CompFunc(func)",
+								{ type="write", name="FuncDecl(hFile, func, typemap, spec, options)", },
+							},
+						},
+						{ type="blank", cond="func-iter"},
 					},
 				},
 			},
 	
 	--Source file.
 	{ type="file", style="source", name="GetFilename(basename, spec, options)",
+		source_struct,
 	},
 }
 

File modules/Structure.lua

 - options
 - basename
 - hFile			Provided by file blocks
-- file_style	Provided by file blocks. A file-specific subsection of `style`.
 - extName		Provided by extension iterators.
 - version		Provided by version iterators.
 - sub_version	Provided by sub-version iterators.
 		end
 	end
 	
+	--NO MORE RETURNS FROM THIS POINT FORWARD!
+	if(self.newStyle) then
+		context:PushStyle(self.newStyle)
+	end
+	
 	local noChildren = nil
 	if(self.PreProcess) then
 		noChildren = self:PreProcess(context)
 	if(self.PostProcess) then
 		self:PostProcess(context)
 	end
+	
+	if(self.newStyle) then
+		context:PopStyle()
+	end
 end
 
 function action:ProcessChildren(context)
 	end
 end
 
-function action:CallFunction(style, context, name)
+function action:CallFunction(context, name)
 	name = name or self.name
 	self:Assert(name, "Unknown function name.")
-	self:Assert(style[name], "The style does not have a function " .. name)
+	local style = context:FindStyleForFunc(name)
+	self:Assert(style, "The style does not have a function " .. name)
 	
 	local paramList = {}
 	for _, param in ipairs(self.params) do
 		assert(conditionals[data.cond], "Unknown conditional " .. data.cond)
 		act._cond = data.cond
 	end
+	
+	act.newStyle = data.style
 
 	--Make child actions recursively.
 	for _, child in ipairs(data) do
 local fileAction = {}
 
 function fileAction:PreProcess(context)
-	assert(context.style[self.file_style],
-		"The style does not have a sub-section named " .. self.file_style)
 	assert(context.hFile == nil, "You cannot nest `file` blocks.")
 
-	context.file_style = context.style[self.file_style]
-	local filename = self:CallFunction(context.file_style, context)
+	local filename = self:CallFunction(context)
 	
 	local hFile = io.open(filename, "w")
 	context.hFile = TabbedFile.TabbedFile(hFile, context.options.indent)
 function fileAction:PostProcess(context)
 	context.hFile:close()
 	context.hFile = nil
-	context.file_style = nil
 end
 
 MakeActionType("file", fileAction, function(self, data)
 	assert(data.style, "File actions must have a `style`")
 	assert(data.name, "File actions need a name to call.")
 
-	self.file_style = data.style
 	self.params = self.params or {"basename", "options"}
 end)
 
 local blockAction = {}
 
 function blockAction:PreProcess(context)
-	assert(context.file_style, "Cannot write a block outside of a file.")
-	self:CallFunction(context.file_style, context, "WriteBlockBegin" .. self.name)
+	assert(context.hFile, "Cannot write a block outside of a file.")
+	self:CallFunction(context, "WriteBlockBegin" .. self.name)
 end
 
 function blockAction:PostProcess(context)
-	self:CallFunction(context.file_style, context, "WriteBlockEnd" .. self.name)
+	self:CallFunction(context, "WriteBlockEnd" .. self.name)
 end
 
 MakeActionType("block", blockAction, function(self, data)
 local writeAction = {}
 
 function writeAction:PreProcess(context)
-	assert(context.file_style, "Cannot write data outside of a file.")
-	self:CallFunction(context.file_style, context)
+	assert(context.hFile, "Cannot write data outside of a file.")
+	self:CallFunction(context)
 end
 
 MakeActionType("write", writeAction, function(self, data)
 local filterAction = {}
 
 function filterAction:PreProcess(context)
-	return not self:CallFunction(context:GetStyle(), context, self.name)
+	return not self:CallFunction(context, self.name)
 end
 
 MakeActionType("filter", filterAction, function(self, data)
 		
 		context._coreExts = spec.GetCoreExts()
 		context._extTbl = util.InvertTable(options.extensions)
+		context._styles = { style }
 		
 		function context:GetStyle()
-			return context.file_style or self.style
+			return context._styles[#context._styles]
+		end
+		
+		function context:FindStyleForFunc(funcName)
+			for i = #context._styles, 1, -1 do
+				if(context._styles[i][funcName]) then
+					return context._styles[i]
+				end
+			end
+			
+			return nil
+		end
+		
+		function context:PushStyle(newStyleName)
+			assert(context._styles[1][newStyleName], "There is no style named " .. newStyleName)
+			table.insert(context._styles, context._styles[1][newStyleName])
+			context.style = context._styles[#context._styles]
+		end
+		
+		function context:PopStyle()
+			local ret = context._styles[#context._styles]
+			context._styles[#context._styles] = nil
+			context.style = context._styles[#context._styles]
+			return ret
 		end
 		
 		for _, action in ipairs(actions) do

File modules/StyleGLLoadC.lua

 
 function incl_hdr.VersionFilenameCore(basename, version, spec, options)
 	local basename, dir = util.ParsePath(basename)
-	return dir .. glload.headerDirectory .. spec.FilePrefix() .. version .. ".h"
+	return dir .. glload.headerDirectory ..
+		glload.GetVersionCoreBasename(version, spec, options)
 end
 
 function incl_hdr.VersionFilenameComp(basename, version, spec, options)
 	local basename, dir = util.ParsePath(basename)
-	return dir .. glload.headerDirectory .. spec.FilePrefix() .. version .. "_comp.h"
+	return dir .. glload.headerDirectory ..
+		glload.GetVersionCompBasename(version, spec, options)
 end
 
 function incl_hdr.AllFilename(basename, spec, options)
 	local basename, dir = util.ParsePath(basename)
-	return dir .. glload.headerDirectory .. spec.FilePrefix() .. "all.h"
+	return dir .. glload.headerDirectory .. 
+		glload.GetAllBasename(spec, options)
 end
 
 function incl_hdr.WriteBlockBeginIncludeGuardCore(hFile, version, spec, options)
 	return dir .. glload.sourceDirectory .. spec.FilePrefix() .. "load.c"
 end
 
+function source.WriteIncludes(hFile, spec, options)
+	hFile:writeblock[[
+#include <stdlib.h>
+#include <string.h>
+]]
+	hFile:fmt('#include "%s"\n', glload.headerDirectory .. 
+		glload.GetAllBasename(spec, options))
+end
 
+function source.WritePointerLoading(hFile, specData, spec, options)
+	hFile:writeblock(spec.GetLoaderFunc())
+end
+
+function source.WriteExtVariable(hFile, extName, spec, options)
+	hFile:fmt("int %s = 0;\n",
+		glload.GetExtVariableName(extName, spec, options))
+end
+
+function source.WriteBlockBeginClearExtVars(hFile, spec, options)
+	hFile:fmtblock("static void %s()\n{\n",
+		glload.GetClearExtVarsFuncName(spec, options))
+	hFile:inc()
+end
+
+function source.WriteBlockEndClearExtVars(hFile, spec, options)
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function source.WriteClearExtVar(hFile, extName, spec, options)
+	hFile:fmt("%s = 0;\n",
+		glload.GetExtVariableName(extName, spec, options))
+end
+
+function source.WriteFuncDef(hFile, func, typemap, spec, options)
+	hFile:fmt("%s %s = NULL;\n",
+		glload.GetFuncTypedefName(func, spec, options),
+		glload.GetFuncPtrName(func, spec, options))
+end
+
+function source.WriteFuncDefCond(hFile, func, typemap, spec, options, funcSeen)
+	if(not funcSeen[func.name]) then
+		source.WriteFuncDef(hFile, func, typemap, spec, options)
+	end
+end
+
+function source.WriteBlockBeginLoadExtensionFuncs(hFile, extName, spec, options)
+	hFile:fmt("static int %s()\n",
+		glload.GetLoadExtensionFuncName(extName, spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+end
+
+function source.WriteBlockEndLoadExtensionFuncs(hFile, extName, spec, options)
+	hFile:write("return numFailed;\n")
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function source.WriteLoadFunction(hFile, func, typemap, spec, options)
+	hFile:fmt('%s = %s("%s");\n',
+		glload.GetFuncPtrName(func, spec, options),
+		common.GetProcAddressName(spec),
+		common.GetOpenGLFuncName(func, spec))
+	hFile:fmt("if(!%s) ++numFailed;\n",
+		glload.GetFuncPtrName(func, spec, options))
+end
+
+function source.WriteBlockBeginLoadCoreFuncs(hFile, version, spec, options)
+	hFile:fmt("static int %s()\n",
+		glload.GetLoadCoreFuncName(version, spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+end
+
+function source.WriteBlockEndLoadCoreFuncs(hFile, version, spec, options)
+	hFile:write("return numFailed;\n")
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function source.WriteBlockBeginLoadCoreFuncsComp(hFile, version, spec, options)
+	hFile:fmt("static int %s()\n",
+		glload.GetLoadCoreCompFuncName(version, spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+end
+
+function source.WriteBlockEndLoadCoreFuncsComp(hFile, version, spec, options)
+	hFile:write("return numFailed;\n")
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function source.WriteLoadFunctionCore(hFile, func, typemap, spec, options)
+	hFile:fmt('%s = %s("%s");\n',
+		glload.GetFuncPtrName(func, spec, options),
+		common.GetProcAddressName(spec),
+		common.GetOpenGLFuncName(func, spec))
+		
+	if(func.name:match("EXT$")) then
+		hFile:fmt("/* %s comes from DSA.*/\n",
+			common.GetOpenGLFuncName(func, spec))
+	else
+		hFile:fmt("if(!%s) ++numFailed;\n",
+			glload.GetFuncPtrName(func, spec, options))
+	end
+end
 
 my_style =
 {
 	end
 end
 
+local function HasFunclistAnyCore(funcList)
+	for _, func in ipairs(funcList) do
+		if(not func.deprecated) then
+			return true
+		end
+	end
+	
+	return false
+end
+
+local function HasFunclistAnyComp(funcList)
+	for _, func in ipairs(funcList) do
+		if(func.deprecated) then
+			return true
+		end
+	end
+	
+	return false
+end
+
+function my_style.FilterVersionHasCoreFuncs(version, specData, spec, options)
+	local coreExtByVersion = spec.GetCoreExts()
+	if(not coreExtByVersion) then return end
+	
+	local coreExts = coreExtByVersion[version]
+	
+	if(coreExts) then
+		for _, extName in ipairs(coreExts) do
+			if(HasFunclistAnyCore(specData.extdefs[extName].funcs)) then
+				return true
+			end
+		end
+	end
+	
+	if(HasFunclistAnyCore(specData.coredefs[version].funcs)) then
+		return true
+	end
+	
+	return false
+end
+
+function my_style.FilterVersionHasCompFuncs(version, specData, spec, options)
+	local coreExtByVersion = spec.GetCoreExts()
+	if(not coreExtByVersion) then return end
+	
+	local coreExts = coreExtByVersion[version]
+	
+	if(coreExts) then
+		for _, extName in ipairs(coreExts) do
+			if(HasFunclistAnyComp(specData.extdefs[extName].funcs)) then
+				return true
+			end
+		end
+	end
+	
+	if(HasFunclistAnyComp(specData.coredefs[version].funcs)) then
+		return true
+	end
+	
+	return false
+end
+
+function my_style.FilterCoreEnum(enum)
+	return not enum.removed and not enum.extensions
+end
+
+function my_style.FilterCompEnum(enum)
+	return enum.removed and not enum.extensions
+end
+
+function my_style.FilterCoreFunc(func)
+	return not func.deprecated
+end
+
+function my_style.FilterCompFunc(func)
+	return func.deprecated
+end
+
+
+
 local function Create()
 	return common.DeepCopyTable(my_style), struct
 end

File modules/glload_util.lua

 data.headerDirectory = ""
 data.sourceDirectory = ""
 
+function data.GetVersionCoreBasename(version, spec, options)
+	return spec.FilePrefix() .. version .. ".h"
+end
+
+function data.GetVersionCompBasename(version, spec, options)
+	return spec.FilePrefix() .. version .. "_comp.h"
+end
+
+function data.GetAllBasename(spec, options)
+	return spec.FilePrefix() .. "all.h"
+end
+
 function data.GetTypeHeaderBasename(spec, options)
 	return data.internalPrefix .. spec.FilePrefix() .. "type.h"
 end
 ]]
 end
 
+function data.GetClearExtVarsFuncName(spec, options)
+	return "ClearExtensionVariables"
+end
+
+function data.GetLoadExtensionFuncName(extName, spec, options)
+	return "LoadExt_" .. extName
+end
+
+function data.GetLoadCoreFuncName(version, spec, options)
+	return "LoadCore_Version_" .. version:gsub("%.", "_")
+end
+
+function data.GetLoadCoreCompFuncName(version, spec, options)
+	return "LoadCore_Version_" .. version:gsub("%.", "_") .. "_Comp"
+end
+
 
 return data