summaryrefslogtreecommitdiff
path: root/symbian/PerlBase.h
blob: a2dbcf6212fbe7eab8a4df2aab9da652a8f3d053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Copyright (c) 2004-2005 Nokia. All rights reserved. */

/* The CPerlBase class is licensed under the same terms as Perl itself. */

/* See PerlBase.pod for documentation. */

#ifndef __PerlBase_h__
#define __PerlBase_h__

#include <e32base.h>

#if !defined(PERL_MINIPERL) && !defined(PERL_PERL)
#  ifndef PERL_IMPLICIT_CONTEXT
#    define PERL_IMPLICIT_CONTEXT
#  endif
#  ifndef PERL_MULTIPLICITY
#    define PERL_MULTIPLICITY
#  endif
#  ifndef PERL_GLOBAL_STRUCT
#    define PERL_GLOBAL_STRUCT
#  endif
#  ifndef PERL_GLOBAL_STRUCT_PRIVATE
#    define PERL_GLOBAL_STRUCT_PRIVATE
#  endif
#endif

#include "EXTERN.h"
#include "perl.h"

typedef enum {
   EPerlNone,
   EPerlAllocated,
   EPerlConstructed,
   EPerlParsed,
   EPerlRunning,
   EPerlTerminated,
   EPerlPaused,
   EPerlSuccess,
   EPerlFailure,
   EPerlDestroying
} TPerlState;

class PerlConsole;

class CPerlBase : public CBase
{
  public:
    CPerlBase();
    IMPORT_C virtual ~CPerlBase();
    IMPORT_C static CPerlBase* NewInterpreterL(TBool aCloseStdlib = ETrue,
                                               void (*aStdioInitFunc)(void*) = NULL,
                                               void *aStdioInitCookie = NULL);
    IMPORT_C static CPerlBase* NewInterpreterLC(TBool iCloseStdlib = ETrue,
                                                void (*aStdioInitFunc)(void*) = NULL,
                                                void *aStdioInitCookie = NULL);
    IMPORT_C TInt RunScriptL(const TDesC& aFileName, int argc = 2, char **argv = NULL, char *envp[] = NULL);
    IMPORT_C int  Parse(int argc = 0, char *argv[] = NULL, char *envp[] = NULL);
    IMPORT_C void SetupExit();
    IMPORT_C int  Run();
    IMPORT_C int  ParseAndRun(int argc = 0, char *argv[] = 0, char *envp[] = 0);
    IMPORT_C void Destruct();

    IMPORT_C PerlInterpreter* GetInterpreter();

    // These two really should be private but when not using PERLIO
    // certain C callback functions of STDLIB need to be able to call
    // these.  In general, all the console related functionality is
    // intentionally hidden and underdocumented.
    int               ConsoleRead(const int fd, char* buf, int n);
    int               ConsoleWrite(const int fd, const char* buf, int n);

    // Having these public does not feel right, but maybe someone needs
    // to do creative things with them.
    int               (*iReadFunc)(const int fd, char *buf, int n);
    int               (*iWriteFunc)(const int fd, const char *buf, int n);

   protected:
    PerlInterpreter*  iPerl;
#ifdef PERL_GLOBAL_STRUCT
    struct perl_vars* iVars;
#else
    void*             iAppCtx;
#endif
    TPerlState        iState;

   private:
    void              ConstructL();
    CConsoleBase*     iConsole;		/* The screen. */
    TUint16*          iConsoleBuffer;	/* The UTF-16 characters. */
    TUint             iConsoleUsed;	/* How many in iConsoleBuffer. */
    TBool             iCloseStdlib;	/* Close STDLIB on exit? */

    void              (*iStdioInitFunc)(void *);
    void*             iStdioInitCookie;

    int               ConsoleReadLine();
    void              StdioRewire(void*);
};

#define diTHX PerlInterpreter*  my_perl = iPerl
#define diVAR struct perl_vars* my_vars = iVars

#ifdef PERL_GLOBAL_STRUCT
#  define PERL_APPCTX_SET(c) ((c)->iVars->Gappctx = (c))
#else
#  define PERL_APPCTX_SET(c) (PL_appctx = (c))
#endif

#undef Copy
#undef CopyD /* For symmetry, not for Symbian reasons. */
#undef New
#define PerlCopy(s,d,n,t)	(MEM_WRAP_CHECK(n,t), (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t)))
#define PerlCopyD(s,d,n,t)	(MEM_WRAP_CHECK(n,t), memcpy((char*)(d),(char*)(s), (n) * sizeof(t)))
#define PerlNew(x,v,n,t)	(v = (MEM_WRAP_CHECK(n,t), (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))))

// This is like the Symbian _LIT() but without the embedded L prefix,
// which enables using #defined constants (which need to carry their
// own L prefix).
#ifndef _LIT_NO_L
# define _LIT_NO_L(n, s) static const TLitC<sizeof(s)/2> n={sizeof(s)/2-1,s}
#endif // #ifndef _LIT_NO_L

#endif /* #ifndef __PerlBase_h__ */