Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Work on the Mac bridge

  • Loading branch information...
commit 9725edaa47d0700ccc4b715ce4bd58d442d0acd8 1 parent 79b2177
@dpp dpp authored
View
BIN  ...i.xcodeproj/project.xcworkspace/xcuserdata/dpp.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
7 Mac/Visi/Visi/VisiDocument.m
@@ -8,9 +8,14 @@
#import "VisiDocument.h"
-@implementation VisiDocument
+#import "include/Test.h"
+@implementation VisiDocument
+void runCommand(const void *theId, const visi_command *cmd) {
+ id target = (__bridge id) theId;
+ // FIXME
+}
@synthesize editor;
@synthesize output;
View
40 Mac/Visi/Visi/haskell/VisiPro/Bridge.chs
@@ -1,15 +1,47 @@
-module VisiPro.Bridge where
+module VisiPro.Bridge(VisiCommand(SetProgramText, SetStringSource, SetNumberSource, SetNumberBool),
+ sendEvent) where
import Foreign.C.Types
import Foreign.Ptr
import Foreign.Storable
+import Foreign.C.String
+import qualified Data.Text as T
+import Foreign.Marshal.Alloc
#include "Test.h"
+type VoidPtr = Ptr ()
+
+data VisiCommand = SetProgramText T.Text
+ | SetStringSource T.Text T.Text
+ | SetNumberSource T.Text Double
+ | SetNumberBool T.Text Bool
+
+{#enum cmds as VisiCmds {upcaseFirstLetter} deriving (Show, Eq) #}
+
+
+
+sendEvent to (SetProgramText text) =
+ do
+ ptr <- mallocBytes {#sizeof visi_command #}
+ {#set visi_command->cmd #} ptr $ enumMe SetProgramTextCmd
+ let doStr s =
+ do
+ {#set visi_command->theInfo.text #} ptr s
+ {#call runCommand #} to ptr
+ free ptr
+ withText text doStr
+
+enumMe x = fromIntegral $ fromEnum x
+withText t = withCString (T.unpack t)
+
+
+{#pointer *visi_command as HVisiCmdPtr newtype #}
+
+getCommandCmd = {#get visi_command->cmd #}
+getCommandText = {#get visi_command->theInfo.text #}
+getEventCmd = {#get visi_event->cmd #}
-#c
-typedef struct test test_t;
-#endc
{-
{#pointer *test_t as Test#}
View
23 Mac/Visi/Visi/haskell/VisiPro/Mac.hs
@@ -30,24 +30,25 @@ import Foreign.Marshal.Alloc
*
* ***** END LICENSE BLOCK ***** -}
---import Visi.Util
---import Visi.Typer
---import Visi.Runtime
---import Visi.Parse
---import Visi.Executor
---import Visi.Expression
+import Visi.Util
+import Visi.Typer
+import Visi.Runtime
+import Visi.Parse
+import Visi.Executor
+import Visi.Expression
+import VisiPro.Bridge
type VoidPtr = Ptr ()
foreign import ccall safe "afterHaskellmain" afterHaskellmain :: CInt -> VoidPtr -> IO CInt
-
+-- foreign export ccall newProcess :: VoidPtr -> IO ()
-- | Initialize the Haskell runtime and call back into the ObjC code
-foreign export ccall haskellMain :: CInt -> VoidPtr -> IO ()
-haskellMain :: CInt -> VoidPtr -> IO ()
+foreign export ccall haskellMain :: CInt -> VoidPtr -> IO CInt
+haskellMain :: CInt -> VoidPtr -> IO CInt
haskellMain argc argv =
do
putStrLn "Meow and woof!!!!"
- afterHaskellmain argc argv
- return ()
+ ret <- afterHaskellmain argc argv
+ return ret
View
54 Mac/Visi/Visi/include/Test.h
@@ -1 +1,53 @@
-#define frog 44
+/***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Visi.io.
+ *
+ * The Initial Developer of the Original Code is
+ * David Pollak.
+ * Portions created by the Initial Developer are Copyright (C) 2012
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * ***** END LICENSE BLOCK *****/
+
+
+enum cmds {
+ setProgramTextCmd,
+ setStringSourceCmd,
+ setNumberSourceCmd,
+ setBoolSourceCmd} visiCmds;
+
+typedef struct {
+ enum cmds cmd;
+ const char *target;
+ union info {
+ const char *text;
+ int boolValue;
+ double number;
+ } theInfo;
+} visi_command;
+
+
+
+typedef struct
+{
+ int cmd;
+ const char *text;
+ int boolValue;
+ double number;
+} visi_event;
+
+void runCommand(const void *id, const visi_command *cmd);
+
Please sign in to comment.
Something went wrong with that request. Please try again.