Porting Smalltalk

In order to have a live programming environment on Haiku, I tried to port opensmalltalk-vm.

Here are the changes made so far:

diff --git a/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c b/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c
index df8a1eec0..22f3cae87 100644
--- a/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c
+++ b/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c
@@ -57,6 +57,10 @@
 #endif
 #endif

+#ifdef __HAIKU__
+#define IFF_RUNNING IFF_LINK
+#endif
+
 #ifdef ACORN
 # include <time.h>
 # define __time_t
diff --git a/platforms/unix/vm/aio.c b/platforms/unix/vm/aio.c
index 1f7153fbc..cac95691d 100644
--- a/platforms/unix/vm/aio.c
+++ b/platforms/unix/vm/aio.c
@@ -88,6 +88,10 @@
   # define signal(a, b) sigset(a, b)
 # endif

+# if __HAIKU__
+  # define SIGIO SIGPOLL
+# endif
+
 #else /* !HAVE_CONFIG_H -- assume lowest common demoninator */

 # include <errno.h>
diff --git a/platforms/unix/vm/include_ucontext.h b/platforms/unix/vm/include_ucontext.h
index 3fb578445..63521f942 100644
--- a/platforms/unix/vm/include_ucontext.h
+++ b/platforms/unix/vm/include_ucontext.h
@@ -16,6 +16,8 @@
 #endif
 #ifdef __OpenBSD__
 # include <sys/signal.h>
+#elif __HAIKU__
+# include <signal.h>
 #elif __sun
 /* Single UNIX Specification (SUS), Version 2 specifies <ucontext.h> */
 # include <ucontext.h>
@@ -63,6 +65,14 @@
 # define _PC_IN_UCONTEXT uc_mcontext.gregs[EIP]
 # define _FP_IN_UCONTEXT uc_mcontext.gregs[REG_FP]
 # define _SP_IN_UCONTEXT uc_mcontext.gregs[REG_SP]
+#elif __HAIKU__ && __i386__
+# define _PC_IN_UCONTEXT uc_mcontext.eip
+# define _FP_IN_UCONTEXT uc_mcontext.ebp
+# define _SP_IN_UCONTEXT uc_mcontext.esp
+#elif __HAIKU__ && __amd64__
+# define _PC_IN_UCONTEXT uc_mcontext.rip
+# define _FP_IN_UCONTEXT uc_mcontext.rbp
+# define _SP_IN_UCONTEXT uc_mcontext.rsp
 #elif __linux__ && __i386__
 # define _PC_IN_UCONTEXT uc_mcontext.gregs[REG_EIP]
 # define _FP_IN_UCONTEXT uc_mcontext.gregs[REG_EBP]

This changes allow to build the bare VM. But in order to display graphics, it requires a display plugin, which uses X11 and OpenGL. I tried to build it using xlibe, but the display plugin requires X11/extensions/Xrandr.h which xlibe lacks.

There are two ways to solve this problem:

  • Either one needs to add Xrandr to xlibe
  • Or to implement a display plugin which uses native Haiku API

But I have no experience with neither X11 nor Be API. So I would appreciate some help or at least suggestions.

5 Likes

If you have to learn something, I vote to go native.

DO you know about BeSqueak the SmallTalk Squeak for BeOS? The source is on BeShare.
I’ll also share it on Haiku’s Telegram

2 Likes

Reading the source code, it appears Xrandr is optional; it compiles against it but can fall back on other things at runtime if it’s not present. So, you should be able to add some modifications to allow compiling without it, either.

I won’t be too surprised if you run into other missing Xlibe functionality, though, after you get it to build. Let me know if you do and I’ll take a look.

1 Like

It also seems to require Xatom.

Xatom.h is a standard header from xorgproto, it should be present?

1 Like

And here it is:

I had to disable OpenGL support because there’s no GL/glx.h. Here’s the patch for opensmalltalk vm: haiku.patch · GitHub.

12 Likes

For some reason network does not work in the vm, and an attempt to connect to somewhere freezes the vm for a while. I do not know how to debug this.

The Smalltalk VM? Or are you using Haiku inside a VM?

If it’s the Smalltalk VM, you can just attach a debugger…

Parse out glx.h for gl.h where needed. Review configure/build for X11/GLX specific handling to convert to non-GLX OS setups.

Smalltalk VM.

If it’s the Smalltalk VM, you can just attach a debugger…

Indeed. But a VM is probably harder to debug than a regular program.