*** empty log message ***

This commit is contained in:
hyung-hwan 2007-01-16 06:09:07 +00:00
parent 596059efb5
commit 1b157a3e8d
5 changed files with 149 additions and 42 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.17 2007-01-14 15:06:58 bacon Exp $ * $Id: Awk.cpp,v 1.18 2007-01-16 06:09:07 bacon Exp $
*/ */
#include "stdafx.h" #include "stdafx.h"
@ -37,7 +37,8 @@ CAwk::CAwk ():
write_src_buf (NULL), write_src_buf (NULL),
write_extio_buf (NULL), write_extio_buf (NULL),
entry_point (NULL), entry_point (NULL),
debug (FALSE) debug (FALSE),
use_longlong (FALSE)
{ {
/* TODO: what is the best default option? */ /* TODO: what is the best default option? */
option = option =
@ -271,7 +272,7 @@ static int __handle_bfn (
{ {
ase_char_t buf[128]; ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf), _sntprintf (buf, ASE_COUNTOF(buf),
_T("out of memory in create argument array for %.*s\n"), _T("out of memory in creating argument array for '%.*s'\n"),
fnl, fnm); fnl, fnm);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
return -1; return -1;
@ -287,11 +288,17 @@ static int __handle_bfn (
if (v->type == ASE_AWK_VAL_INT) if (v->type == ASE_AWK_VAL_INT)
{ {
//arg.vt = VT_I8; if (awk->use_longlong)
//arg.llVal = ((ase_awk_val_int_t*)v)->val; {
arg.vt = VT_I8;
arg.llVal = ((ase_awk_val_int_t*)v)->val;
}
else
{
arg.vt = VT_I4; arg.vt = VT_I4;
arg.lVal = (LONG)((ase_awk_val_int_t*)v)->val; arg.lVal = (LONG)((ase_awk_val_int_t*)v)->val;
} }
}
else if (v->type == ASE_AWK_VAL_REAL) else if (v->type == ASE_AWK_VAL_REAL)
{ {
arg.vt = VT_R8; arg.vt = VT_R8;
@ -307,6 +314,12 @@ static int __handle_bfn (
{ {
VariantClear (&arg); VariantClear (&arg);
SafeArrayDestroy (aa); SafeArrayDestroy (aa);
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
_T("out of memory in handling '%.*s'\n"),
fnl, fnm);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
return -1; return -1;
} }
@ -324,7 +337,11 @@ static int __handle_bfn (
VariantClear (&arg); VariantClear (&arg);
SafeArrayDestroy (aa); SafeArrayDestroy (aa);
/* TODO: handle error properly */ ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
_T("out of memory in handling '%.*s'\n"),
fnl, fnm);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
return -1; return -1;
} }
@ -334,17 +351,52 @@ static int __handle_bfn (
BSTR name = SysAllocStringLen (fnm, fnl); BSTR name = SysAllocStringLen (fnm, fnl);
if (name == NULL) if (name == NULL)
{ {
/* TODO: handle error properly */
SafeArrayDestroy (aa); SafeArrayDestroy (aa);
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
_T("out of memory in handling '%.*s'\n"),
fnl, fnm);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
return -1; return -1;
} }
INT n = awk->Fire_HandleBuiltinFunction (name, aa); ase_awk_val_t* ret;
int n = awk->Fire_HandleBuiltinFunction (run, name, aa, &ret);
if (n == 1)
{
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
_T("out of memory in handling '%.*s'\n"),
fnl, fnm);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
return -1;
}
else if (n == 2)
{
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
_T("no handler for '%.*s'\n"),
fnl, fnm);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
return -1;
}
else if (n == 3)
{
ase_char_t buf[128];
_sntprintf (buf, ASE_COUNTOF(buf),
_T("return value not supported for '%.*s'\n"),
fnl, fnm);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf);
return -1;
}
/* name and aa are destroyed in HandleBuiltinFunction */ /* name and aa are destroyed in HandleBuiltinFunction */
//SafeArrayDestroy (aa); //SafeArrayDestroy (aa);
//SysFreeString (name); //SysFreeString (name);
ase_awk_setretval (run, ret);
return 0; return 0;
} }
@ -412,7 +464,10 @@ HRESULT CAwk::Parse (int* ret)
ASE_AWK_DEPTH_REX_MATCH, max_depth.rex.match); ASE_AWK_DEPTH_REX_MATCH, max_depth.rex.match);
} }
ase_awk_addbfn (handle, _T("abc"), 3, 0, 5, 5, ASE_NULL, __handle_bfn); ase_awk_addbfn (handle, _T("sin"), 3, 0, 1, 1, ASE_NULL, __handle_bfn);
ase_awk_addbfn (handle, _T("cos"), 3, 0, 1, 1, ASE_NULL, __handle_bfn);
ase_awk_addbfn (handle, _T("tan"), 3, 0, 1, 1, ASE_NULL, __handle_bfn);
/* /*
for (each buitlin function name... ) for (each buitlin function name... )
{ {
@ -1040,3 +1095,15 @@ STDMETHODIMP CAwk::put_Debug(BOOL newVal)
debug = newVal; debug = newVal;
return S_OK; return S_OK;
} }
STDMETHODIMP CAwk::get_UseLongLong(BOOL *pVal)
{
*pVal = use_longlong;
return S_OK;
}
STDMETHODIMP CAwk::put_UseLongLong(BOOL newVal)
{
use_longlong = newVal;
return S_OK;
}

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.h,v 1.11 2007-01-14 15:06:58 bacon Exp $ * $Id: Awk.h,v 1.12 2007-01-16 06:09:07 bacon Exp $
*/ */
#ifndef _ASE_COM_AWK_H_ #ifndef _ASE_COM_AWK_H_
@ -11,9 +11,9 @@
#include "resource.h" #include "resource.h"
#include "ase.h" #include "ase.h"
#include "awk_cp.h"
#include <ase/awk/awk.h> #include <ase/awk/awk.h>
#include <ase/awk/val.h> #include <ase/awk/val.h>
#include "awk_cp.h"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// CAwk // CAwk
@ -64,6 +64,7 @@ public:
BSTR entry_point; BSTR entry_point;
BOOL debug; BOOL debug;
BOOL use_longlong;
public: public:
CAwk(); CAwk();
~CAwk (); ~CAwk ();
@ -91,6 +92,8 @@ DECLARE_REGISTRY_RESOURCEID(IDR_AWK)
// IAwk // IAwk
public: public:
STDMETHOD(get_UseLongLong)(/*[out, retval]*/ BOOL *pVal);
STDMETHOD(put_UseLongLong)(/*[in]*/ BOOL newVal);
STDMETHOD(get_Debug)(/*[out, retval]*/ BOOL *pVal); STDMETHOD(get_Debug)(/*[out, retval]*/ BOOL *pVal);
STDMETHOD(put_Debug)(/*[in]*/ BOOL newVal); STDMETHOD(put_Debug)(/*[in]*/ BOOL newVal);
STDMETHOD(get_EntryPoint)(/*[out, retval]*/ BSTR *pVal); STDMETHOD(get_EntryPoint)(/*[out, retval]*/ BSTR *pVal);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: ase.idl,v 1.12 2007-01-14 15:06:58 bacon Exp $ * $Id: ase.idl,v 1.13 2007-01-16 06:09:07 bacon Exp $
*/ */
import "oaidl.idl"; import "oaidl.idl";
@ -137,6 +137,11 @@ interface IAwk : IDispatch
HRESULT Debug([out, retval] BOOL *pVal); HRESULT Debug([out, retval] BOOL *pVal);
[propput, id(27), helpstring("property Debug")] [propput, id(27), helpstring("property Debug")]
HRESULT Debug([in] BOOL newVal); HRESULT Debug([in] BOOL newVal);
[propget, id(28), helpstring("property UseLongLong")]
HRESULT UseLongLong([out, retval] BOOL *pVal);
[propput, id(28), helpstring("property UseLongLong")]
HRESULT UseLongLong([in] BOOL newVal);
}; };
/* ASELib */ /* ASELib */
@ -259,7 +264,7 @@ library ASELib
int NextExtio([in] IAwkExtio* extio); int NextExtio([in] IAwkExtio* extio);
[id(11), helpstring("method HandleBuiltinFunction")] [id(11), helpstring("method HandleBuiltinFunction")]
int HandleBuiltinFunction([in] BSTR name, [in] VARIANT argarray); int HandleBuiltinFunction([in] BSTR name, [in] VARIANT argarray, [out, retval] VARIANT* ret);
}; };
/* Awk */ /* Awk */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk_cp.h,v 1.6 2007-01-14 15:06:58 bacon Exp $ * $Id: awk_cp.h,v 1.7 2007-01-16 06:09:07 bacon Exp $
*/ */
#ifndef _AWK_CP_H_ #ifndef _AWK_CP_H_
@ -504,13 +504,14 @@ public:
return -1; return -1;
} }
int Fire_HandleBuiltinFunction (
INT Fire_HandleBuiltinFunction (BSTR name, SAFEARRAY* argarray) ase_awk_run_t* run, BSTR name, SAFEARRAY* argarray, ase_awk_val_t** retv)
{ {
T* pT = static_cast<T*>(this); T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize(); int i, nconns = m_vec.GetSize();
CComVariant ret; CComVariant ret;
VARIANT args[2]; VARIANT args[2];
ase_awk_val_t* v;
VariantInit (&args[0]); VariantInit (&args[0]);
VariantInit (&args[1]); VariantInit (&args[1]);
@ -545,25 +546,48 @@ public:
continue; continue;
} }
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
VariantClear (&args[1]); VariantClear (&args[1]);
VariantClear (&args[0]); VariantClear (&args[0]);
return -1;
if (ret.vt == VT_I1)
v = ase_awk_makeintval (run, ret.cVal);
else if (ret.vt == VT_I2)
v = ase_awk_makeintval (run, ret.iVal);
else if (ret.vt == VT_I4)
v = ase_awk_makeintval (run, ret.lVal);
else if (ret.vt == VT_I8)
v = ase_awk_makeintval (run, ret.llVal);
else if (ret.vt == VT_UI1)
v = ase_awk_makeintval (run, ret.bVal);
else if (ret.vt == VT_UI2)
v = ase_awk_makeintval (run, ret.uiVal);
else if (ret.vt == VT_UI4)
v = ase_awk_makeintval (run, ret.ulVal);
else if (ret.vt == VT_UI8)
v = ase_awk_makeintval (run, ret.ullVal);
else if (ret.vt == VT_INT)
v = ase_awk_makeintval (run, ret.intVal);
else if (ret.vt == VT_UINT)
v = ase_awk_makeintval (run, ret.uintVal);
else if (ret.vt == VT_BOOL)
v = ase_awk_makeintval (run, ((ret.boolVal == 0)? 0: 1));
else if (ret.vt == VT_R4)
v = ase_awk_makerealval (run, ret.fltVal);
else if (ret.vt == VT_R8)
v = ase_awk_makerealval (run, ret.dblVal);
else if (ret.vt == VT_BSTR)
v = ase_awk_makestrval (run, ret.bstrVal, SysStringLen(ret.bstrVal));
else return 3; /* wrong return value */
if (v == ASE_NULL) return 1; /* out of memory */
*retv = v;
return 0; /* success */
} }
VariantClear (&args[1]); VariantClear (&args[1]);
VariantClear (&args[0]); VariantClear (&args[0]);
return ret.lVal; return 2; /* no proper handler */
}
/* TODO; clear name and aa */
VariantClear (&args[1]);
VariantClear (&args[0]);
return -1;
} }

