Compare commits

...

9 Commits

13 changed files with 214 additions and 151 deletions

View File

@ -29,104 +29,81 @@
#ifndef AMATH_H #ifndef AMATH_H
#define AMATH_H #define AMATH_H
/******************************************************************************/
#ifdef __AMIGA__ /* Operating System */
# define SYS_NAME "AmigaOS 3" #if defined(__MORPHOS__)
# ifndef AOS3
# define AOS3
# endif
#endif
/******************************************************************************/
#ifdef __AROS__
# define SYS_NAME "Aros"
# ifndef AROS
# define AROS
# endif
#endif
/******************************************************************************/
#ifdef __MORPHOS__
# define SYS_NAME "MorphOS" # define SYS_NAME "MorphOS"
# ifndef MORPHOS # ifndef MORPHOS
# define MORPHOS # define MORPHOS
# endif # endif
#endif #elif defined(__amigaos4__)
/******************************************************************************/
#ifdef __amigaos4__
# define SYS_NAME "AmigaOS 4" # define SYS_NAME "AmigaOS 4"
# ifndef AOS4 # ifndef AOS4
# define AOS4 # define AOS4
# endif # endif
#endif #elif defined(__AMIGA__) || defined(__amigaos3__)
/******************************************************************************/ # define SYS_NAME "AmigaOS 3"
#ifdef __HAIKU__ # ifndef AOS3
# define AOS3
# endif
#elif defined(__AROS__)
# define SYS_NAME "AROS"
# ifndef AROS
# define AROS
# endif
#elif defined(__HAIKU__)
# define SYS_NAME "Haiku" # define SYS_NAME "Haiku"
# ifndef HAIKU # ifndef HAIKU
# define HAIKU # define HAIKU
# endif # endif
#endif #elif defined(__APPLE__) && defined(__MACH__)
/******************************************************************************/
#ifdef __APPLE__
# define SYS_NAME "Apple" # define SYS_NAME "Apple"
# ifndef APPLE # ifndef APPLE
# define APPLE # define APPLE
# endif # endif
#endif #elif defined(__FreeBSD__)
/******************************************************************************/
#ifdef __FreeBSD__
# define SYS_NAME "FreeBSD" # define SYS_NAME "FreeBSD"
# ifndef FREEBSD # ifndef FREEBSD
# define FREEBSD # define FREEBSD
# endif # endif
#endif #elif defined(__NetBSD__)
/******************************************************************************/
#ifdef __NetBSD__
# define SYS_NAME "NetBSD" # define SYS_NAME "NetBSD"
# ifndef NETBSD # ifndef NETBSD
# define NETBSD # define NETBSD
# endif # endif
#endif #elif defined(__OpenBSD__)
/******************************************************************************/
#ifdef __OpenBSD__
# define SYS_NAME "OpenBSD" # define SYS_NAME "OpenBSD"
# ifndef OPENBSD # ifndef OPENBSD
# define OPENBSD # define OPENBSD
# endif # endif
#endif #elif defined(__DragonFly__)
/******************************************************************************/
#ifdef __DragonFly__
# define SYS_NAME "DragonFly BSD" # define SYS_NAME "DragonFly BSD"
# ifndef DRAGONFLY # ifndef DRAGONFLY
# define DRAGONFLY # define DRAGONFLY
# endif # endif
#endif #elif defined(__linux__)
/******************************************************************************/
#ifdef __linux__
# define SYS_NAME "Linux" # define SYS_NAME "Linux"
# ifndef LINUX # ifndef LINUX
# define LINUX # define LINUX
# endif # endif
#endif #elif defined(_WIN32)
/******************************************************************************/
#ifdef _WIN32
# define SYS_NAME "Windows" # define SYS_NAME "Windows"
# ifndef WINDOWS # ifndef WINDOWS
# define WINDOWS # define WINDOWS
# endif # endif
#endif #elif defined(_WIN64)
/******************************************************************************/
#ifdef _WIN64
# define SYS_NAME "Windows 64 bit" # define SYS_NAME "Windows 64 bit"
# ifndef WINDOWS # ifndef WINDOWS
# define WINDOWS # define WINDOWS
# endif # endif
#endif #endif
/******************************************************************************/
#if defined(AOS3) || defined(AOS4) || defined(AROS) || defined (MORPHOS) #if defined(AOS3) || defined(AOS4) || defined(AROS) || defined (MORPHOS)
# ifndef AMIGA # ifndef AMIGA
# define AMIGA # define AMIGA
# endif # endif
#endif #endif
/******************************************************************************/
#if defined(unix) || defined(__unix__) || defined(__unix) #if defined(unix) || defined(__unix__) || defined(__unix)
# ifndef UNIX # ifndef UNIX
# define UNIX # define UNIX
@ -135,7 +112,7 @@
# define SYS_NAME "Unix variant" # define SYS_NAME "Unix variant"
# endif # endif
#endif #endif
/******************************************************************************/
#if defined(HAIKU) || defined(UNIX) || defined(APPLE) #if defined(HAIKU) || defined(UNIX) || defined(APPLE)
# ifndef TERMIOS # ifndef TERMIOS
# define TERMIOS # define TERMIOS
@ -143,39 +120,38 @@
# include <stdint.h> # include <stdint.h>
# include <unistd.h> # include <unistd.h>
#endif #endif
/******************************************************************************/
#if defined(WINDOWS) #if defined(WINDOWS)
# include <stdint.h> # include <stdint.h>
#endif #endif
/******************************************************************************/
#if defined(AROS) || defined(MORPHOS) || defined(AOS4) #if defined(AROS) || defined(MORPHOS) || defined(AOS4)
# include <stdint.h> # include <stdint.h>
# include <sys/types.h> # include <sys/types.h>
#endif #endif
/******************************************************************************/
#if defined(AOS3) #if defined(AOS3)
# include <sys/types.h> # include <sys/types.h>
# define IPTR LONG*
# define uintptr_t uint32_t # define uintptr_t uint32_t
typedef u_int8_t uint8_t; typedef u_int8_t uint8_t;
typedef u_int16_t uint16_t; typedef u_int16_t uint16_t;
typedef u_int32_t uint32_t; typedef u_int32_t uint32_t;
typedef u_int64_t uint64_t; typedef u_int64_t uint64_t;
#endif #endif
/******************************************************************************/
#if (__cplusplus <= 199711L && !defined(WINDOWS)) || !defined(__cplusplus) #if (__cplusplus <= 199711L && !defined(WINDOWS)) || !defined(__cplusplus)
#ifndef nullptr # ifndef nullptr
#define nullptr 0 # define nullptr 0
#endif # endif
#elif (__cplusplus <= 199711L) && (defined(__GNUC__) || defined(__GNUG__)) #elif (__cplusplus <= 199711L) && (defined(__GNUC__) || defined(__GNUG__))
#ifndef nullptr # ifndef nullptr
#define nullptr 0 # define nullptr 0
# endif
#endif #endif
#endif
/******************************************************************************/
#define assert(x) #define assert(x)
/******************************************************************************/
/* Compilers*/ /* Compilers */
#if defined(__clang__) #if defined(__clang__)
/* Clang */ /* Clang */
# if defined(__apple_build_version__) # if defined(__apple_build_version__)
@ -228,7 +204,9 @@ typedef u_int64_t uint64_t;
# elif (_MSC_VER == 1900) # elif (_MSC_VER == 1900)
# define COMP_VERS "14.0" # define COMP_VERS "14.0"
# elif (_MSC_VER > 1900) # elif (_MSC_VER > 1900)
# define COMP_VERS "15.0+" # define COMP_VERS "15.x"
# elif (_MSC_VER > 1920)
# define COMP_VERS "16.0+"
# else # else
# define str(x) #x # define str(x) #x
# define MSC_VER_STR(x) str(x) # define MSC_VER_STR(x) str(x)
@ -261,11 +239,11 @@ typedef u_int64_t uint64_t;
# define COMP_VERS GCC_VER_STR(__GNUC__) DOT GCC_VER_STR(__GNUC_MINOR__) # define COMP_VERS GCC_VER_STR(__GNUC__) DOT GCC_VER_STR(__GNUC_MINOR__)
# endif # endif
#endif #endif
/******************************************************************************/
#define EMPTYSTRING "" #define EMPTYSTRING ""
#define SPACE " " #define SPACE " "
#define DOT "." #define DOT "."
/******************************************************************************/
#if defined(WINDOWS) #if defined(WINDOWS)
#define NEWLINE "\r\n" #define NEWLINE "\r\n"
#elif defined(APPLE) #elif defined(APPLE)
@ -273,17 +251,17 @@ typedef u_int64_t uint64_t;
#else #else
#define NEWLINE "\n" #define NEWLINE "\n"
#endif #endif
/******************************************************************************/
#ifndef __cplusplus #ifndef __cplusplus
typedef int bool; typedef int bool;
#define true 1 #define true 1
#define false 0 #define false 0
#endif #endif
/******************************************************************************/
#define LONG_BIT 32 #define LONG_BIT 32
#define wsize sizeof(unsigned int) #define wsize sizeof(unsigned int)
#define wmask (wsize - 1) #define wmask (wsize - 1)
/******************************************************************************/
#if defined(INTELCPU) || defined(i386) || defined(i486) || \ #if defined(INTELCPU) || defined(i386) || defined(i486) || \
defined(intel) || defined(x86) || defined(i86pc) || \ defined(intel) || defined(x86) || defined(i86pc) || \
defined(__i386__) || defined(_M_IX86) defined(__i386__) || defined(_M_IX86)
@ -295,18 +273,18 @@ typedef int bool;
#if defined(__x86_64__) || defined(_M_AMD64) #if defined(__x86_64__) || defined(_M_AMD64)
# define TXTCPU "amd64" # define TXTCPU "amd64"
#endif #endif
/******************************************************************************/
#if defined(__powerpc__) || defined(__powerpc64__) #if defined(__powerpc__) || defined(__powerpc64__)
# define TXTCPU "PowerPC" # define TXTCPU "PowerPC"
#endif #endif
/******************************************************************************/
#if defined(__arm__) || defined(_M_ARM) || defined(__ARM_ARCH_6__) #if defined(__arm__) || defined(_M_ARM) || defined(__ARM_ARCH_6__)
# define TXTCPU "arm" # define TXTCPU "arm"
#endif #endif
#if defined(__aarch64__) || defined(_M_ARM64) #if defined(__aarch64__) || defined(_M_ARM64)
# define TXTCPU "arm64" # define TXTCPU "arm64"
#endif #endif
/******************************************************************************/
#if defined(m68060) || defined(mc68060) #if defined(m68060) || defined(mc68060)
# define TXTCPU "68060" # define TXTCPU "68060"
#elif defined(m68040) || defined(mc68040) #elif defined(m68040) || defined(mc68040)
@ -320,33 +298,33 @@ typedef int bool;
#elif defined(m68000) || defined(mc68000) #elif defined(m68000) || defined(mc68000)
# define TXTCPU "68000+" # define TXTCPU "68000+"
#endif #endif
/******************************************************************************/
#ifndef TXTCPU #ifndef TXTCPU
//#error what cpu is this ?! //#error what cpu is this ?!
# define TXTCPU EMPTYSTRING # define TXTCPU EMPTYSTRING
#endif #endif
/******************************************************************************/
#if defined(TXTCPU) && defined(__HAVE_68881__) #if defined(TXTCPU) && defined(__HAVE_68881__)
# define TXTFPU SPACE "FPU" # define TXTFPU SPACE "FPU"
#else #else
# define TXTFPU EMPTYSTRING # define TXTFPU EMPTYSTRING
#endif #endif
/******************************************************************************/
#define TXTARCH TXTCPU TXTFPU #define TXTARCH TXTCPU TXTFPU
#define RELDATESTAMP "(11-01-2021)" #define RELDATESTAMP "(11-01-2021)"
#define TXTDOSVERSION "\0$VER: amath 1.90" SPACE RELDATESTAMP SPACE TXTARCH #define TXTDOSVERSION "\0$VER: amath 1.90" SPACE RELDATESTAMP SPACE TXTARCH
#define TXTTITLE "amath version 1.9.0" #define TXTTITLE "amath version 1.9.0"
#define TXTCOPYRIGHT "(c) 2021 Carsten Sonne Larsen" #define TXTCOPYRIGHT "(c) 2021 Carsten Sonne Larsen"
#define TXTSTARTMSG TXTTITLE SPACE TXTCOPYRIGHT #define TXTSTARTMSG TXTTITLE SPACE TXTCOPYRIGHT
/******************************************************************************/
#define TXTVERSMSG TXTTITLE SPACE RELDATESTAMP SPACE TXTARCH #define TXTVERSMSG TXTTITLE SPACE RELDATESTAMP SPACE TXTARCH
#define TXTCOMPMSG "Compiled with " COMP_NAME SPACE COMP_VERS #define TXTCOMPMSG "Compiled with " COMP_NAME SPACE COMP_VERS
/******************************************************************************/
#ifdef SYS_NAME #ifdef SYS_NAME
# define TXTSYSMSG TXTCOMPMSG " for " SYS_NAME # define TXTSYSMSG TXTCOMPMSG " for " SYS_NAME
# define SYSKNOWN 1 # define SYSKNOWN 1
#else #else
# define TXTSYSMSG TXTCOMPMSG # define TXTSYSMSG TXTCOMPMSG
#endif #endif
/******************************************************************************/
#endif #endif

