Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /gen/gen-func-fn.sml
ViewVC logotype

View of /gen/gen-func-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 243 - (download) (annotate)
Wed Sep 24 08:12:22 2008 UTC (11 years, 3 months ago) by jhr
File size: 1086 byte(s)
  Working on generator tool
(* gen-func-fn.sml
 *
 * COPYRIGHT (c) 2008 John Reppy (http://cs.uchicago.edu/~jhr)
 * All rights reserved.
 *)

functor GenFuncFn (Target : sig

    val indirect : bool			(* true if called via function pointer *)
    val cName : string -> string	(* name mangling for C function *)

  end) = struct

    structure Ext = Extensions

    fun genParams [] = "unit"
      | genParams [Ext.Param{ty, ...}] = GLTypes.cToML ty
      | genParams (Ext.Param{ty, ...}::tys) = let
	  fun gen [] = [")"]
	    | gen (Ext.Param{ty, ...}::tys) = " * " :: GLTypes.cToML ty :: gen tys
	  in
	    String.concat ("(" :: GLTypes.cToML ty :: gen tys)
	  end

    fun gen {name, retTy, params} = if Target.indirect
	  then String.concat [
	      "val ", name, " = (_import * stdcall : MLton.Pointer.t -> ", genParams params, " -> ",
	      GLTypes.cToML retTy, ";)(_address \"", Target.cName name, "\" : MLton.Pointer.t;)"
	    ]
	  else String.concat [
	      "val ", name, " = _import \"", Target.cName name,
	      "\" stdcall : ", genParams params, " -> ",
	      GLTypes.cToML retTy, ";"
	    ]

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0