Added Scilab function runVMKit to be used to change how the AST is visited.
Peter Senna Tschudin [Tue, 28 May 2013 13:31:59 +0000 (15:31 +0200)]
Change-Id: Ib46b82e4ef8298b7b9b967a52dc66e0453b5fd5e

scilab/modules/core/Makefile.am
scilab/modules/core/includes/core_gw.hxx
scilab/modules/core/includes/tasks.hxx
scilab/modules/core/includes/vmkit_core.h [new file with mode: 0644]
scilab/modules/core/sci_gateway/cpp/core_gw.cpp
scilab/modules/core/sci_gateway/cpp/sci_runASTwithVMKit.cpp [new file with mode: 0644]
scilab/modules/core/src/cpp/scilab.cpp
scilab/modules/core/src/cpp/tasks.cpp

index a809b9c..13275f2 100644 (file)
@@ -137,7 +137,10 @@ GATEWAY_C_SOURCES = \
        sci_gateway/c/gw_user2.c \
        sci_gateway/c/sci_type.c \
        sci_gateway/c/sci_getdebuginfo.c \
-       sci_gateway/c/sci_readgateway.c
+       sci_gateway/c/gw_user2.c \
+       sci_gateway/c/sci_getvariablesonstack.c \
+       sci_gateway/c/sci_readgateway.c \
+       sci_gateway/c/sci_comp.c
 
 GATEWAY_FORTRAN_SOURCES =  \
 sci_gateway/fortran/where.f
@@ -174,6 +177,11 @@ GATEWAY_CPP_SOURCES =      \
        sci_gateway/cpp/sci_typename.cpp \
        sci_gateway/cpp/sci_where.cpp \
        sci_gateway/cpp/sci_getmemory.cpp
+       sci_gateway/cpp/sci_format.cpp \
+       sci_gateway/cpp/sci_sciargs.cpp \
+       sci_gateway/cpp/sci_ieee.cpp \
+       sci_gateway/cpp/sci_funcprot.cpp \
+       sci_gateway/cpp/sci_runASTwithVMKit.cpp
 
 
 libscicore_la_CPPFLAGS = \
index c2afe2a..a40bb51 100644 (file)
@@ -57,5 +57,6 @@ CPP_GATEWAY_PROTOTYPE(sci_mode);
 CPP_GATEWAY_PROTOTYPE(sci_typename);
 CPP_GATEWAY_PROTOTYPE(sci_where);
 CPP_GATEWAY_PROTOTYPE(sci_getmemory);
+CPP_GATEWAY_PROTOTYPE(sci_runVMKit);
 
 #endif /* __CORE_GW_HXX__ */
index 5e752ac..5ac5ec8 100644 (file)
@@ -48,7 +48,7 @@ void printAstTask(ast::Exp *tree, bool timed);
 **
 ** Execute the stored AST.
 */
-void execAstTask(ast::Exp *tree, bool timed, bool ASTtimed, bool execVerbose);
+void execAstTask(ast::Exp *tree, bool timed, bool ASTtimed, bool execVerbose, bool ASTrunVMKit);
 
 /*
 ** Exec Tree with original visitor ( without template )
diff --git a/scilab/modules/core/includes/vmkit_core.h b/scilab/modules/core/includes/vmkit_core.h
new file mode 100644 (file)
index 0000000..0af011c
--- /dev/null
@@ -0,0 +1,75 @@
+#include "MutatorThread.h"
+#include "vmkit/System.h"
+#include "vmkit/Locks.h"
+#include "vmkit/Thread.h"
+#include "vmkit/VirtualMachine.h"
+
+namespace VMKitScilab
+{
+class ScilabVM;
+
+class ScilabThread : public vmkit::MutatorThread
+{
+private:
+    int argc, iFileIndex, iLangIndex, ret;
+    char **argv;
+
+public:
+    void setArgs(int argc, char** argv, int iFileIndex, int iLangIndex);
+    void setret(int ret);
+    int getargc();
+    int getiFileIndex();
+    int getiLangIndex();
+    char **getargv();
+    int getret();
+
+    ScilabThread (ScilabVM* vm);
+    ScilabVM* vm();
+    void execute();
+};
+
+class ScilabVM : public vmkit::VirtualMachine
+{
+private:
+    int ret;
+
+public:
+    vmkit::BumpPtrAllocator Alloc;
+    vmkit::CompiledFrames **frames;
+
+    ScilabVM (vmkit::BumpPtrAllocator& Alloc, vmkit::CompiledFrames** frames) : VirtualMachine(Alloc, frames) {}
+    ~ScilabVM() {}
+
+    virtual void startCollection() {}
+    virtual void endCollection() {}
+    virtual void scanWeakReferencesQueue(word_t closure) {}
+    virtual void scanSoftReferencesQueue(word_t closure) {}
+    virtual void scanPhantomReferencesQueue(word_t closure) {}
+    virtual void scanFinalizationQueue(word_t closure) {}
+    virtual void addFinalizationCandidate(gc* obj) {}
+    virtual void finalizeObject(gc* res) {}
+    virtual void traceObject(gc* obj, word_t closure) {}
+    virtual void setType(gc* header, void* type) {}
+    virtual void setType(void* header, void* type) {}
+    virtual void* getType(gc* obj) {}
+    virtual size_t getObjectSize(gc* obj) {}
+    virtual const char* getObjectTypeName(gc* obj) {}
+    virtual bool isCorruptedType(gc* header) {}
+    virtual void printMethod(vmkit::FrameInfo* FI, word_t ip, word_t addr) {}
+    virtual void invokeEnqueueReference(gc* res) {}
+    virtual void clearObjectReferent(gc* ref) {}
+    virtual gc** getObjectReferentPtr(gc* _obj) {}
+    virtual void setObjectReferent(gc* _obj, gc* val) {}
+
+    virtual void runApplication(int argc, char** argv) {}
+
+    virtual void runApplication(int argc, char**  argv, int iFileIndex, int iLangIndex);
+
+    virtual void nullPointerException() {}
+    virtual void stackOverflowError() {}
+
+    static void mainStart(ScilabThread* thread);
+    int getret();
+    void setret(int ret);
+};
+}
index 14ab867..2e9f2ac 100644 (file)
@@ -56,5 +56,6 @@ int CoreModule::Load()
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"mode", &sci_mode, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"where", &sci_where, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"getmemory", &sci_getmemory, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"runVMKit", &sci_runVMKit, MODULE_NAME));
     return 1;
 }
diff --git a/scilab/modules/core/sci_gateway/cpp/sci_runASTwithVMKit.cpp b/scilab/modules/core/sci_gateway/cpp/sci_runASTwithVMKit.cpp
new file mode 100644 (file)
index 0000000..75fd251
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2007 - INRIA - Allan CORNET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+#include "funcmanager.hxx"
+#include "context.hxx"
+#include "core_gw.hxx"
+#include "string.hxx"
+
+extern "C"
+{
+#include "sci_mode.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "sci_mode.h"
+#include "os_strdup.h"
+}
+
+// Defined at modules/core/src/cpp/scilab.cpp
+extern bool ASTrunVMKit;
+
+/*--------------------------------------------------------------------------*/
+
+using namespace types;
+
+Function::ReturnValue sci_runVMKit(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    Scierror(999, _("Comming soon...\n"));
+
+    ASTrunVMKit = true;
+
+    return Function::OK;
+}
+/*--------------------------------------------------------------------------*/
index acf0c01..f329172 100644 (file)
@@ -35,7 +35,7 @@ extern "C"
 #include "scilabWrite.hxx"
 
 #if defined(VMKIT_ENABLED)