View File

@ -35,18 +35,22 @@
#include <exec/memory.h> #include <exec/memory.h>
#include <exec/semaphores.h> #include <exec/semaphores.h>
#include <clib/exec_protos.h> #include <clib/exec_protos.h>
#define ALLOC_MEM(x) AllocVec(x, MEMF_ANY | MEMF_CLEAR) #define ALLOC_LIST(x) AllocVec(x, MEMF_ANY | MEMF_CLEAR)
#define FREE_MEM(x) FreeVec(x) #define FREE_LIST(x) FreeVec(x)
#define Debug(x,y,z) #define ALLOC_MEM(x, y) AllocPooledZero(x, y)
#define FREE_MEM(x, y, z) FreePooled(x, y, z)
#define Debug(x, y, z)
#else #else
#include <stdlib.h> #include <stdlib.h>
#define ALLOC_MEM(x) calloc(1L,x) #define ALLOC_LIST(x) calloc(1L, x)
#define FREE_MEM(x) free(x) #define FREE_LIST(x) free(x)
#define Debug(x,y,z) #define ALLOC_MEM(x, y) calloc(1L, y)
#define FREE_MEM(x, y, z) free(y)
#define Debug(x, y, z)
#endif #endif
#if defined(__x86_64__) || defined(__aarch64__) || \ #if defined(__x86_64__) || defined(__aarch64__) || \
defined(_M_AMD64) || defined(_M_ARM64) || \ defined(_M_AMD64) || defined(_M_ARM64) || \
defined(__powerpc64__) defined(__powerpc64__)
#define P64BIT #define P64BIT
#endif #endif
@ -56,9 +60,9 @@
*/ */
struct MemoryBlock struct MemoryBlock
{ {
struct MemoryBlock* next; struct MemoryBlock *next;
size_t size; size_t size;
void* address; void *address;
}; };
/** /**
@ -66,7 +70,8 @@ struct MemoryBlock
*/ */
struct MemoryList struct MemoryList
{ {
struct MemoryBlock* first; struct MemoryBlock *first;
void *pool;
size_t peak; size_t peak;
size_t size; size_t size;
long count; long count;
@ -75,28 +80,56 @@ struct MemoryList
/** /**
* @brief Global list of allocated memory. * @brief Global list of allocated memory.
*/ */
struct MemoryList* list = nullptr; struct MemoryList *list = nullptr;
void alloc_error(char*, size_t); void alloc_error(char *, size_t);
void dealloc_error(char*, void*); void dealloc_error(char *, void *);
#if defined(AMIGA)
static void MemZero(void *address, ULONG size)
{
char *c = (char *)address;
int n = size;
do
{
*c++ = '\0';
} while (--n);
}
static void *AllocPooledZero(void *pool, size_t size)
{
ULONG memSize = (ULONG)size;
void *memory = AllocPooled(pool, memSize);
if (memory != NULL)
{
MemZero(memory, memSize);
}
return memory;
}
#endif
/** /**
* @brief Allocate memory and add it to the global memory list. * @brief Allocate memory and add it to the global memory list.
*/ */
void* AllocMemSafe(size_t size) void *AllocMemSafe(size_t size)
{ {
struct MemoryBlock* newblock; struct MemoryBlock *newblock;
size_t allocsize; size_t allocsize;
if (list == nullptr) if (list == nullptr)
{ {
list = (struct MemoryList*)ALLOC_MEM(sizeof(struct MemoryList)); list = (struct MemoryList *)ALLOC_LIST(sizeof(struct MemoryList));
if (!list) if (!list)
{ {
alloc_error("list", sizeof(struct MemoryList)); alloc_error("list", sizeof(struct MemoryList));
return 0; return 0;
} }
#if defined(AMIGA)
list->pool = CreatePool(MEMF_ANY, 4096, 512);
#endif
list->first = nullptr; list->first = nullptr;
list->peak = 0; list->peak = 0;
list->size = 0; list->size = 0;
@ -104,24 +137,24 @@ void* AllocMemSafe(size_t size)
} }
#ifdef P64BIT #ifdef P64BIT
// Align to bytes of 8 // Align to bytes of 8, remove 0 bytes allocations
allocsize = (size + 7) & ~0x07; allocsize = (size + 8) & ~0x07;
#else #else
// Align to bytes of 4 // Align to bytes of 4, remove 0 bytes allocations
allocsize = (size + 3) & ~0x03; allocsize = (size + 4) & ~0x03;
#endif #endif
newblock = (struct MemoryBlock*)ALLOC_MEM(sizeof(struct MemoryBlock)); newblock = (struct MemoryBlock *)ALLOC_MEM(list->pool, sizeof(struct MemoryBlock));
if (!newblock) if (newblock == NULL)
{ {
alloc_error("block", sizeof(struct MemoryBlock)); alloc_error("block", sizeof(struct MemoryBlock));
return 0; return 0;
} }
newblock->address = (struct MemoryBlock*)ALLOC_MEM(allocsize); newblock->address = (struct MemoryBlock *)ALLOC_MEM(list->pool, allocsize);
if (!newblock->address) if (newblock->address == NULL)
{ {
FREE_MEM(newblock); FREE_MEM(list->pool, newblock, sizeof(struct MemoryBlock));
alloc_error("memory", allocsize); alloc_error("memory", allocsize);
return 0; return 0;
} }
@ -141,7 +174,7 @@ void* AllocMemSafe(size_t size)
return newblock->address; return newblock->address;
} }
void RemoveMemSafe(void* block, bool deallocate) void RemoveMemSafe(void *block, bool deallocate)
{ {
struct MemoryBlock *current, *previous; struct MemoryBlock *current, *previous;
@ -185,19 +218,19 @@ void RemoveMemSafe(void* block, bool deallocate)
if (deallocate) if (deallocate)
{ {
FREE_MEM(current->address); FREE_MEM(list->pool, current->address, current->size);
} }
current->address = nullptr; current->address = nullptr;
current->next = nullptr; current->next = nullptr;
current->size = 0; current->size = 0;
FREE_MEM(current); FREE_MEM(list->pool, current, sizeof(struct MemoryBlock));
} }
/** /**
* @brief Deallocate memory from the global memory list. * @brief Deallocate memory from the global memory list.
*/ */
void FreeMemSafe(void* block) void FreeMemSafe(void *block)
{ {
RemoveMemSafe(block, true); RemoveMemSafe(block, true);
} }
@ -206,7 +239,7 @@ void FreeMemSafe(void* block)
* @brief Detach an allocated memory from the global memory list. * @brief Detach an allocated memory from the global memory list.
* @details The memory block is only detached, not deallocated. * @details The memory block is only detached, not deallocated.
*/ */
void DetachMemSafe(void* block) void DetachMemSafe(void *block)
{ {
RemoveMemSafe(block, false); RemoveMemSafe(block, false);
} }
@ -227,29 +260,34 @@ void FreeAllSafe()
while (current != nullptr) while (current != nullptr)
{ {
next = current->next; next = current->next;
FREE_MEM(current->address); FREE_MEM(list->pool, current->address, current->size);
FREE_MEM(current); FREE_MEM(list->pool, current, sizeof(struct MemoryBlock));
current = next; current = next;
} }
FREE_MEM(list); #if defined(AMIGA)
DeletePool(list->pool);
#endif
FREE_LIST(list);
list = nullptr; list = nullptr;
} }
/** /**
* @brief Get memory usage in the global memory list. * @brief Get memory usage in the global memory list.
*/ */
void MemUsage(long* blocks, long* size, long* peak) void MemUsage(long *blocks, long *size, long *peak)
{ {
*blocks = list->count; *blocks = list->count;
*size = (long)list->size; *size = (long)list->size;
*peak = (long)list->peak;; *peak = (long)list->peak;
;
} }
/** /**
* @brief Log a memory allocation error * @brief Log a memory allocation error
*/ */
void alloc_error(char* descr, size_t size) void alloc_error(char *descr, size_t size)
{ {
Debug("Memory allocation error (%s) with size (%d)\n", descr, size); Debug("Memory allocation error (%s) with size (%d)\n", descr, size);
//if (size == 0) //if (size == 0)
@ -259,7 +297,7 @@ void alloc_error(char* descr, size_t size)
/** /**
* @brief Log a memory deallocation error * @brief Log a memory deallocation error
*/ */
void dealloc_error(char* descr, void* p) void dealloc_error(char *descr, void *p)
{ {
Debug("Memory deallocation error (%s) address (%x)\n", descr, p); Debug("Memory deallocation error (%s) address (%x)\n", descr, p);
} }

View File

@ -37,6 +37,7 @@ Evaluator::Evaluator(const char* input)
{ {
this->input = input; this->input = input;
output = new CharBuffer(); output = new CharBuffer();
ResultOnly = false;
} }
Evaluator::~Evaluator() Evaluator::~Evaluator()
@ -52,6 +53,7 @@ void Evaluator::Evaluate() const
output->ClearBuffer(); output->ClearBuffer();
Parser* parser = new Parser(input); Parser* parser = new Parser(input);
parser->ResultOnly = ResultOnly;
SyntaxNode* node = parser->Parse(); SyntaxNode* node = parser->Parse();
delete parser; delete parser;

View File

@ -35,14 +35,20 @@
class Evaluator class Evaluator
{ {
public: public:
explicit Evaluator(const char* input); explicit Evaluator(const char *input);
~Evaluator(); ~Evaluator();
/**
* @brief Do not include expression string in evaluation result.
*/
bool ResultOnly;
void Evaluate() const; void Evaluate() const;
char* GetResult() const; char *GetResult() const;
private: private:
const char* input; const char *input;
CharBuffer* output; CharBuffer *output;
}; };
#endif #endif

View File

@ -46,6 +46,7 @@ Parser::Parser(const char* input)
token = nullptr; token = nullptr;
errorNode = nullptr; errorNode = nullptr;
syntaxError = 0; syntaxError = 0;
ResultOnly = false;
} }
Parser::~Parser() Parser::~Parser()
@ -224,7 +225,7 @@ SyntaxNode* Parser::ParseStatement()
res = new ListFunctionsStatement(); res = new ListFunctionsStatement();
break; break;
case symeval: case symeval:
res = new EvalStatement(ParseExpression()); res = new EvalStatement(ParseExpression(), ResultOnly);
break; break;
default: default:
PutToken(); PutToken();
@ -266,7 +267,7 @@ SyntaxNode* Parser::ParseEvaluation()
return nullptr; return nullptr;
} }
StatementNode* sta = new EvalStatement(exp); StatementNode* sta = new EvalStatement(exp, ResultOnly);
if (exp->IsSilent()) if (exp->IsSilent())
{ {
sta = new SilentStatement(sta); sta = new SilentStatement(sta);

View File

@ -52,6 +52,11 @@ public:
explicit Parser(const char* input); explicit Parser(const char* input);
~Parser(); ~Parser();
/**
* @brief Do not include expression string in evaluation result.
*/
bool ResultOnly;
/** /**
* @brief Parses the input into a syntax tree. * @brief Parses the input into a syntax tree.
* *

View File

@ -32,9 +32,10 @@
#include "amathc.h" #include "amathc.h"
#include "system/program.h" #include "system/program.h"
EvalStatement::EvalStatement(ExpressionNode* expression) : EvalStatement::EvalStatement(ExpressionNode *expression, bool resultOnly) :
StatementNode(), expression(expression) StatementNode(), expression(expression)
{ {
this->resultOnly = resultOnly;
} }
EvalStatement::~EvalStatement() EvalStatement::~EvalStatement()
@ -45,31 +46,41 @@ EvalStatement::~EvalStatement()
} }
} }
char* EvalStatement::Execute() char *EvalStatement::Execute()
{ {
Number* result = expression->Evaluate(); Number *result = expression->Evaluate();
Number* temp = result->Clone(); Number *temp = result->Clone();
const char* text = expression->GetText(); const char *val = Program->Output->GetText(result);
const char* val = Program->Output->GetText(result);
Program->SetLastResult(temp); Program->SetLastResult(temp);
delete temp; delete temp;
output->Empty(); if (resultOnly)
output->EnsureSize( {
StrLen(text) + 3 + output->Empty();
StrLen(val) + output->EnsureSize(StrLen(val) + 1);
StrLen(NEWLINE) + 1); output->Append(val);
}
else
{
const char *text = expression->GetText();
output->Append(text); output->Empty();
output->Append(" = "); output->EnsureSize(
output->Append(val); StrLen(text) + 3 +
output->Append(NEWLINE); StrLen(val) +
StrLen(NEWLINE) + 1);
output->Append(text);
output->Append(" = ");
output->Append(val);
output->Append(NEWLINE);
}
return output->GetString(); return output->GetString();
} }
SyntaxNode* EvalStatement::GetNext() SyntaxNode *EvalStatement::GetNext()
{ {
if (iterator == nullptr) if (iterator == nullptr)
{ {
@ -80,16 +91,16 @@ SyntaxNode* EvalStatement::GetNext()
return nullptr; return nullptr;
} }
void EvalStatement::Attach(SyntaxNode* node) void EvalStatement::Attach(SyntaxNode *node)
{ {
if (expression == nullptr) if (expression == nullptr)
{ {
expression = static_cast<ExpressionNode*>(node); expression = static_cast<ExpressionNode *>(node);
node->SetParent(this); node->SetParent(this);
} }
} }
void EvalStatement::Detach(SyntaxNode* node) void EvalStatement::Detach(SyntaxNode *node)
{ {
if (expression == node) if (expression == node)
{ {
@ -97,11 +108,11 @@ void EvalStatement::Detach(SyntaxNode* node)
} }
} }
void EvalStatement::Replace(SyntaxNode* n, SyntaxNode* x) void EvalStatement::Replace(SyntaxNode *n, SyntaxNode *x)
{ {
if (expression == n) if (expression == n)
{ {
delete expression; delete expression;
expression = static_cast<ExpressionNode*>(x); expression = static_cast<ExpressionNode *>(x);
} }
} }

View File

@ -39,7 +39,7 @@
class EvalStatement : public virtual StatementNode class EvalStatement : public virtual StatementNode
{ {
public: public:
explicit EvalStatement(ExpressionNode* expression); explicit EvalStatement(ExpressionNode* expression, bool resultOnly);
~EvalStatement(); ~EvalStatement();
char* Execute(); char* Execute();
@ -50,6 +50,7 @@ public:
private: private:
ExpressionNode* expression; ExpressionNode* expression;
bool resultOnly;
}; };
#endif #endif

View File

@ -193,15 +193,17 @@ bool AmigaARexx::HandleMessage(struct RexxMsg *message)
message->rm_Result1 = 0; message->rm_Result1 = 0;
Evaluator *evaluator = new Evaluator(message->rm_Args[0]);
evaluator->ResultOnly = true;
evaluator->Evaluate();
if (message->rm_Action & RXFF_RESULT) if (message->rm_Action & RXFF_RESULT)
{ {
Evaluator *evaluator = new Evaluator(message->rm_Args[0]);
evaluator->Evaluate();
const char *result = evaluator->GetResult(); const char *result = evaluator->GetResult();
message->rm_Result2 = (LONG)CreateArgstring((STRPTR)result, (LONG)StrLen(result)); message->rm_Result2 = (LONG)CreateArgstring((STRPTR)result, (LONG)StrLen(result));
delete evaluator;
} }
delete evaluator;
return true; return true;
} }

View File

@ -80,6 +80,11 @@ void AmigaShellConsole::ReadLine()
{ {
Flush(Input()); Flush(Input());
FGets(Input(), line, linesize); FGets(Input(), line, linesize);
if (CheckSignal(SIGBREAKF_CTRL_C))
{
exit = true;
}
} }
void AmigaShellConsole::WriteString(const char* string) void AmigaShellConsole::WriteString(const char* string)

View File

@ -104,7 +104,12 @@ char* AmigaLanguage::Translate(identhelpdef *def)
char AmigaLanguage::GetFractionPoint() char AmigaLanguage::GetFractionPoint()
{ {
#if defined(STRICT_LOCAL)
return locale->loc_DecimalPoint[0]; return locale->loc_DecimalPoint[0];
#else
// To ensure compatibility, set fraction point to full stop / period
return '.';
#endif
} }
bool AmigaLanguage::CharIsAlNum(long unsigned int character) bool AmigaLanguage::CharIsAlNum(long unsigned int character)

View File

@ -71,12 +71,12 @@ static struct GfxBase *GfxBase = nullptr;
static struct LocaleBase *LocaleBase = nullptr; static struct LocaleBase *LocaleBase = nullptr;
static struct IntuitionBase *IntuitionBase = nullptr; static struct IntuitionBase *IntuitionBase = nullptr;
#define ARGS_FORMAT "SHELL/S,NOANSI/S,INPUT/F" #define ARGS_FORMAT "SHELL/S,NOANSI/S,AREXX/S,INPUT/F"
#if defined(AOS3) #if defined(AROS)
#define RDPTR LONG *
#else
#define RDPTR IPTR * #define RDPTR IPTR *
#else
#define RDPTR LONG *
#endif #endif
AmigaProgram::AmigaProgram() AmigaProgram::AmigaProgram()
@ -90,6 +90,7 @@ AmigaProgram::AmigaProgram()
rdargs = nullptr; rdargs = nullptr;
args.shell = FALSE; args.shell = FALSE;
args.noansi = FALSE; args.noansi = FALSE;
args.arexx = FALSE;
args.input = nullptr; args.input = nullptr;
Console = nullptr; Console = nullptr;
} }
@ -179,7 +180,14 @@ void AmigaProgram::Start()
AmigaARexx *arexx = new AmigaARexx(); AmigaARexx *arexx = new AmigaARexx();
arexx->Start(); arexx->Start();
Console->Start(); if (args.arexx)
{
Wait(SIGBREAKF_CTRL_C);
}
else
{
Console->Start();
}
arexx->Stop(); arexx->Stop();
delete arexx; delete arexx;

View File

@ -37,6 +37,7 @@ struct amathargs
{ {
long shell; long shell;
long noansi; long noansi;
long arexx;
char* input; char* input;
}; };