Skip to content
This repository

Unix-related fixes and basic interactive interpreter #6

Merged
merged 4 commits into from over 1 year ago

2 participants

Adrian Perez Evgeniy Golovin
Adrian Perez

This set of commits makes it possible to build ObjectScript for recent GNU/Linux and OpenBSD (both tested by me).

As a bonus, a simple interactive interpreter is added. It will only work under Unix as it uses the libedit library, which unfortunately is not available for Windows. A reasonable replacement for Windows could be MinGWEditLine, or just using the standard input functions (in that case there would be no support for line editing or history).

added some commits October 01, 2012
Adrian Perez Use intptr_t for casting pointers to integers
This is more correct and also fixes compilation errors with G++ 4.x
and Clang in Linux.
a346a36
Adrian Perez Simple interactive REPL using the libedit library
This implements a simple REPL (Read-Eval-Print Loop) interactive interpreter
using the BSD-licensed libedit library to read user input and provide input
history.
da52e09
Adrian Perez Update .gitignore with .o object files
Compiled object files with .o suffix are common in the Unix world.
5dfe31a
Adrian Perez Simple Makefile for Unix-like systems
Adds a simple Makefile which should work for most of the modern Unix
operating systems that ship GNU Make. Tested under GNU/Linux and
OpenBSD (using gmake port).
8249b28
Evgeniy Golovin unitpoint merged commit b0bb6c6 into from October 01, 2012
Evgeniy Golovin unitpoint closed this October 01, 2012
Evgeniy Golovin
Owner

thanks aperezdc, perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

Oct 01, 2012
Adrian Perez Use intptr_t for casting pointers to integers
This is more correct and also fixes compilation errors with G++ 4.x
and Clang in Linux.
a346a36
Adrian Perez Simple interactive REPL using the libedit library
This implements a simple REPL (Read-Eval-Print Loop) interactive interpreter
using the BSD-licensed libedit library to read user input and provide input
history.
da52e09
Adrian Perez Update .gitignore with .o object files
Compiled object files with .o suffix are common in the Unix world.
5dfe31a
Adrian Perez Simple Makefile for Unix-like systems
Adds a simple Makefile which should work for most of the modern Unix
operating systems that ship GNU Make. Tested under GNU/Linux and
OpenBSD (using gmake port).
8249b28
This page is out of date. Refresh to see the latest.
1  .gitignore
@@ -5,3 +5,4 @@
5 5
 *.vcxproj.user
6 6
 *.osd
7 7
 *.osc
  8
+*.o
14  Makefile
... ...
@@ -0,0 +1,14 @@
  1
+
  2
+SOURCES := source/objectscript.cpp source/main.cpp
  3
+OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES))
  4
+CXXFLAGS = -Wall -ggdb -O0
  5
+LD       = $(CXX)
  6
+
  7
+all: bin/os
  8
+
  9
+bin/os: $(OBJECTS) -ledit -lstdc++ -lm
  10
+	$(LD) $(LDFLAGS) -o $@ $^
  11
+
  12
+clean:
  13
+	$(RM) $(OBJECTS) bin/os
  14
+
46  source/main.cpp
... ...
@@ -0,0 +1,46 @@
  1
+
  2
+#include "objectscript.h"
  3
+#include <histedit.h>
  4
+#include <stdio.h>
  5
+
  6
+#ifndef OS_HISTORY_SIZE
  7
+#define OS_HISTORY_SIZE 1000
  8
+#endif /* !OS_HISTORY_SIZE */
  9
+
  10
+
  11
+static char*
  12
+prompt_cb(EditLine*)
  13
+{
  14
+    static char promptstr[] = "(os) ";
  15
+    return promptstr;
  16
+}
  17
+
  18
+
  19
+int main(int argc, char *argv[])
  20
+{
  21
+    HistEvent hevent;
  22
+    History *hh(history_init());
  23
+    history(hh, &hevent, H_SETUNIQUE, 1);
  24
+    history(hh, &hevent, H_SETSIZE, OS_HISTORY_SIZE);
  25
+
  26
+    EditLine *el(el_init("os", stdin, stdout, stderr));
  27
+    el_set(el, EL_SIGNAL, 1);
  28
+    el_set(el, EL_EDITOR, "emacs");
  29
+    el_set(el, EL_PROMPT, prompt_cb);
  30
+    el_set(el, EL_HIST, history, hh);
  31
+
  32
+    ObjectScript::OS *shell(ObjectScript::OS::create());
  33
+
  34
+    const char *line = NULL;
  35
+    int linelen = -1;
  36
+
  37
+    while ((line = el_gets(el, &linelen)) && linelen > 0) {
  38
+        shell->eval(line);
  39
+        history(hh, &hevent, H_ENTER, line);
  40
+    }
  41
+
  42
+    el_end(el);
  43
+    history_end(hh);
  44
+    shell->release();
  45
+}
  46
+
6  source/objectscript.cpp
@@ -8345,7 +8345,7 @@ int OS::Core::PropertyIndex::getHash() const
8345 8345
 		return index.v.string->hash;
8346 8346
 	}
8347 8347
 	// all other values share same area with index.v.value so just use it as hash
8348  
-	return (int)index.v.value;
  8348
+	return (ptrdiff_t) index.v.value;
8349 8349
 }
8350 8350
 
8351 8351
 // =====================================================================
@@ -15995,8 +15995,8 @@ void OS::initGlobalFunctions()
15995 15995
 
15996 15996
 void OS::initObjectClass()
15997 15997
 {
15998  
-	static int iterator_crc = (int)&iterator_crc;
15999  
-	static int array_iter_num_crc = (int)&array_iter_num_crc;
  15998
+	static intptr_t iterator_crc = (intptr_t)&iterator_crc;
  15999
+	static intptr_t array_iter_num_crc = (intptr_t)&array_iter_num_crc;
16000 16000
 
16001 16001
 	struct Object
16002 16002
 	{
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.