From c8b439dd9115aa030e21234a55f417209022737e Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 2 Sep 2007 00:43:00 +0000 Subject: [PATCH] Recovered from cvs revision 2007-09-01 15:43:00 --- ase/awk/Awk.cpp | 4 +-- ase/awk/Awk.hpp | 4 +-- ase/awk/Awk.java | 4 +-- ase/awk/StdAwk.cpp | 9 ++++++- ase/awk/StdAwk.hpp | 4 ++- ase/awk/StdAwk.java | 11 ++++++-- ase/awk/awk.h | 6 ++--- ase/awk/func.c | 10 +++---- ase/awk/jni.c | 4 +-- ase/awk/run.c | 14 +++++++--- ase/com/Awk.cpp | 14 +++++----- ase/com/Awk.h | 6 ++--- ase/com/asecom.idl | 10 +++---- ase/net/Awk.hpp | 4 +-- ase/net/StdAwk.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++- ase/net/StdAwk.hpp | 12 ++++++++- ase/test/awk/Awk.cpp | 8 +++++- ase/test/awk/asm.awk | 52 +++++++++++++++++++++++++++++++++++ ase/test/awk/asm.s | 14 ++++++++++ ase/test/awk/awk.c | 4 +-- 20 files changed, 213 insertions(+), 45 deletions(-) create mode 100644 ase/test/awk/asm.awk create mode 100644 ase/test/awk/asm.s diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index c3135f8e..9c376a4e 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.51 2007/08/24 15:11:36 bacon Exp $ + * $Id: Awk.cpp,v 1.52 2007/08/26 14:33:38 bacon Exp $ */ @@ -539,7 +539,7 @@ namespace ASE OPT_SHIFT | OPT_EXTIO | OPT_BLOCKLESS | - OPT_STRBASEONE | + OPT_BASEONE | OPT_STRIPSPACES | OPT_NEXTOFILE | OPT_ARGSTOMAIN; diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index 9972f7eb..5bcc75de 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.48 2007/08/24 13:17:59 bacon Exp $ + * $Id: Awk.hpp,v 1.49 2007/08/26 14:33:38 bacon Exp $ */ #ifndef _ASE_AWK_AWK_HPP_ @@ -350,7 +350,7 @@ namespace ASE OPT_EXTIO = ASE_AWK_EXTIO, OPT_COPROC = ASE_AWK_COPROC, OPT_BLOCKLESS = ASE_AWK_BLOCKLESS, - OPT_STRBASEONE = ASE_AWK_STRBASEONE, + OPT_BASEONE = ASE_AWK_BASEONE, OPT_STRIPSPACES = ASE_AWK_STRIPSPACES, OPT_NEXTOFILE = ASE_AWK_NEXTOFILE, OPT_CRLF = ASE_AWK_CRLF, diff --git a/ase/awk/Awk.java b/ase/awk/Awk.java index 578d3af6..d1ed9b3d 100644 --- a/ase/awk/Awk.java +++ b/ase/awk/Awk.java @@ -1,5 +1,5 @@ /* - * $Id: Awk.java,v 1.12 2007/06/28 15:45:57 bacon Exp $ + * $Id: Awk.java,v 1.13 2007/08/26 14:33:38 bacon Exp $ * * {License} */ @@ -33,7 +33,7 @@ public abstract class Awk public static final int OPTION_EXTIO = (1 << 7); public static final int OPTION_COPROC = (1 << 8); public static final int OPTION_BLOCKLESS = (1 << 9); - public static final int OPTION_STRBASEONE = (1 << 10); + public static final int OPTION_ASEONE = (1 << 10); public static final int OPTION_STRIPSPACES = (1 << 11); public static final int OPTION_NEXTOFILE = (1 << 12); public static final int OPTION_CRLF = (1 << 13); diff --git a/ase/awk/StdAwk.cpp b/ase/awk/StdAwk.cpp index 7bf20155..d836235f 100644 --- a/ase/awk/StdAwk.cpp +++ b/ase/awk/StdAwk.cpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.cpp,v 1.23 2007/08/21 14:24:37 bacon Exp $ + * $Id: StdAwk.cpp,v 1.24 2007/08/26 14:33:38 bacon Exp $ */ #include @@ -44,6 +44,7 @@ namespace ASE ADD_FUNC (ASE_T("sin"), 1, 1, &StdAwk::sin); ADD_FUNC (ASE_T("cos"), 1, 1, &StdAwk::cos); ADD_FUNC (ASE_T("tan"), 1, 1, &StdAwk::tan); + ADD_FUNC (ASE_T("atan"), 1, 1, &StdAwk::atan); ADD_FUNC (ASE_T("atan2"), 2, 2, &StdAwk::atan2); ADD_FUNC (ASE_T("log"), 1, 1, &StdAwk::log); ADD_FUNC (ASE_T("exp"), 1, 1, &StdAwk::exp); @@ -77,6 +78,12 @@ namespace ASE return ret->set ((real_t)::tan(args[0].toReal())); } + int StdAwk::atan (Return* ret, const Argument* args, size_t nargs, + const char_t* name, size_t len) + { + return ret->set ((real_t)::atan(args[0].toReal())); + } + int StdAwk::atan2 (Return* ret, const Argument* args, size_t nargs, const char_t* name, size_t len) { diff --git a/ase/awk/StdAwk.hpp b/ase/awk/StdAwk.hpp index ccfcebd5..0809cb20 100644 --- a/ase/awk/StdAwk.hpp +++ b/ase/awk/StdAwk.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.hpp,v 1.12 2007/07/15 16:31:59 bacon Exp $ + * $Id: StdAwk.hpp,v 1.13 2007/08/26 14:33:38 bacon Exp $ */ #ifndef _ASE_AWK_STDAWK_HPP_ @@ -25,6 +25,8 @@ namespace ASE const char_t* name, size_t len); int tan (Return* ret, const Argument* args, size_t nargs, const char_t* name, size_t len); + int atan (Return* ret, const Argument* args, size_t nargs, + const char_t* name, size_t len); int atan2 (Return* ret, const Argument* args, size_t nargs, const char_t* name, size_t len); int log (Return* ret, const Argument* args, size_t nargs, diff --git a/ase/awk/StdAwk.java b/ase/awk/StdAwk.java index 1903c9a4..8ad440ff 100644 --- a/ase/awk/StdAwk.java +++ b/ase/awk/StdAwk.java @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.java,v 1.10 2007/05/26 10:23:52 bacon Exp $ + * $Id: StdAwk.java,v 1.11 2007/08/26 14:33:38 bacon Exp $ * * {License} */ @@ -23,7 +23,8 @@ public abstract class StdAwk extends Awk addFunction ("sin", 1, 1); addFunction ("cos", 1, 1); addFunction ("tan", 1, 1); - addFunction ("atan2", 1, 1); + addFunction ("atan", 1, 1); + addFunction ("atan2", 2, 2); addFunction ("log", 1, 1); addFunction ("exp", 1, 1); addFunction ("sqrt", 1, 1); @@ -349,6 +350,12 @@ public abstract class StdAwk extends Awk return new Double (Math.tan(x)); } + public Object bfn_atan (long runid, Object[] args) throws Exception + { + double x = builtinFunctionArgumentToDouble (runid, args[0]); + return new Double (Math.atan(x)); + } + public Object bfn_atan2 (long runid, Object[] args) throws Exception { double y = builtinFunctionArgumentToDouble (runid, args[0]); diff --git a/ase/awk/awk.h b/ase/awk/awk.h index 16da7509..7fe5c4d7 100644 --- a/ase/awk/awk.h +++ b/ase/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h,v 1.9 2007/08/24 13:17:59 bacon Exp $ + * $Id: awk.h,v 1.10 2007/08/26 14:33:38 bacon Exp $ * * {License} */ @@ -165,8 +165,8 @@ enum ase_awk_option_t /* support blockless patterns */ ASE_AWK_BLOCKLESS = (1 << 9), - /* use 1 as the start index for string operations */ - ASE_AWK_STRBASEONE = (1 << 10), + /* use 1 as the start index for string operations and ARGV */ + ASE_AWK_BASEONE = (1 << 10), /* strip off leading and trailing spaces when splitting a record * into fields with a regular expression. diff --git a/ase/awk/func.c b/ase/awk/func.c index ab7e98ba..3fce5b11 100644 --- a/ase/awk/func.c +++ b/ase/awk/func.c @@ -1,5 +1,5 @@ /* - * $Id: func.c,v 1.7 2007/06/18 14:26:30 bacon Exp $ + * $Id: func.c,v 1.8 2007/08/26 14:33:38 bacon Exp $ * * {License} */ @@ -448,7 +448,7 @@ static int bfn_index ( ptr = ase_strxnstr (str0, len0, str1, len1); idx = (ptr == ASE_NULL)? -1: (ase_long_t)(ptr - str0); - if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) idx = idx + 1; + if (ase_awk_getoption(run->awk) & ASE_AWK_BASEONE) idx = idx + 1; if (a0->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str0); if (a1->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str1); @@ -550,7 +550,7 @@ static int bfn_substr ( if (n == 1) lcount = (ase_long_t)rcount; } - if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) lindex = lindex - 1; + if (ase_awk_getoption(run->awk) & ASE_AWK_BASEONE) lindex = lindex - 1; if (lindex >= len) lindex = len; else if (lindex < 0) lindex = 0; @@ -724,7 +724,7 @@ static int bfn_split ( ase_awk_refupval (run, *a1_ref); p = str; str_left = str_len; - sta = (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE)? 1: 0; + sta = (ase_awk_getoption(run->awk) & ASE_AWK_BASEONE)? 1: 0; num = sta; while (p != ASE_NULL) @@ -1280,7 +1280,7 @@ static int bfn_match ( if (n == -1) return -1; idx = (n == 0)? -1: (ase_long_t)(mat_ptr - str0); - if (ase_awk_getoption(run->awk) & ASE_AWK_STRBASEONE) idx = idx + 1; + if (ase_awk_getoption(run->awk) & ASE_AWK_BASEONE) idx = idx + 1; a0 = ase_awk_makeintval (run, idx); if (a0 == ASE_NULL) diff --git a/ase/awk/jni.c b/ase/awk/jni.c index 58487534..fa79f650 100644 --- a/ase/awk/jni.c +++ b/ase/awk/jni.c @@ -1,5 +1,5 @@ /* - * $Id: jni.c,v 1.12 2007/06/28 15:45:57 bacon Exp $ + * $Id: jni.c,v 1.13 2007/08/26 14:33:38 bacon Exp $ * * {License} */ @@ -388,7 +388,7 @@ JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj) ASE_AWK_SHIFT | ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | - ASE_AWK_STRBASEONE | + ASE_AWK_BASEONE | ASE_AWK_STRIPSPACES | ASE_AWK_NEXTOFILE | ASE_AWK_ARGSTOMAIN; diff --git a/ase/awk/run.c b/ase/awk/run.c index 6fdaa7a8..b09802c1 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.10 2007/08/21 14:24:37 bacon Exp $ + * $Id: run.c,v 1.11 2007/08/26 14:33:38 bacon Exp $ * * {License} */ @@ -964,8 +964,16 @@ static int __build_runarg ( return -1; } - key_len = ase_awk_longtostr ( - argc, 10, ASE_NULL, key, ASE_COUNTOF(key)); + if (ase_awk_getoption(run->awk) & ASE_AWK_BASEONE) + { + key_len = ase_awk_longtostr (argc+1, + 10, ASE_NULL, key, ASE_COUNTOF(key)); + } + else + { + key_len = ase_awk_longtostr (argc, + 10, ASE_NULL, key, ASE_COUNTOF(key)); + } ASE_ASSERT (key_len != (ase_size_t)-1); /* increment reference count of v_tmp in advance as if diff --git a/ase/com/Awk.cpp b/ase/com/Awk.cpp index d1f640d4..8b0d6413 100644 --- a/ase/com/Awk.cpp +++ b/ase/com/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.6 2007/07/02 14:04:20 bacon Exp $ + * $Id: Awk.cpp,v 1.7 2007/08/26 14:33:38 bacon Exp $ * * {License} */ @@ -62,7 +62,7 @@ CAwk::CAwk (): ASE_AWK_SHIFT | ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | - ASE_AWK_STRBASEONE | + ASE_AWK_BASEONE | ASE_AWK_STRIPSPACES | ASE_AWK_NEXTOFILE | ASE_AWK_CRLF; @@ -1247,17 +1247,17 @@ STDMETHODIMP CAwk::put_SupportBlockless(VARIANT_BOOL newVal) return S_OK; } -STDMETHODIMP CAwk::get_StringBaseOne(VARIANT_BOOL *pVal) +STDMETHODIMP CAwk::get_BaseOne(VARIANT_BOOL *pVal) { if (handle != NULL) option = ase_awk_getoption (handle); - *pVal = (option & ASE_AWK_STRBASEONE) == 1; + *pVal = (option & ASE_AWK_BASEONE) == 1; return S_OK; } -STDMETHODIMP CAwk::put_StringBaseOne(VARIANT_BOOL newVal) +STDMETHODIMP CAwk::put_BaseOne(VARIANT_BOOL newVal) { - if (newVal) option = option | ASE_AWK_STRBASEONE; - else option = option & ~ASE_AWK_STRBASEONE; + if (newVal) option = option | ASE_AWK_BASEONE; + else option = option & ~ASE_AWK_BASEONE; if (handle != NULL) ase_awk_setoption (handle, option); return S_OK; } diff --git a/ase/com/Awk.h b/ase/com/Awk.h index 9ec91e8e..b1cfbe5d 100644 --- a/ase/com/Awk.h +++ b/ase/com/Awk.h @@ -1,5 +1,5 @@ /* - * $Id: Awk.h,v 1.6 2007/07/02 14:04:20 bacon Exp $ + * $Id: Awk.h,v 1.7 2007/08/26 14:33:38 bacon Exp $ * * {License} */ @@ -149,8 +149,8 @@ public: STDMETHOD(put_Nextofile)(/*[in]*/ VARIANT_BOOL newVal); STDMETHOD(get_StripSpaces)(/*[out, retval]*/ VARIANT_BOOL *pVal); STDMETHOD(put_StripSpaces)(/*[in]*/ VARIANT_BOOL newVal); - STDMETHOD(get_StringBaseOne)(/*[out, retval]*/ VARIANT_BOOL *pVal); - STDMETHOD(put_StringBaseOne)(/*[in]*/ VARIANT_BOOL newVal); + STDMETHOD(get_BaseOne)(/*[out, retval]*/ VARIANT_BOOL *pVal); + STDMETHOD(put_BaseOne)(/*[in]*/ VARIANT_BOOL newVal); STDMETHOD(get_SupportBlockless)(/*[out, retval]*/ VARIANT_BOOL *pVal); STDMETHOD(put_SupportBlockless)(/*[in]*/ VARIANT_BOOL newVal); STDMETHOD(get_SupportExtio)(/*[out, retval]*/ VARIANT_BOOL *pVal); diff --git a/ase/com/asecom.idl b/ase/com/asecom.idl index e0a278cb..4ac47de3 100644 --- a/ase/com/asecom.idl +++ b/ase/com/asecom.idl @@ -1,5 +1,5 @@ /* - * $Id: asecom.idl,v 1.6 2007/07/02 14:04:20 bacon Exp $ + * $Id: asecom.idl,v 1.7 2007/08/26 14:33:38 bacon Exp $ */ import "oaidl.idl"; @@ -90,10 +90,10 @@ interface IAwk : IDispatch [propput, id(19), helpstring("property SupportBlockless")] HRESULT SupportBlockless([in] VARIANT_BOOL newVal); - [propget, id(20), helpstring("property StringBaseOne")] - HRESULT StringBaseOne([out,retval] VARIANT_BOOL *pVal); - [propput, id(20), helpstring("property StringBaseOne")] - HRESULT StringBaseOne([in] VARIANT_BOOL newVal); + [propget, id(20), helpstring("property BaseOne")] + HRESULT BaseOne([out,retval] VARIANT_BOOL *pVal); + [propput, id(20), helpstring("property BaseOne")] + HRESULT BaseOne([in] VARIANT_BOOL newVal); [propget, id(21), helpstring("property StripSpaces")] HRESULT StripSpaces([out,retval] VARIANT_BOOL *pVal); diff --git a/ase/net/Awk.hpp b/ase/net/Awk.hpp index 54873416..5b77e4f0 100644 --- a/ase/net/Awk.hpp +++ b/ase/net/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.19 2007/08/24 13:17:59 bacon Exp $ + * $Id: Awk.hpp,v 1.20 2007/08/26 14:33:38 bacon Exp $ */ #pragma once @@ -310,7 +310,7 @@ namespace ASE EXTIO = ASE::Awk::OPT_EXTIO, COPROC = ASE::Awk::OPT_COPROC, BLOCKLESS = ASE::Awk::OPT_BLOCKLESS, - STRBASEONE = ASE::Awk::OPT_STRBASEONE, + STRBASEONE = ASE::Awk::OPT_BASEONE, STRIPSPACES = ASE::Awk::OPT_STRIPSPACES, NEXTOFILE = ASE::Awk::OPT_NEXTOFILE, CRLF = ASE::Awk::OPT_CRLF, diff --git a/ase/net/StdAwk.cpp b/ase/net/StdAwk.cpp index 189b2c43..f50bb200 100644 --- a/ase/net/StdAwk.cpp +++ b/ase/net/StdAwk.cpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.cpp,v 1.7 2007/08/24 16:02:49 bacon Exp $ + * $Id: StdAwk.cpp,v 1.8 2007/08/26 14:33:38 bacon Exp $ */ #include "stdafx.h" @@ -18,10 +18,23 @@ namespace ASE StdAwk::StdAwk () { + /* + seed = System::DateTime + random = gcnew System::Random (); + */ + // TODO: exception/error handling.... AddFunction ("sin", 1, 1, gcnew FunctionHandler (this, &StdAwk::Sin)); AddFunction ("cos", 1, 1, gcnew FunctionHandler (this, &StdAwk::Cos)); AddFunction ("tan", 1, 1, gcnew FunctionHandler (this, &StdAwk::Tan)); + AddFunction ("atan", 1, 1, gcnew FunctionHandler (this, &StdAwk::Atan)); + AddFunction ("atan2", 2, 2, gcnew FunctionHandler (this, &StdAwk::Atan2)); + AddFunction ("log", 1, 1, gcnew FunctionHandler (this, &StdAwk::Log)); + AddFunction ("exp", 1, 1, gcnew FunctionHandler (this, &StdAwk::Exp)); + AddFunction ("sqrt", 1, 1, gcnew FunctionHandler (this, &StdAwk::Sqrt)); + AddFunction ("int", 1, 1, gcnew FunctionHandler (this, &StdAwk::Int)); + //AddFunction ("rand", 0, 0, gcnew FunctionHandler (this, &StdAwk::Int)); + //AddFunction ("srand", 1, 1, gcnew FunctionHandler (this, &StdAwk::Int)); } StdAwk::~StdAwk () @@ -46,6 +59,55 @@ namespace ASE return true; } + bool StdAwk::Atan (System::String^ name, array^ args, Return^ ret) + { + ret->RealValue = System::Math::Atan (args[0]->RealValue); + return true; + } + + bool StdAwk::Atan2 (System::String^ name, array^ args, Return^ ret) + { + ret->RealValue = System::Math::Atan2 (args[0]->RealValue, args[1]->RealValue); + return true; + } + + bool StdAwk::Log (System::String^ name, array^ args, Return^ ret) + { + ret->RealValue = System::Math::Log (args[0]->RealValue); + return true; + } + + bool StdAwk::Exp (System::String^ name, array^ args, Return^ ret) + { + ret->RealValue = System::Math::Exp (args[0]->RealValue); + return true; + } + + bool StdAwk::Sqrt (System::String^ name, array^ args, Return^ ret) + { + ret->RealValue = System::Math::Sqrt (args[0]->RealValue); + return true; + } + + bool StdAwk::Int (System::String^ name, array^ args, Return^ ret) + { + ret->LongValue = args[0]->LongValue; + return true; + } + + /* + bool StdAwk::Rand (System::String^ name, array^ args, Return^ ret) + { + ret->LongValue = random->Next (); + return true; + } + + bool StdAwk::Srand (System::String^ name, array^ args, Return^ ret) + { + ret->LongValue = args[0]->LongValue; + return true; + }*/ + int StdAwk::OpenFile (File^ file) { System::IO::FileMode mode; diff --git a/ase/net/StdAwk.hpp b/ase/net/StdAwk.hpp index 211b7f8a..c45e5c8f 100644 --- a/ase/net/StdAwk.hpp +++ b/ase/net/StdAwk.hpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.hpp,v 1.5 2007/08/20 14:19:58 bacon Exp $ + * $Id: StdAwk.hpp,v 1.6 2007/08/26 14:33:38 bacon Exp $ */ #include @@ -16,9 +16,19 @@ namespace ASE ~StdAwk (); protected: + System::Random^ random; + bool Sin (System::String^ name, array^ args, Return^ ret); bool Cos (System::String^ name, array^ args, Return^ ret); bool Tan (System::String^ name, array^ args, Return^ ret); + bool Atan (System::String^ name, array^ args, Return^ ret); + bool Atan2 (System::String^ name, array^ args, Return^ ret); + bool Log (System::String^ name, array^ args, Return^ ret); + bool Exp (System::String^ name, array^ args, Return^ ret); + bool Sqrt (System::String^ name, array^ args, Return^ ret); + bool Int (System::String^ name, array^ args, Return^ ret); + //bool Rand (System::String^ name, array^ args, Return^ ret); + //bool Srand (System::String^ name, array^ args, Return^ ret); public protected: // File diff --git a/ase/test/awk/Awk.cpp b/ase/test/awk/Awk.cpp index c8d2a529..902311ae 100644 --- a/ase/test/awk/Awk.cpp +++ b/ase/test/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.31 2007/07/20 09:23:37 bacon Exp $ + * $Id: Awk.cpp,v 1.32 2007/08/26 14:33:38 bacon Exp $ */ #include @@ -530,6 +530,8 @@ static void print_usage (const ase_char_t* argv0) ase_printf (ASE_T(" -w o:n Specify an old and new word pair\n")); ase_printf (ASE_T(" o - an original word\n")); ase_printf (ASE_T(" n - the new word to replace the original\n")); + ase_printf (ASE_T(" -ns Don't strip whitespaces\n")); + ase_printf (ASE_T(" The STRIPSPACES option is truned off\n")); } int awk_main (int argc, ase_char_t* argv[]) @@ -561,6 +563,10 @@ int awk_main (int argc, ase_char_t* argv[]) else if (ase_strcmp(argv[i], ASE_T("-a")) == 0) mode = 5; else if (ase_strcmp(argv[i], ASE_T("-m")) == 0) mode = 6; else if (ase_strcmp(argv[i], ASE_T("-w")) == 0) mode = 7; + else if (ase_strcmp(argv[i], ASE_T("-ns")) == 0) + { + awk.setOption (awk.getOption () & ~TestAwk::OPT_STRIPSPACES); + } else { print_usage (argv[0]); diff --git a/ase/test/awk/asm.awk b/ase/test/awk/asm.awk new file mode 100644 index 00000000..fb599953 --- /dev/null +++ b/ase/test/awk/asm.awk @@ -0,0 +1,52 @@ +# +# Taken from the book "The AWK Programming Language" +# aseawk++ -si asm.awk -ns -a asm.s +# +# ASEAWK should turn on STRIPSPACES & BASEONE to run this program. +# + +BEGIN { + srcfile = ARGV[1]; + ARGV[1] = ""; + tempfile = "asm.temp"; + n = split("const get put ld st add sub jpos jz j halt", x); + for (i = 1; i <= n; i++) op[x[i]] = i - 1; + +# PASS 1 + FS = "[ \t]+"; + while (getline 0) { + sub (/#.*/, ""); + symtab[$1] = nextmem; + + if ($2 != "") { + print $2 "\t" $3 >tempfile; + nextmem++; + } + } + close (tempfile); + +# PASS 2 + nextmem = 0; + while (getline 0) { + if ($2 !~ /^[0-9]*$/) $2 = symtab[$2]; + mem[nextmem++] = 1000 * op[$1] + $2; + } + +# INTERPRETER + for (pc = 0; pc >= 0; ) { + addr = mem[pc] % 1000; + code = int(mem[pc++] / 1000); + if (code == op["get"]) { getline acc; } + else if (code == op["put"]) { print acc; } + else if (code == op["st"]) { mem[addr] = acc; } + else if (code == op["ld"]) { acc = mem[addr]; } + else if (code == op["add"]) { acc += mem[addr]; } + else if (code == op["sub"]) { acc -= mem[addr]; } + else if (code == op["jpos"]) { if (acc > 0) pc = addr; } + else if (code == op["jz"]) { if (acc == 0) pc = addr; } + else if (code == op["j"]) { pc = addr; } + else if (code == op["halt"]) { pc = -1; } + else { pc = -1; } + } +} + diff --git a/ase/test/awk/asm.s b/ase/test/awk/asm.s new file mode 100644 index 00000000..d1f4e3ab --- /dev/null +++ b/ase/test/awk/asm.s @@ -0,0 +1,14 @@ + ld zero # initialize sum to zero + st sum +loop get # read a number + jz done # no more input if number is zero + add sum # add in accumulated sum + st sum # store new value back in sum + j loop # go back and read another number + +done ld sum # print sum + put + halt + +zero const 0 +sum const diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 658accb6..e0908a64 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.12 2007/06/20 03:48:02 bacon Exp $ + * $Id: awk.c,v 1.13 2007/08/26 14:33:38 bacon Exp $ */ #include @@ -907,7 +907,7 @@ static int awk_main (int argc, ase_char_t* argv[]) ASE_AWK_SHIFT | ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | - ASE_AWK_STRBASEONE | + ASE_AWK_BASEONE | ASE_AWK_STRIPSPACES | ASE_AWK_NEXTOFILE /*| ASE_AWK_ARGSTOMAIN*/;