Recovered from cvs revision 2007-05-08 07:48:00

This commit is contained in:
hyung-hwan 2007-05-09 00:09:00 +00:00
parent 8d1d47e26f
commit 3fc43518d1
6 changed files with 173 additions and 68 deletions

View File

@ -1,8 +1,9 @@
/*
* $Id: Awk.cpp,v 1.11 2007/05/06 10:38:22 bacon Exp $
* $Id: Awk.cpp,v 1.13 2007/05/07 09:30:28 bacon Exp $
*/
#include <ase/awk/Awk.hpp>
#include <ase/awk/val.h>
#include <ase/cmn/str.h>
#include <ase/cmn/mem.h>
@ -118,9 +119,9 @@ namespace ASE
ase_awk_prmfns_t prmfns;
prmfns.mmgr.malloc = malloc;
prmfns.mmgr.realloc = realloc;
prmfns.mmgr.free = free;
prmfns.mmgr.malloc = allocMem;
prmfns.mmgr.realloc = reallocMem;
prmfns.mmgr.free = freeMem;
prmfns.mmgr.custom_data = this;
prmfns.ccls.is_upper = isUpper;
@ -138,11 +139,6 @@ namespace ASE
prmfns.ccls.to_lower = toLower;
prmfns.ccls.custom_data = this;
/*
int (Awk::*ptr) (void*, ase_char_t*, ase_size_t, const ase_char_t*, ...) = &Awk::sprintf;
(this->*ptr) (ASE_NULL, ASE_NULL, 0, ASE_NULL);
*/
prmfns.misc.pow = pow;
prmfns.misc.sprintf = sprintf;
prmfns.misc.dprintf = dprintf;
@ -183,7 +179,8 @@ namespace ASE
}
}
int Awk::dispatchFunction (const char_t* name, size_t len)
int Awk::dispatchFunction (
ase_awk_run_t* run, const char_t* name, size_t len)
{
ase_awk_pair_t* pair;
@ -193,7 +190,49 @@ namespace ASE
FunctionHandler handler;
handler = *(FunctionHandler*)ASE_AWK_PAIR_VAL(pair);
return (this->*handler) ();
size_t i, nargs = ase_awk_getnargs(run);
Value** args = new Value* [nargs];
for (i = 0; i < nargs; i++)
{
ase_awk_val_t* v = ase_awk_getarg (run, i);
Value* obj = ASE_NULL;
switch (v->type)
{
case ASE_AWK_VAL_INT:
obj = new IntValue (
((ase_awk_val_int_t*)v)->val);
break;
case ASE_AWK_VAL_REAL:
obj = new RealValue (
((ase_awk_val_real_t*)v)->val);
break;
case ASE_AWK_VAL_STR:
obj = new StrValue (
((ase_awk_val_str_t*)v)->buf,
((ase_awk_val_str_t*)v)->len);
break;
case ASE_AWK_VAL_NIL:
obj = new NilValue ();
break;
}
}
Value* ret = (this->*handler) (nargs, args);
for (i = 0; i < nargs; i++) delete args[i];
delete[] args;
if (ret == ASE_NULL) return -1;
// TODO: convert the return value to normal value...
return 0;
}
int Awk::addFunction (
@ -202,8 +241,8 @@ namespace ASE
{
ASE_ASSERT (awk != ASE_NULL);
FunctionHandler* tmp;
tmp = (FunctionHandler*)this->malloc (ASE_SIZEOF(handler));
FunctionHandler* tmp = (FunctionHandler*)
ase_awk_malloc (awk, ASE_SIZEOF(handler));
if (tmp == ASE_NULL)
{
// TODO: SET ERROR INFO -> ENOMEM
@ -220,7 +259,7 @@ namespace ASE
functionHandler);
if (p == ASE_NULL)
{
this->free (tmp);
ase_awk_free (awk, tmp);
return -1;
}
@ -230,7 +269,7 @@ namespace ASE
{
// TODO: SET ERROR INFO
ase_awk_delbfn (awk, name, nameLen);
this->free (tmp);
ase_awk_free (awk, tmp);
return -1;
}
@ -382,28 +421,28 @@ namespace ASE
ase_awk_run_t* run, const char_t* name, size_t len)
{
Awk* awk = (Awk*) ase_awk_getruncustomdata (run);
return awk->dispatchFunction (name, len);
return awk->dispatchFunction (run, name, len);
}
void Awk::freeFunctionMapValue (void* owner, void* value)
{
Awk* awk = (Awk*)owner;
awk->free (value);
ase_awk_free (awk->awk, value);
}
void* Awk::malloc (void* custom, size_t n)
void* Awk::allocMem (void* custom, size_t n)
{
return ((Awk*)custom)->malloc (n);
return ((Awk*)custom)->allocMem (n);
}
void* Awk::realloc (void* custom, void* ptr, size_t n)
void* Awk::reallocMem (void* custom, void* ptr, size_t n)
{
return ((Awk*)custom)->realloc (ptr, n);
return ((Awk*)custom)->reallocMem (ptr, n);
}
void Awk::free (void* custom, void* ptr)
void Awk::freeMem (void* custom, void* ptr)
{
((Awk*)custom)->free (ptr);
((Awk*)custom)->freeMem (ptr);
}
Awk::bool_t Awk::isUpper (void* custom, cint_t c)

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.10 2007/05/06 10:38:22 bacon Exp $
* $Id: Awk.hpp,v 1.12 2007/05/07 09:30:28 bacon Exp $
*/
#ifndef _ASE_AWK_AWK_HPP_
@ -9,16 +9,6 @@
#include <ase/awk/map.h>
#include <stdarg.h>
#ifdef malloc
#undef malloc
#endif
#ifdef realloc
#undef realloc
#endif
#ifdef free
#undef free
#endif
namespace ASE
{
@ -30,6 +20,7 @@ namespace ASE
typedef ase_cint_t cint_t;
typedef ase_size_t size_t;
typedef ase_ssize_t ssize_t;
typedef ase_long_t long_t;
typedef ase_real_t real_t;
class Source
@ -118,6 +109,47 @@ namespace ASE
Mode mode;
};
class Value
{
public:
};
class NilValue: public Value
{
public:
NilValue ();
protected:
};
class StrValue: public Value
{
public:
StrValue (const char_t* ptr, size_t len);
protected:
char_t* ptr;
size_t len;
};
class RealValue: public Value
{
public:
RealValue (real_t v);
protected:
real_t value;
};
class IntValue: public Value
{
public:
IntValue (long_t v);
protected:
long_t value;
};
Awk ();
virtual ~Awk ();
@ -128,7 +160,7 @@ namespace ASE
virtual int run (const char_t* main = ASE_NULL,
const char_t** args = ASE_NULL);
typedef int (Awk::*FunctionHandler) ();
typedef Value* (Awk::*FunctionHandler) (size_t nargs, Value** args);
virtual int addFunction (
const char_t* name, size_t minArgs, size_t maxArgs,
@ -137,7 +169,8 @@ namespace ASE
protected:
virtual int dispatchFunction (const char_t* name, size_t len);
virtual int dispatchFunction (
ase_awk_run_t* run, const char_t* name, size_t len);
// source code io handlers
virtual int openSource (Source& io) = 0;
@ -177,9 +210,9 @@ namespace ASE
*/
// primitive handlers
virtual void* malloc (size_t n) = 0;
virtual void* realloc (void* ptr, size_t n) = 0;
virtual void free (void* ptr) = 0;
virtual void* allocMem (size_t n) = 0;
virtual void* reallocMem (void* ptr, size_t n) = 0;
virtual void freeMem (void* ptr) = 0;
virtual bool_t isUpper (cint_t c) = 0;
virtual bool_t isLower (cint_t c) = 0;
@ -217,9 +250,9 @@ namespace ASE
ase_awk_run_t* run, const char_t* name, size_t len);
static void freeFunctionMapValue (void* owner, void* value);
static void* malloc (void* custom, size_t n);
static void* realloc (void* custom, void* ptr, size_t n);
static void free (void* custom, void* ptr);
static void* allocMem (void* custom, size_t n);
static void* reallocMem (void* custom, void* ptr, size_t n);
static void freeMem (void* custom, void* ptr);
static bool_t isUpper (void* custom, cint_t c);
static bool_t isLower (void* custom, cint_t c);

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.cpp,v 1.4 2007/05/06 10:38:22 bacon Exp $
* $Id: StdAwk.cpp,v 1.5 2007/05/07 09:30:28 bacon Exp $
*/
#include <ase/awk/StdAwk.hpp>
@ -16,19 +16,20 @@ namespace ASE
int n = Awk::open ();
if (n == 0)
{
int opt = ASE_AWK_IMPLICIT |
ASE_AWK_EXPLICIT |
ASE_AWK_UNIQUEFN |
ASE_AWK_IDIV |
ASE_AWK_SHADING |
ASE_AWK_SHIFT |
ASE_AWK_EXTIO |
ASE_AWK_BLOCKLESS |
ASE_AWK_STRBASEONE |
ASE_AWK_STRIPSPACES |
ASE_AWK_NEXTOFILE /*|
ASE_AWK_ARGSTOMAIN*/;
ase_awk_setoption (awk, opt);
int opt =
ASE_AWK_IMPLICIT |
ASE_AWK_EXPLICIT |
ASE_AWK_UNIQUEFN |
ASE_AWK_IDIV |
ASE_AWK_SHADING |
ASE_AWK_SHIFT |
ASE_AWK_EXTIO |
ASE_AWK_BLOCKLESS |
ASE_AWK_STRBASEONE |
ASE_AWK_STRIPSPACES |
ASE_AWK_NEXTOFILE /*|
ASE_AWK_ARGSTOMAIN*/;
ase_awk_setoption (awk, opt);
addFunction (ASE_T("sin"), 1, 1, (FunctionHandler)&StdAwk::sin);
addFunction (ASE_T("cos"), 1, 1, (FunctionHandler)&StdAwk::cos);
@ -38,17 +39,17 @@ namespace ASE
return n;
}
int StdAwk::sin ()
StdAwk::Value* StdAwk::sin (size_t nargs, Value** args)
{
return 0;
}
int StdAwk::cos ()
StdAwk::Value* StdAwk::cos (size_t nargs, Value** args)
{
return 0;
}
int StdAwk::tan ()
StdAwk::Value* StdAwk::tan (size_t nargs, Value** args)
{
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.hpp,v 1.3 2007/05/06 06:55:05 bacon Exp $
* $Id: StdAwk.hpp,v 1.4 2007/05/07 09:30:28 bacon Exp $
*/
#ifndef _ASE_AWK_STDAWK_HPP_
@ -18,9 +18,9 @@ namespace ASE
int open ();
protected:
int sin ();
int cos ();
int tan ();
Value* sin (size_t nargs, Value** args);
Value* cos (size_t nargs, Value** args);
Value* tan (size_t nargs, Value** args);
};
}

