[MLton-commit] r6204

Vesa Karvonen vesak at mlton.org
Mon Nov 26 07:19:10 PST 2007


Started work on a SDL binding.
----------------------------------------------------------------------

A   mltonlib/trunk/org/mlton/vesak/sdl/
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/Generate-FFI.sh
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/config/
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/config/x86-linux.h
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/sdl.sml
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.bgb
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.sh
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.mlb
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.sml
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/lib.mlb
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/export.sml
A   mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/sdl.sig

----------------------------------------------------------------------


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable
___________________________________________________________________
Name: svn:ignore
   + generated


Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/Generate-FFI.sh
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/Generate-FFI.sh	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/Generate-FFI.sh	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,95 @@
+#!/bin/bash
+
+# Copyright (C) 2007 Vesa Karvonen
+#
+# This code is released under the MLton license, a BSD-style license.
+# See the LICENSE file or http://mlton.org/License for details.
+
+set -e
+set -x
+
+##########################################################################
+# Configuration
+
+prefix=/usr/include
+GL=$prefix/GL
+SDL=$prefix/SDL
+
+headers="$SDL/SDL.h
+$SDL/SDL_active.h
+$SDL/SDL_audio.h
+$SDL/SDL_cdrom.h
+$SDL/SDL_copying.h
+$SDL/SDL_cpuinfo.h
+$SDL/SDL_endian.h
+$SDL/SDL_error.h
+$SDL/SDL_events.h
+$SDL/SDL_getenv.h
+$SDL/SDL_joystick.h
+$SDL/SDL_keyboard.h
+$SDL/SDL_keysym.h
+$SDL/SDL_loadso.h
+$SDL/SDL_main.h
+$SDL/SDL_mouse.h
+$SDL/SDL_mutex.h
+$SDL/SDL_name.h
+$GL/gl.h
+$SDL/SDL_opengl.h
+$SDL/SDL_platform.h
+$SDL/SDL_quit.h
+$SDL/SDL_rwops.h
+$SDL/SDL_stdinc.h
+$SDL/SDL_syswm.h
+$SDL/SDL_thread.h
+$SDL/SDL_timer.h
+$SDL/SDL_types.h
+$SDL/SDL_version.h
+$SDL/SDL_video.h"
+
+##########################################################################
+# MLton Platform
+
+arch="$(mlton -show path-map | awk '/^TARGET_ARCH/ {print $2}')"
+os="$(mlton -show path-map | awk '/^TARGET_OS/ {print $2}')"
+target="$arch-$os"
+outdir=generated/$target
+
+mkdir -p $outdir
+
+##########################################################################
+# Generate ML-NLFFI
+
+#mlnlffigen -linkage static                             \
+#           -dir $outdir                                \
+#           -cppopt "-include detail/config/$target.h"  \
+#           $headers
+
+##########################################################################
+# Generate #define constants
+
+consts=$outdir/constants.sml
+
+echo "(* WARNING: Generated by the $(basename $0) script. *)
+
+local
+   open IntInf
+   infix orb
+in
+   (* Manually translated: *)
+   fun SDL_BUTTON i = IntInf.<< (1, Word.fromLargeInt (i-1))" > $consts
+
+for header in $headers ; do
+    echo "" >> $consts
+    echo "   (* From $header: *)" >> $consts
+    sed -e 's#/\*.*\*/##g' -e $'s#[\t]\\+$##g' $header                                              \
+     | grep -o -e $'^#define[\t ]\\+\\(GL\\|SDL\\)_[_a-zA-Z0-9]\\+[\t ]\\+[^\\\\g-w]\\+$'           \
+     | sed -e $'s-#define[\t ]\\+\\([^\t ]\\+\\)[\t ]\\+\\(.\\+\\)-   val \\1 : IntInf.int = \\2-g' \
+           -e 's#|# orb #g'                                                                         \
+           -e 's#~# notb #g'                                                                        \
+           -e 's#-#~#g'                                                                             \
+           -e 's#(size_t)##g'                                                                       \
+           -e 's#(Uint32)##g'                                                                       \
+     >> $consts
+done
+
+echo 'end' >> $consts


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/Generate-FFI.sh
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/config/x86-linux.h
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/config/x86-linux.h	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/config/x86-linux.h	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,36 @@
+/* Copyright (C) 2007 Vesa Karvonen
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ */
+
+#define _BITS_PTHREADTYPES_H 1
+#define _SDL_endian_h
+
+#include <stddef.h>
+#include <sys/types.h>
+
+#include <SDL/SDL_config.h>
+
+#undef STDC_HEADERS
+
+#undef HAVE_CTYPE_H
+#undef HAVE_ICONV_H
+#undef HAVE_INTTYPES_H
+#undef HAVE_MALLOC_H
+#undef HAVE_STDARG_H
+#undef HAVE_STDDEF_H
+#undef HAVE_STDINT_H
+#undef HAVE_STDIO_H
+#undef HAVE_STDLIB_H
+#undef HAVE_STRINGS_H
+#undef HAVE_STRING_H
+#undef HAVE_SYS_TYPES_H
+
+#undef HAVE_ICONV
+
+typedef unsigned char       uint8_t;
+typedef unsigned short      uint16_t;
+typedef unsigned int        uint32_t;
+typedef          long long  int64_t;
+typedef unsigned long long  uint64_t;


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/config/x86-linux.h
___________________________________________________________________
Name: svn:eol-style
   + native

Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/sdl.sml
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/sdl.sml	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/sdl.sml	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,32 @@
+(* Copyright (C) 2007 Vesa Karvonen
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+structure Word32Flags = MkWordFlags (Word32)
+
+structure SDL :> SDL = struct
+   fun check code =
+       if 0 = code
+       then ()
+       else raise Fail (ZString.toML' (F_SDL_GetError.f' ()))
+
+   structure Init = struct
+      open Word32Flags
+      val ` = Word32.fromLargeInt
+      val TIMER       = `SDL_INIT_TIMER
+      val AUDIO       = `SDL_INIT_AUDIO
+      val VIDEO       = `SDL_INIT_VIDEO
+      val CDROM       = `SDL_INIT_CDROM
+      val JOYSTICK    = `SDL_INIT_JOYSTICK
+      val NOPARACHUTE = `SDL_INIT_NOPARACHUTE
+      val EVENTTHREAD = `SDL_INIT_EVENTTHREAD
+      val EVERYTHING  = `SDL_INIT_EVERYTHING
+   end
+   val init = check o F_SDL_Init.f'
+   val initSubSystem = check o F_SDL_InitSubSystem.f'
+   val quitSubSystem = F_SDL_QuitSubSystem.f'
+   val wasInit = F_SDL_WasInit.f'
+   val quit = F_SDL_Quit.f'
+end


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/detail/sdl.sml
___________________________________________________________________
Name: svn:eol-style
   + native


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce
___________________________________________________________________
Name: svn:ignore
   + generated


Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.bgb
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.bgb	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.bgb	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,8 @@
+;; Copyright (C) 2007 Vesa Karvonen
+;;
+;; This code is released under the MLton license, a BSD-style license.
+;; See the LICENSE file or http://mlton.org/License for details.
+
+(bg-build
+ :name  "Bounce SDL example"
+ :shell "./Build.sh")

Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.sh
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.sh	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.sh	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,21 @@
+# Copyright (C) 2007 Vesa Karvonen
+#
+# This code is released under the MLton license, a BSD-style license.
+# See the LICENSE file or http://mlton.org/License for details.
+
+set -e
+set -x
+
+export MLTON_LIB="$(cd ../../../../../../../ && pwd)"
+
+mkdir -p generated
+
+time \
+mlton -mlb-path-var "SML_COMPILER mlton"    \
+      -mlb-path-var "MLTON_LIB $MLTON_LIB"  \
+      -prefer-abs-paths true                \
+      -show-def-use generated/bounce.du     \
+      -output generated/bounce              \
+      -link-opt '-ldl'                      \
+      -link-opt '-lSDL'                     \
+      bounce.mlb


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/Build.sh
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.mlb
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.mlb	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.mlb	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,13 @@
+(* Copyright (C) 2007 Vesa Karvonen
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+local
+   $(MLTON_LIB)/com/ssh/extended-basis/unstable/basis.mlb
+   ../../lib.mlb
+
+   bounce.sml
+in
+end


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.mlb
___________________________________________________________________
Name: svn:eol-style
   + native

Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.sml
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.sml	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.sml	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,15 @@
+(* Copyright (C) 2007 Vesa Karvonen
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+fun say ms = println (concat ms)
+
+fun main () =
+    ()
+
+val () =
+    (SDL.init SDL.Init.EVERYTHING
+   ; say ["SDL initialized"]
+   ; after (main, SDL.quit))


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/example/bounce/bounce.sml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/lib.mlb
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/lib.mlb	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/lib.mlb	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,25 @@
+(* Copyright (C) 2007 Vesa Karvonen
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+local
+   $(MLTON_LIB)/com/ssh/extended-basis/unstable/basis.mlb
+   $(SML_LIB)/mlnlffi-lib/mlnlffi-lib.mlb
+   generated/$(TARGET_ARCH)-$(TARGET_OS)/nlffi-generated.mlb
+   generated/$(TARGET_ARCH)-$(TARGET_OS)/constants.sml
+in
+   ann
+      "forceUsed"
+      "sequenceNonUnit warn"
+      "warnUnused true"
+   in
+      local
+         public/sdl.sig
+         detail/sdl.sml
+      in
+         public/export.sml
+      end
+   end
+end


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/lib.mlb
___________________________________________________________________
Name: svn:eol-style
   + native

Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/export.sml
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/export.sml	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/export.sml	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,13 @@
+(* Copyright (C) 2007 Vesa Karvonen
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+(** == Exported Signatures == *)
+
+signature SDL = SDL
+
+(** == Exported Structures == *)
+
+structure SDL : SDL = SDL


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/export.sml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/sdl.sig
===================================================================
--- mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/sdl.sig	2007-11-25 13:45:54 UTC (rev 6203)
+++ mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/sdl.sig	2007-11-26 15:19:09 UTC (rev 6204)
@@ -0,0 +1,31 @@
+(* Copyright (C) 2007 Vesa Karvonen
+ *
+ * This code is released under the MLton license, a BSD-style license.
+ * See the LICENSE file or http://mlton.org/License for details.
+ *)
+
+(**
+ * This is a thin wrapper on top of the SDL API.  It should be easy to see
+ * the correspondence between these specifications and the SDL API.  The
+ * most visible difference is that instead of returning errors, we raise
+ * exceptions.  See, for example, [http://www.libsdl.org/cgi/docwiki.cgi/
+ * SDL Documentation Wiki] for documentation on the SDL.
+ *)
+signature SDL = sig
+   structure Init : sig
+      include FLAGS where type flags_word = Word32.t
+      val TIMER : flags
+      val AUDIO : flags
+      val VIDEO : flags
+      val CDROM : flags
+      val JOYSTICK : flags
+      val NOPARACHUTE : flags
+      val EVENTTHREAD : flags
+      val EVERYTHING : flags
+   end
+   val init : Init.flags Effect.t
+   val initSubSystem : Init.flags Effect.t
+   val quitSubSystem : Init.flags Effect.t
+   val wasInit : Init.flags -> Init.flags
+   val quit : Unit.t Effect.t
+end


Property changes on: mltonlib/trunk/org/mlton/vesak/sdl/unstable/public/sdl.sig
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the MLton-commit mailing list