Recovered from cvs revision 2007-10-10 03:37:00

This commit is contained in:
hyung-hwan 2007-10-10 16:03:00 +00:00
parent 853d8e8e1e
commit c79702df8e
7 changed files with 128 additions and 85 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.68 2007/10/07 15:27:39 bacon Exp $
* $Id: Awk.cpp,v 1.69 2007/10/08 09:43:15 bacon Exp $
*
* {License}
*/
@ -901,6 +901,16 @@ Awk::Run::~Run ()
{
}
Awk::Run::operator Awk* () const
{
return this->awk;
}
Awk::Run::operator Awk::run_t* () const
{
return this->run;
}
int Awk::Run::stop () const
{
ASE_ASSERT (this->run != ASE_NULL);
@ -1033,6 +1043,11 @@ Awk::~Awk ()
{
}
Awk::operator Awk::awk_t* () const
{
return this->awk;
}
Awk::ErrorCode Awk::getErrorCode () const
{
return this->errnum;

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.69 2007/10/07 15:27:39 bacon Exp $
* $Id: Awk.hpp,v 1.70 2007/10/08 09:43:15 bacon Exp $
*
* {License}
*/
@ -569,6 +569,9 @@ public:
~Run ();
public:
operator Awk* () const;
operator run_t* () const;
int stop () const;
ErrorCode getErrorCode () const;
@ -688,6 +691,9 @@ public:
Awk ();
/** Destructor */
virtual ~Awk ();
/** Returns the underlying handle */
operator awk_t* () const;
/** Returns the error code */
ErrorCode getErrorCode () const;

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.30 2007/10/07 15:27:39 bacon Exp $
* $Id: Awk.cpp,v 1.31 2007/10/08 09:43:15 bacon Exp $
*
* {License}
*/
@ -276,8 +276,12 @@ namespace ASE
Run& run, Return& ret, const Argument* args, size_t nargs,
const char_t* name, size_t len)
{
return wrapper->DispatchFunction (run, ret, args, nargs, name, len)? 0: -1;
System::IntPtr ip ((void*)run.getCustom ());
GCHandle gh = GCHandle::FromIntPtr (ip);
return wrapper->DispatchFunction (
(ASE::Net::Awk::Context^)gh.Target,
ret, args, nargs, name, len)? 0: -1;
}
int openSource (Source& io)
@ -939,7 +943,7 @@ namespace ASE
}
bool Awk::DispatchFunction (
ASE::Awk::Run& run, ASE::Awk::Return& ret,
Context^ ctx, ASE::Awk::Return& ret,
const ASE::Awk::Argument* args, size_t nargs,
const char_t* name, size_t len)
{
@ -949,6 +953,7 @@ namespace ASE
FunctionHandler^ fh = (FunctionHandler^)funcs[nm];
if (fh == nullptr)
{
// TODO: ctx.setError...
setError (ERROR::INVAL);
return false;
}
@ -959,9 +964,9 @@ namespace ASE
size_t i;
for (i = 0; i < nargs; i++)
a[i] = gcnew Argument(args[i]);
a[i] = gcnew Argument(ctx, args[i]);
bool n = fh (nm, a, r);
bool n = fh (ctx, nm, a, r);
while (i > 0) delete a[--i];
delete a;

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp,v 1.34 2007/10/07 15:27:39 bacon Exp $
* $Id: Awk.hpp,v 1.36 2007/10/08 09:50:52 bacon Exp $
*
* {License}
*/
@ -26,22 +26,56 @@ namespace ASE
typedef ASE::Awk::cint_t cint_t;
typedef ASE::Awk::bool_t bool_t;
ref class Context;
ref class Argument
{
public protected:
Argument (const ASE::Awk::Argument& arg): arg(arg)
public:
Argument (Context^ ctx)
{
arg = new((ASE::Awk::awk_t*)(ASE::Awk*)ctx->run) ASE::Awk::Argument (ctx->run);
if (arg == ASE_NULL)
{
throw gcnew System::OutOfMemoryException ("cannot create an instance of ASE::Awk::Argument");
}
arg_new = true;
}
public protected:
Argument (Context^ ctx, const ASE::Awk::Argument& arg):
ctx(ctx), arg((ASE::Awk::Argument*)&arg), arg_new (false)
{
}
public:
~Argument ()
{
if (arg_new && arg != ASE_NULL)
{
delete arg;
arg = ASE_NULL;
}
}
!Argument ()
{
if (arg_new && arg != ASE_NULL)
{
delete arg;
arg = ASE_NULL;
}
}
public:
property long_t LongValue
{
long_t get () { return arg.toInt(); }
long_t get () { return arg->toInt(); }
}
property real_t RealValue
{
real_t get () { return arg.toReal(); }
real_t get () { return arg->toReal(); }
}
property System::String^ StringValue
@ -49,47 +83,21 @@ namespace ASE
System::String^ get ()
{
size_t len;
const char_t* s = arg.toStr(&len);
const char_t* s = arg->toStr(&len);
return gcnew System::String (s, 0, len);
}
}
/*
bool GetIndexedLong (System::String^ idx,
[System::Runtime::InteropServices::Out] long_t% v)
bool GetIndexed (System::String^ idx, [System::Runtime::InteropServices::Out] Argument^% v)
{
ASE::Awk::Argument x;
cli::pin_ptr<const char_t> ip = PtrToStringChars(idx);
if (arg.getIndexed (ip, idx->Length, x) == -1) return false;
v = x.toInt ();
return true;
return arg->getIndexed (ip, idx->Length, *v->arg) == 0;
}
bool GetIndexedReal (System::String^ idx,
[System::Runtime::InteropServices::Out] real_t% v)
{
ASE::Awk::Argument x;
cli::pin_ptr<const char_t> ip = PtrToStringChars(idx);
if (arg.getIndexed (ip, idx->Length, x) == -1) return false;
v = x.toReal ();
return true;
}
bool GetIndexedString (System::String^ idx,
[System::Runtime::InteropServices::Out] System::String^% v)
{
ASE::Awk::Argument x;
cli::pin_ptr<const char_t> ip = PtrToStringChars(idx);
if (arg.getIndexed (ip, idx->Length, x) == -1) return false;
size_t len;
const char_t* s = arg.toStr(&len);
v = gcnew System::String (s, 0, len);
return true;
}*/
protected:
const ASE::Awk::Argument& arg;
public protected:
Context^ ctx;
ASE::Awk::Argument* arg;
bool arg_new;
};
ref class Return
@ -100,6 +108,11 @@ namespace ASE
}
public:
void Clear ()
{
ret.clear ();
}
bool Set (System::String^ v)
{
cli::pin_ptr<const char_t> nptr = PtrToStringChars(v);
@ -250,7 +263,7 @@ namespace ASE
return ret.setIndexed (ip, idx->Length, (long_t)(unsigned __int64)v) == 0;
}
protected:
public protected:
ASE::Awk::Return& ret;
};
@ -333,14 +346,17 @@ namespace ASE
return run.setGlobal (id, (real_t)(double)v) == 0;
}
/*
bool GetGlobal (int id, [System::Runtime::InteropServices::Out] Argument^ v)
bool SetGlobal (int id, Return^ v)
{
return run.getGlobal (id, v->placeHolder) == 0;
return run.setGlobal (id, v->ret) == 0;
}
*/
protected:
bool GetGlobal (int id, [System::Runtime::InteropServices::Out] Argument^% v)
{
return run.getGlobal (id, *v->arg) == 0;
}
public protected:
Awk^ owner;
ASE::Awk::Run& run;
};
@ -661,7 +677,8 @@ namespace ASE
virtual bool DeleteGlobal (System::String^ name);
delegate bool FunctionHandler (
System::String^ name, cli::array<Argument^>^ args, Return^ ret);
Context^ ctx, System::String^ name,
cli::array<Argument^>^ args, Return^ ret);
virtual bool AddFunction (
System::String^ name, int minArgs,
@ -742,7 +759,7 @@ namespace ASE
public protected:
bool Awk::DispatchFunction (
ASE::Awk::Run& run, ASE::Awk::Return& ret,
Context^ ctx, ASE::Awk::Return& ret,
const ASE::Awk::Argument* args, size_t nargs,
const char_t* name, size_t len);

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.cpp,v 1.15 2007/10/03 09:47:07 bacon Exp $
* $Id: StdAwk.cpp,v 1.16 2007/10/08 09:43:15 bacon Exp $
*
* {License}
*/
@ -47,57 +47,57 @@ namespace ASE
{
}
bool StdAwk::Sin (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Sin (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((real_t)System::Math::Sin (args[0]->RealValue));
}
bool StdAwk::Cos (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Cos (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((real_t)System::Math::Cos (args[0]->RealValue));
}
bool StdAwk::Tan (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Tan (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((real_t)System::Math::Tan (args[0]->RealValue));
}
bool StdAwk::Atan (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Atan (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((real_t)System::Math::Atan (args[0]->RealValue));
}
bool StdAwk::Atan2 (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Atan2 (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((real_t)System::Math::Atan2 (args[0]->RealValue, args[1]->RealValue));
}
bool StdAwk::Log (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Log (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((real_t)System::Math::Log (args[0]->RealValue));
}
bool StdAwk::Exp (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Exp (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((real_t)System::Math::Exp (args[0]->RealValue));
}
bool StdAwk::Sqrt (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Sqrt (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((real_t)System::Math::Sqrt (args[0]->RealValue));
}
bool StdAwk::Int (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Int (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set (args[0]->LongValue);
}
bool StdAwk::Rand (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Rand (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((long_t)random->Next ());
}
bool StdAwk::Srand (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Srand (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
int seed = (int)args[0]->LongValue;
System::Random^ tmp = gcnew System::Random (seed);
@ -116,12 +116,12 @@ namespace ASE
#define gmtime _gmtime64
#endif
bool StdAwk::Systime (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Systime (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
return ret->Set ((long_t)::time(NULL));
}
bool StdAwk::Strftime (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Strftime (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
wchar_t buf[128];
struct tm* tm;
@ -148,7 +148,7 @@ namespace ASE
return ret->Set (gcnew System::String (buf, 0, len));
}
bool StdAwk::Strfgmtime (System::String^ name, array<Argument^>^ args, Return^ ret)
bool StdAwk::Strfgmtime (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret)
{
wchar_t buf[128];
struct tm* tm;

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.hpp,v 1.7 2007/09/01 15:43:16 bacon Exp $
* $Id: StdAwk.hpp,v 1.8 2007/10/08 09:43:15 bacon Exp $
*/
#include <ase/net/Awk.hpp>
@ -19,20 +19,20 @@ namespace ASE
int random_seed;
System::Random^ random;
bool Sin (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Cos (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Tan (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Atan (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Atan2 (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Log (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Exp (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Sqrt (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Int (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Rand (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Srand (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Systime (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Strftime (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Strfgmtime (System::String^ name, array<Argument^>^ args, Return^ ret);
bool Sin (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Cos (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Tan (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Atan (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Atan2 (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Log (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Exp (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Sqrt (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Int (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Rand (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Srand (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Systime (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Strftime (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
bool Strfgmtime (Context^ ctx, System::String^ name, array<Argument^>^ args, Return^ ret);
public protected:
// File

View File

@ -42,7 +42,7 @@ namespace ase.net
return base.Run (main, args);
}
protected bool Sleep(string name, Argument[] args, Return ret)
protected bool Sleep(Context ctx, string name, Argument[] args, Return ret)
{
System.Threading.Thread.Sleep((int)(args[0].LongValue*1000));
return ret.Set(0);