View File

@ -196,6 +196,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\StdAwk.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
@ -205,6 +209,10 @@
RelativePath="Awk.hpp"
>
</File>
<File
RelativePath=".\StdAwk.hpp"
>
</File>
</Filter>
<Filter
Name="Resource Files"

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.5 2007/05/06 10:38:22 bacon Exp $
* $Id: Awk.cpp,v 1.6 2007/05/07 09:30:28 bacon Exp $
*/
#include <ase/awk/StdAwk.hpp>
@ -116,9 +116,9 @@ protected:
int nextConsole (Console& io) { return 0; }
// primitive operations
void* malloc (size_t n) { return ::malloc (n); }
void* realloc (void* ptr, size_t n) { return ::realloc (ptr, n); }
void free (void* ptr) { ::free (ptr); }
void* allocMem (size_t n) { return ::malloc (n); }
void* reallocMem (void* ptr, size_t n) { return ::realloc (ptr, n); }
void freeMem (void* ptr) { ::free (ptr); }
bool_t isUpper (cint_t c) { return ase_isupper (c); }
bool_t isLower (cint_t c) { return ase_islower (c); }
@ -186,7 +186,7 @@ void ase_assert_printf (const ase_char_t* fmt, ...)
}
#endif
extern "C" int ase_main (int argc, ase_char_t* argv[])
int awk_main (int argc, ase_char_t* argv[])
{
TestAwk awk;
@ -214,3 +214,27 @@ extern "C" int ase_main (int argc, ase_char_t* argv[])
// awk.close ();
return 0;
}
extern "C" int ase_main (int argc, ase_char_t* argv[])
{
int n;
#if defined(__linux) && defined(_DEBUG)
mtrace ();
#endif
n = awk_main (argc, argv);
#if defined(__linux) && defined(_DEBUG)
muntrace ();
#endif
#if defined(_WIN32) && defined(_DEBUG)
#if defined(_MSC_VER)
_CrtDumpMemoryLeaks ();
#endif
_tprintf (_T("Press ENTER to quit\n"));
getchar ();
#endif
return n;
}