Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix-related fixes and basic interactive interpreter #6

Merged
merged 4 commits into from Oct 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@
*.vcxproj.user *.vcxproj.user
*.osd *.osd
*.osc *.osc
*.o
14 changes: 14 additions & 0 deletions Makefile
@@ -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 changes: 46 additions & 0 deletions source/main.cpp
@@ -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 changes: 3 additions & 3 deletions source/objectscript.cpp
Expand Up @@ -8345,7 +8345,7 @@ int OS::Core::PropertyIndex::getHash() const
return index.v.string->hash; return index.v.string->hash;
} }
// all other values share same area with index.v.value so just use it as 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;
} }


// ===================================================================== // =====================================================================
Expand Down Expand Up @@ -15995,8 +15995,8 @@ void OS::initGlobalFunctions()


void OS::initObjectClass() void OS::initObjectClass()
{ {
static int iterator_crc = (int)&iterator_crc; static intptr_t iterator_crc = (intptr_t)&iterator_crc;
static int array_iter_num_crc = (int)&array_iter_num_crc; static intptr_t array_iter_num_crc = (intptr_t)&array_iter_num_crc;


struct Object struct Object
{ {
Expand Down