Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Unix-related fixes and basic interactive interpreter #6

Merged
merged 4 commits into from

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).

aperezdc added some commits
Adrian Perez aperezdc 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 aperezdc 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 aperezdc Update .gitignore with .o object files
Compiled object files with .o suffix are common in the Unix world.
5dfe31a
Adrian Perez aperezdc 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
Evgeniy Golovin
Owner

thanks aperezdc, perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 1, 2012
  1. Adrian Perez

    Use intptr_t for casting pointers to integers

    aperezdc authored
    This is more correct and also fixes compilation errors with G++ 4.x
    and Clang in Linux.
  2. Adrian Perez

    Simple interactive REPL using the libedit library

    aperezdc authored
    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.
  3. Adrian Perez

    Update .gitignore with .o object files

    aperezdc authored
    Compiled object files with .o suffix are common in the Unix world.
  4. Adrian Perez

    Simple Makefile for Unix-like systems

    aperezdc authored
    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).
This page is out of date. Refresh to see the latest.
1  .gitignore
View
@@ -5,3 +5,4 @@
*.vcxproj.user
*.osd
*.osc
+*.o
14 Makefile
View
@@ -0,0 +1,14 @@
+
+SOURCES := source/objectscript.cpp source/main.cpp
+OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES))
+CXXFLAGS = -Wall -ggdb -O0
+LD = $(CXX)
+
+all: bin/os
+
+bin/os: $(OBJECTS) -ledit -lstdc++ -lm
+ $(LD) $(LDFLAGS) -o $@ $^
+
+clean:
+ $(RM) $(OBJECTS) bin/os
+
46 source/main.cpp
View
@@ -0,0 +1,46 @@
+
+#include "objectscript.h"
+#include <histedit.h>
+#include <stdio.h>
+
+#ifndef OS_HISTORY_SIZE
+#define OS_HISTORY_SIZE 1000
+#endif /* !OS_HISTORY_SIZE */
+
+
+static char*
+prompt_cb(EditLine*)
+{
+ static char promptstr[] = "(os) ";
+ return promptstr;
+}
+
+
+int main(int argc, char *argv[])
+{
+ HistEvent hevent;
+ History *hh(history_init());
+ history(hh, &hevent, H_SETUNIQUE, 1);
+ history(hh, &hevent, H_SETSIZE, OS_HISTORY_SIZE);
+
+ EditLine *el(el_init("os", stdin, stdout, stderr));
+ el_set(el, EL_SIGNAL, 1);
+ el_set(el, EL_EDITOR, "emacs");
+ el_set(el, EL_PROMPT, prompt_cb);
+ el_set(el, EL_HIST, history, hh);
+
+ ObjectScript::OS *shell(ObjectScript::OS::create());
+
+ const char *line = NULL;
+ int linelen = -1;
+
+ while ((line = el_gets(el, &linelen)) && linelen > 0) {
+ shell->eval(line);
+ history(hh, &hevent, H_ENTER, line);
+ }
+
+ el_end(el);
+ history_end(hh);
+ shell->release();
+}
+
6 source/objectscript.cpp
View
@@ -8345,7 +8345,7 @@ int OS::Core::PropertyIndex::getHash() const
return index.v.string->hash;
}
// all other values share same area with index.v.value so just use it as hash
- return (int)index.v.value;
+ return (ptrdiff_t) index.v.value;
}
// =====================================================================
@@ -15995,8 +15995,8 @@ void OS::initGlobalFunctions()
void OS::initObjectClass()
{
- static int iterator_crc = (int)&iterator_crc;
- static int array_iter_num_crc = (int)&array_iter_num_crc;
+ static intptr_t iterator_crc = (intptr_t)&iterator_crc;
+ static intptr_t array_iter_num_crc = (intptr_t)&array_iter_num_crc;
struct Object
{
Something went wrong with that request. Please try again.