-#include <vmkit.h>
+#include <vmkit_core.h>
 #endif
 
 #define INTERACTIVE     -1
@@ -81,6 +81,14 @@ static int get_option(const int argc, char *argv[], ScilabEngineInfo* _pSEI)
     std::cerr << "-*- Getting Options -*-" << std::endl;
 #endif
 
+    bool execFile = false;
+    bool parseFile = false;
+
+    bool ASTrunVMKit = false;
+
+    using symbol::Context;
+    using std::string;
+
     for (i = 1; i < argc; ++i)
     {
         if (!strcmp("--parse-trace", argv[i]))
@@ -147,6 +155,9 @@ static int get_option(const int argc, char *argv[], ScilabEngineInfo* _pSEI)
             if (argc >= i)
             {
                 _pSEI->pstLang = argv[i];
+                //before calling YaspReader, try to call %onprompt function
+                callOnPrompt();
+                execAstTask(parser->getTree(), timed, ASTtimed, execVerbose, ASTrunVMKit);
             }
         }
         else if (!strcmp("-nw", argv[i]))
@@ -169,7 +180,8 @@ static int get_option(const int argc, char *argv[], ScilabEngineInfo* _pSEI)
     }
 
 #ifdef DEBUG
-    if (*_piFileIndex >= 0) {
+    if (*_piFileIndex >= 0)
+    {
         std::cerr << "File : " << argv[*_piFileIndex] << std::endl;
     }
 #endif
index f964150..3670ad4 100644 (file)
@@ -29,6 +29,9 @@
 
 Timer _timer;
 
+// Defined at modules/core/src/cpp/scilab.cpp
+extern bool ASTrunVMKit;
+
 //#define DEBUG
 
 /*
@@ -133,7 +136,7 @@ void printAstTask(ast::Exp *tree, bool timed)
 **
 ** Execute the stored AST.
 */
-void execAstTask(ast::Exp* tree, bool timed, bool ASTtimed, bool execVerbose)
+void execAstTask(ast::Exp* tree, bool timed, bool ASTtimed, bool execVerbose, bool ASTrunVMKit)
 {
     if (tree == NULL)
     {
@@ -161,8 +164,16 @@ void execAstTask(ast::Exp* tree, bool timed, bool ASTtimed, bool execVerbose)
         exec = new ast::ExecVisitor();
     }
 
-    Runner::execAndWait(tree, exec);
-    //delete exec;
+    if (ASTrunVMKit)
+    {
+        printf("VMKit implementation goes here\n");
+        exit(1);
+    }
+    else
+    {
+        Runner::execAndWait(tree, exec);
+        //delete exec;
+    }
 
     if (timed)
     {
@@ -209,7 +220,7 @@ void execScilabStartTask(void)
         return;
     }
 
-    execAstTask(parse.getTree(), false, false, false);
+    execAstTask(parse.getTree(), false, false, false, ASTrunVMKit);
 }
 
 /*
@@ -231,7 +242,7 @@ void execScilabQuitTask(void)
         return;
     }
 
-    execAstTask(parse.getTree(), false, false, false);
+    execAstTask(parse.getTree(), false, false, false, ASTrunVMKit);
 }