View File

@ -172,6 +172,8 @@ Private Sub Execute_Click()
'Awk.MaxDepthForRexBuild = 10 'Awk.MaxDepthForRexBuild = 10
'Awk.MaxDepthForRexMatch = 10 'Awk.MaxDepthForRexMatch = 10
Awk.UseLongLong = False
Awk.Debug = True Awk.Debug = True
If Awk.Parse() = -1 Then If Awk.Parse() = -1 Then
@ -387,20 +389,26 @@ ErrorTrap:
Exit Function Exit Function
End Function End Function
Function Awk_HandleBuiltinFunction(ByVal name As String, ByVal args As Variant) As Long Function Awk_HandleBuiltinFunction(ByVal name As String, ByVal args As Variant) As Variant
Dim i As Integer If name = "sin" Then
Dim xxx As String Awk_HandleBuiltinFunction = Sin(args(0))
ElseIf name = "cos" Then
Awk_HandleBuiltinFunction = Cos(args(0))
ElseIf name = "tan" Then
Awk_HandleBuiltinFunction = Tan(args(0))
End If
MsgBox name 'Dim i As Integer
'Dim xxx As String
For i = LBound(args) To UBound(args) 'MsgBox name
xxx = xxx & "," & args(i)
Next i
MsgBox xxx 'For i = LBound(args) To UBound(args)
' xxx = xxx & "," & args(i)
'Next i
Awk_HandleBuiltinFunction = 0 'MsgBox xxx
End Function End Function
Private Sub Form_Load() Private Sub Form_Load()