*** empty log message ***

This commit is contained in:
hyung-hwan 2007-01-16 14:20:43 +00:00
parent 1b157a3e8d
commit 465aef1208
6 changed files with 96 additions and 26 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c,v 1.102 2007-01-02 12:25:18 bacon Exp $ * $Id: val.c,v 1.103 2007-01-16 14:20:42 bacon Exp $
*/ */
#include <ase/awk/awk_i.h> #include <ase/awk/awk_i.h>
@ -16,12 +16,9 @@ static ase_char_t* __val_real_to_str (
static ase_awk_val_nil_t __awk_nil = { ASE_AWK_VAL_NIL, 0 }; static ase_awk_val_nil_t __awk_nil = { ASE_AWK_VAL_NIL, 0 };
static ase_awk_val_str_t __awk_zls = { ASE_AWK_VAL_STR, 0, ASE_T(""), 0 }; static ase_awk_val_str_t __awk_zls = { ASE_AWK_VAL_STR, 0, ASE_T(""), 0 };
/* TODO: consider different line ending schemes */
static ase_awk_val_str_t __awk_nl = { ASE_AWK_VAL_STR, 0, ASE_T("\n"), 1 };
ase_awk_val_t* ase_awk_val_nil = (ase_awk_val_t*)&__awk_nil; ase_awk_val_t* ase_awk_val_nil = (ase_awk_val_t*)&__awk_nil;
ase_awk_val_t* ase_awk_val_zls = (ase_awk_val_t*)&__awk_zls; ase_awk_val_t* ase_awk_val_zls = (ase_awk_val_t*)&__awk_zls;
ase_awk_val_t* ase_awk_val_nl = (ase_awk_val_t*)&__awk_nl;
static ase_awk_val_int_t __awk_int[] = static ase_awk_val_int_t __awk_int[] =
{ {
@ -266,7 +263,6 @@ ase_bool_t ase_awk_isbuiltinval (ase_awk_val_t* val)
return val == ASE_NULL || return val == ASE_NULL ||
val == ase_awk_val_nil || val == ase_awk_val_nil ||
val == ase_awk_val_zls || val == ase_awk_val_zls ||
val == ase_awk_val_nl ||
val == ase_awk_val_zero || val == ase_awk_val_zero ||
val == ase_awk_val_one || val == ase_awk_val_one ||
(val >= (ase_awk_val_t*)&__awk_int[0] && (val >= (ase_awk_val_t*)&__awk_int[0] &&

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.h,v 1.58 2007-01-14 15:07:22 bacon Exp $ * $Id: val.h,v 1.59 2007-01-16 14:20:42 bacon Exp $
*/ */
#ifndef _ASE_AWK_VAL_H_ #ifndef _ASE_AWK_VAL_H_
@ -151,7 +151,6 @@ extern "C" {
extern ase_awk_val_t* ase_awk_val_nil; extern ase_awk_val_t* ase_awk_val_nil;
extern ase_awk_val_t* ase_awk_val_zls; extern ase_awk_val_t* ase_awk_val_zls;
extern ase_awk_val_t* ase_awk_val_nl;
extern ase_awk_val_t* ase_awk_val_negone; extern ase_awk_val_t* ase_awk_val_negone;
extern ase_awk_val_t* ase_awk_val_zero; extern ase_awk_val_t* ase_awk_val_zero;
extern ase_awk_val_t* ase_awk_val_one; extern ase_awk_val_t* ase_awk_val_one;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.cpp,v 1.18 2007-01-16 06:09:07 bacon Exp $ * $Id: Awk.cpp,v 1.19 2007-01-16 14:20:42 bacon Exp $
*/ */
#include "stdafx.h" #include "stdafx.h"
@ -36,6 +36,7 @@ CAwk::CAwk ():
read_src_buf (NULL), read_src_buf (NULL),
write_src_buf (NULL), write_src_buf (NULL),
write_extio_buf (NULL), write_extio_buf (NULL),
bfn_list (NULL),
entry_point (NULL), entry_point (NULL),
debug (FALSE), debug (FALSE),
use_longlong (FALSE) use_longlong (FALSE)
@ -63,6 +64,14 @@ CAwk::CAwk ():
CAwk::~CAwk () CAwk::~CAwk ()
{ {
while (bfn_list != NULL)
{
bfn_t* next = bfn_list->next;
free (bfn_list->name.ptr);
free (bfn_list);
bfn_list = next;
}
if (entry_point != NULL) SysFreeString (entry_point); if (entry_point != NULL) SysFreeString (entry_point);
if (write_extio_buf != NULL) write_extio_buf->Release (); if (write_extio_buf != NULL) write_extio_buf->Release ();
@ -464,17 +473,24 @@ 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("sin"), 3, 0, 1, 1, ASE_NULL, __handle_bfn); for (bfn_t* bfn = bfn_list; bfn != NULL; bfn = bfn->next)
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... )
{ {
ase_awk_addbfn (handle, if (ase_awk_addbfn (
ptr, len, 0, min_args, max_args, __handle_bfn); handle, bfn->name.ptr, bfn->name.len, 0,
bfn->min_args, bfn->max_args, NULL,
__handle_bfn) == NULL)
{
const ase_char_t* msg;
DBGOUT (_T("cannot add the builtin function"));
ase_awk_geterror (handle, &errnum, &errlin, &msg);
ase_awk_strxcpy (errmsg, ASE_COUNTOF(errmsg), msg);
*ret = -1;
return S_OK;
}
} }
*/
ase_awk_srcios_t srcios; ase_awk_srcios_t srcios;
@ -704,9 +720,46 @@ HRESULT CAwk::Run (int* ret)
return S_OK; return S_OK;
} }
STDMETHODIMP CAwk::AddBuiltinFunction(BSTR name)
STDMETHODIMP CAwk::AddBuiltinFunction (
BSTR name, int min_args, int max_args, int* ret)
{ {
/* TODO: remember names */ bfn_t* bfn = (bfn_t*)malloc (sizeof(bfn_t));
if (bfn == NULL)
{
errnum = ASE_AWK_ENOMEM;
errlin = 0;
ase_awk_strxcpy (
errmsg, ASE_COUNTOF(errmsg),
ase_awk_geterrstr(errnum));
*ret = -1;
return S_OK;
}
bfn->name.len = SysStringLen(name);
bfn->name.ptr = (TCHAR*)malloc (bfn->name.len * sizeof(TCHAR));
if (bfn->name.ptr == NULL)
{
free (bfn);
errnum = ASE_AWK_ENOMEM;
errlin = 0;
ase_awk_strxcpy (
errmsg, ASE_COUNTOF(errmsg),
ase_awk_geterrstr(errnum));
*ret = -1;
return S_OK;
}
memcpy (bfn->name.ptr, name, sizeof(TCHAR) * bfn->name.len);
bfn->min_args = min_args;
bfn->max_args = max_args;
bfn->next = bfn_list;
bfn_list = bfn;
*ret = 0;
return S_OK; return S_OK;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Awk.h,v 1.12 2007-01-16 06:09:07 bacon Exp $ * $Id: Awk.h,v 1.13 2007-01-16 14:20:43 bacon Exp $
*/ */
#ifndef _ASE_COM_AWK_H_ #ifndef _ASE_COM_AWK_H_
@ -62,6 +62,18 @@ public:
IBuffer* write_extio_buf; IBuffer* write_extio_buf;
struct bfn_t
{
struct
{
TCHAR* ptr;
size_t len;
} name;
size_t min_args;
size_t max_args;
struct bfn_t* next;
} * bfn_list;
BSTR entry_point; BSTR entry_point;
BOOL debug; BOOL debug;
BOOL use_longlong; BOOL use_longlong;
@ -92,7 +104,6 @@ DECLARE_REGISTRY_RESOURCEID(IDR_AWK)
// IAwk // IAwk
public: public:
STDMETHOD(get_UseLongLong)(/*[out, retval]*/ BOOL *pVal);
STDMETHOD(put_UseLongLong)(/*[in]*/ BOOL newVal); 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);
@ -139,7 +150,8 @@ public:
STDMETHOD(get_ErrorMessage)(/*[out, retval]*/ BSTR *pVal); STDMETHOD(get_ErrorMessage)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(get_ErrorLine)(/*[out, retval]*/ int *pVal); STDMETHOD(get_ErrorLine)(/*[out, retval]*/ int *pVal);
STDMETHOD(get_ErrorCode)(/*[out, retval]*/ int *pVal); STDMETHOD(get_ErrorCode)(/*[out, retval]*/ int *pVal);
STDMETHOD(AddBuiltinFunction)(BSTR name); STDMETHOD(AddBuiltinFunction)(/*[in]*/ BSTR name, /*[in]*/ int min_args, /*[in]*/ int max_args, /*[out, retval]*/ int* ret);
STDMETHOD(get_UseLongLong)(/*[out, retval]*/ BOOL *pVal);
HRESULT __stdcall Parse (int* ret); HRESULT __stdcall Parse (int* ret);
HRESULT __stdcall Run (int* ret); HRESULT __stdcall Run (int* ret);
}; };

View File

@ -1,5 +1,5 @@
/* /*
* $Id: ase.idl,v 1.13 2007-01-16 06:09:07 bacon Exp $ * $Id: ase.idl,v 1.14 2007-01-16 14:20:43 bacon Exp $
*/ */
import "oaidl.idl"; import "oaidl.idl";
@ -22,7 +22,7 @@ interface IAwk : IDispatch
HRESULT Run([out, retval] int* ret); HRESULT Run([out, retval] int* ret);
[id(3), helpstring("method AddBuiltinFunction")] [id(3), helpstring("method AddBuiltinFunction")]
HRESULT AddBuiltinFunction(BSTR name); HRESULT AddBuiltinFunction([in] BSTR name, [in] int min_args, [in] int max_args, [out, retval] int* ret);
[propget, id(4), helpstring("property ErrorCode")] [propget, id(4), helpstring("property ErrorCode")]
HRESULT ErrorCode([out, retval] int *pVal); HRESULT ErrorCode([out, retval] int *pVal);

View File

@ -124,7 +124,7 @@ Begin VB.Form AwkForm
Width = 3735 Width = 3735
End End
Begin VB.Label Label2 Begin VB.Label Label2
Caption = "Deparsed Source Code" Caption = "Source Out"
Height = 255 Height = 255
Left = 5280 Left = 5280
TabIndex = 6 TabIndex = 6
@ -132,7 +132,7 @@ Begin VB.Form AwkForm
Width = 3735 Width = 3735
End End
Begin VB.Label Label1 Begin VB.Label Label1
Caption = "Source Code" Caption = "Source In"
Height = 255 Height = 255
Left = 120 Left = 120
TabIndex = 4 TabIndex = 4
@ -176,6 +176,14 @@ Private Sub Execute_Click()
Awk.Debug = True Awk.Debug = True
If Awk.AddBuiltinFunction("sin", 1, 1) = -1 Then
MsgBox "Cannot add builtin function - " + Awk.ErrorMessage
Exit Sub
End If
Call Awk.AddBuiltinFunction("cos", 1, 1)
Call Awk.AddBuiltinFunction("tan", 1, 1)
Call Awk.AddBuiltinFunction("trim", 1, 1)
If Awk.Parse() = -1 Then If Awk.Parse() = -1 Then
MsgBox "PARSE ERROR [" + Str(Awk.ErrorLine) + "]" + Awk.ErrorMessage MsgBox "PARSE ERROR [" + Str(Awk.ErrorLine) + "]" + Awk.ErrorMessage
Else Else
@ -397,6 +405,8 @@ Function Awk_HandleBuiltinFunction(ByVal name As String, ByVal args As Variant)
Awk_HandleBuiltinFunction = Cos(args(0)) Awk_HandleBuiltinFunction = Cos(args(0))
ElseIf name = "tan" Then ElseIf name = "tan" Then
Awk_HandleBuiltinFunction = Tan(args(0)) Awk_HandleBuiltinFunction = Tan(args(0))
ElseIf name = "trim" Then
Awk_HandleBuiltinFunction = Trim(args(0))
End If End If
'Dim i As Integer 'Dim i As Integer