From 1b157a3e8d8911689011db510b078d59e780ccd9 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 16 Jan 2007 06:09:07 +0000 Subject: [PATCH] *** empty log message *** --- ase/com/Awk.cpp | 89 +++++++++++++++++++++++++++++++++++----- ase/com/Awk.h | 7 +++- ase/com/ase.idl | 9 +++- ase/com/awk_cp.h | 56 +++++++++++++++++-------- ase/test/com/AwkForm.frm | 30 +++++++++----- 5 files changed, 149 insertions(+), 42 deletions(-) diff --git a/ase/com/Awk.cpp b/ase/com/Awk.cpp index fc8e20c3..38037930 100644 --- a/ase/com/Awk.cpp +++ b/ase/com/Awk.cpp @@ -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" @@ -37,7 +37,8 @@ CAwk::CAwk (): write_src_buf (NULL), write_extio_buf (NULL), entry_point (NULL), - debug (FALSE) + debug (FALSE), + use_longlong (FALSE) { /* TODO: what is the best default option? */ option = @@ -271,7 +272,7 @@ static int __handle_bfn ( { ase_char_t buf[128]; _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); ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, buf); return -1; @@ -287,10 +288,16 @@ static int __handle_bfn ( if (v->type == ASE_AWK_VAL_INT) { - //arg.vt = VT_I8; - //arg.llVal = ((ase_awk_val_int_t*)v)->val; - arg.vt = VT_I4; - arg.lVal = (LONG)((ase_awk_val_int_t*)v)->val; + if (awk->use_longlong) + { + arg.vt = VT_I8; + arg.llVal = ((ase_awk_val_int_t*)v)->val; + } + else + { + arg.vt = VT_I4; + arg.lVal = (LONG)((ase_awk_val_int_t*)v)->val; + } } else if (v->type == ASE_AWK_VAL_REAL) { @@ -307,6 +314,12 @@ static int __handle_bfn ( { VariantClear (&arg); 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; } @@ -324,7 +337,11 @@ static int __handle_bfn ( VariantClear (&arg); 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; } @@ -334,17 +351,52 @@ static int __handle_bfn ( BSTR name = SysAllocStringLen (fnm, fnl); if (name == NULL) { - /* TODO: handle error properly */ 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; } - 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 */ //SafeArrayDestroy (aa); //SysFreeString (name); + ase_awk_setretval (run, ret); return 0; } @@ -412,7 +464,10 @@ HRESULT CAwk::Parse (int* ret) 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... ) { @@ -1040,3 +1095,15 @@ STDMETHODIMP CAwk::put_Debug(BOOL newVal) debug = newVal; 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; +} diff --git a/ase/com/Awk.h b/ase/com/Awk.h index 868101ff..47053594 100644 --- a/ase/com/Awk.h +++ b/ase/com/Awk.h @@ -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_ @@ -11,9 +11,9 @@ #include "resource.h" #include "ase.h" -#include "awk_cp.h" #include #include +#include "awk_cp.h" ///////////////////////////////////////////////////////////////////////////// // CAwk @@ -64,6 +64,7 @@ public: BSTR entry_point; BOOL debug; + BOOL use_longlong; public: CAwk(); ~CAwk (); @@ -91,6 +92,8 @@ DECLARE_REGISTRY_RESOURCEID(IDR_AWK) // IAwk public: + STDMETHOD(get_UseLongLong)(/*[out, retval]*/ BOOL *pVal); + STDMETHOD(put_UseLongLong)(/*[in]*/ BOOL newVal); STDMETHOD(get_Debug)(/*[out, retval]*/ BOOL *pVal); STDMETHOD(put_Debug)(/*[in]*/ BOOL newVal); STDMETHOD(get_EntryPoint)(/*[out, retval]*/ BSTR *pVal); diff --git a/ase/com/ase.idl b/ase/com/ase.idl index 33691e09..dea08dd8 100644 --- a/ase/com/ase.idl +++ b/ase/com/ase.idl @@ -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"; @@ -137,6 +137,11 @@ interface IAwk : IDispatch HRESULT Debug([out, retval] BOOL *pVal); [propput, id(27), helpstring("property Debug")] 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 */ @@ -259,7 +264,7 @@ library ASELib int NextExtio([in] IAwkExtio* extio); [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 */ diff --git a/ase/com/awk_cp.h b/ase/com/awk_cp.h index db07cf2b..ec386de5 100644 --- a/ase/com/awk_cp.h +++ b/ase/com/awk_cp.h @@ -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_ @@ -504,13 +504,14 @@ public: return -1; } - - INT Fire_HandleBuiltinFunction (BSTR name, SAFEARRAY* argarray) + int Fire_HandleBuiltinFunction ( + ase_awk_run_t* run, BSTR name, SAFEARRAY* argarray, ase_awk_val_t** retv) { T* pT = static_cast(this); int i, nconns = m_vec.GetSize(); CComVariant ret; VARIANT args[2]; + ase_awk_val_t* v; VariantInit (&args[0]); VariantInit (&args[1]); @@ -545,25 +546,48 @@ public: continue; } - hr = ret.ChangeType (VT_I4); - if (FAILED(hr)) - { - /* TODO: set the error code properly... */ - /* invalid value returned... */ - VariantClear (&args[1]); - VariantClear (&args[0]); - return -1; - } - VariantClear (&args[1]); VariantClear (&args[0]); - return ret.lVal; + + 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 */ } - /* TODO; clear name and aa */ VariantClear (&args[1]); VariantClear (&args[0]); - return -1; + return 2; /* no proper handler */ } diff --git a/ase/test/com/AwkForm.frm b/ase/test/com/AwkForm.frm index 112025e6..63959383 100644 --- a/ase/test/com/AwkForm.frm +++ b/ase/test/com/AwkForm.frm @@ -172,6 +172,8 @@ Private Sub Execute_Click() 'Awk.MaxDepthForRexBuild = 10 'Awk.MaxDepthForRexMatch = 10 + Awk.UseLongLong = False + Awk.Debug = True If Awk.Parse() = -1 Then @@ -387,20 +389,26 @@ ErrorTrap: Exit 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 - Dim xxx As String - - MsgBox name + If name = "sin" Then + 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 - For i = LBound(args) To UBound(args) - xxx = xxx & "," & args(i) - Next i - - MsgBox xxx + 'Dim i As Integer + 'Dim xxx As String - Awk_HandleBuiltinFunction = 0 + 'MsgBox name + + 'For i = LBound(args) To UBound(args) + ' xxx = xxx & "," & args(i) + 'Next i + + 'MsgBox xxx End Function Private Sub Form_Load()