help: Move selection of help to hel() method

Instead of having a big switch statement in the `Help` command,
dispatch to the `help()` method in the various types. Not exactly sure
why this was not done this way initially.

Fixes: #378

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2023-09-30 18:38:30 +02:00
parent 257773267f
commit 5d2d16ff6e
23 changed files with 170 additions and 34 deletions

View file

@ -61,6 +61,15 @@ RENDER_BODY(array)
}
HELP_BODY(array)
// ----------------------------------------------------------------------------
// Help topic for arrays
// ----------------------------------------------------------------------------
{
return utf8("Vectors and matrices");
}
// ============================================================================
//

View file

@ -85,6 +85,7 @@ public:
OBJECT_DECL(array);
PARSE_DECL(array);
RENDER_DECL(array);
HELP_DECL(array);
};

View file

@ -111,6 +111,15 @@ PARSE_BODY(bignum)
}
HELP_BODY(bignum)
// ----------------------------------------------------------------------------
// Help topic for big integers
// ----------------------------------------------------------------------------
{
return utf8("Big integers");
}
static size_t render_num(renderer &r,
bignum_p num,
uint base,

View file

@ -194,6 +194,7 @@ public:
OBJECT_DECL(bignum);
PARSE_DECL(bignum);
RENDER_DECL(bignum);
HELP_DECL(bignum);
};

View file

@ -506,7 +506,7 @@ COMMAND_BODY(Help)
if (rt.depth())
{
if (!rt.args(10))
if (!rt.args(1))
return ERROR;
if (object_p top = rt.top())
{
@ -522,39 +522,7 @@ COMMAND_BODY(Help)
}
else
{
switch(top->type())
{
case ID_integer:
case ID_neg_integer: topic = utf8("Integers"); break;
case ID_fraction:
case ID_neg_fraction:
case ID_big_fraction:
case ID_neg_big_fraction: topic = utf8("Fractions"); break;
case ID_bignum:
case ID_neg_bignum: topic = utf8("Big integers"); break;
case ID_polar:
case ID_rectangular: topic = utf8("Complex numbers"); break;
#if CONFIG_FIXED_BASED_OBJECTS
case ID_hex_integer:
case ID_dec_integer:
case ID_oct_integer:
case ID_bin_integer:
case ID_hex_bignum:
case ID_dec_bignum:
case ID_oct_bignum:
case ID_bin_bignum:
#endif // CONFIG_FIXED_BASED_OBJECTS
case ID_based_integer:
case ID_based_bignum: topic = utf8("Based numbers"); break;
case ID_decimal128:
case ID_decimal64:
case ID_decimal32: topic = utf8("Decimal numbers"); break;
case ID_equation: topic = utf8("Equations"); break;
case ID_list: topic = utf8("Lists"); break;
case ID_array: topic = utf8("Vectors and matrices"); break;
case ID_tag: topic = utf8("Tagged objects"); break;
default: topic = fancy(top->type()); break;
}
topic = top->help();
}
}
}

View file

@ -59,6 +59,15 @@ SIZE_BODY(complex)
}
HELP_BODY(complex)
// ----------------------------------------------------------------------------
// Help topic for complex numbers
// ----------------------------------------------------------------------------
{
return utf8("Complex numbers");
}
algebraic_g complex::re() const
// ----------------------------------------------------------------------------
// Return real part in a format-independent way

View file

@ -103,6 +103,7 @@ public:
SIZE_DECL(complex);
PARSE_DECL(complex);
PREC_DECL(COMPLEX);
HELP_DECL(complex);
public:
// Complex implementation for main functions

View file

@ -141,6 +141,15 @@ SIZE_BODY(decimal32)
}
HELP_BODY(decimal32)
// ----------------------------------------------------------------------------
// Help topic for decimal numbers
// ----------------------------------------------------------------------------
{
return utf8("Decimal numbers");
}
PARSE_BODY(decimal32)
// ----------------------------------------------------------------------------
// Try to parse this as an decimal32

View file

@ -260,6 +260,7 @@ public:
OBJECT_DECL(decimal32);
PARSE_DECL(decimal32);
SIZE_DECL(decimal32);
HELP_DECL(decimal32);
RENDER_DECL(decimal32);
};

View file

@ -141,6 +141,15 @@ SIZE_BODY(decimal64)
}
HELP_BODY(decimal64)
// ----------------------------------------------------------------------------
// Help topic for decimal numbers
// ----------------------------------------------------------------------------
{
return utf8("Decimal numbers");
}
PARSE_BODY(decimal64)
// ----------------------------------------------------------------------------
// Try to parse this as an decimal64

View file

@ -260,6 +260,7 @@ public:
OBJECT_DECL(decimal64);
PARSE_DECL(decimal64);
SIZE_DECL(decimal64);
HELP_DECL(decimal64);
RENDER_DECL(decimal64);
};

View file

@ -141,6 +141,15 @@ SIZE_BODY(decimal128)
}
HELP_BODY(decimal128)
// ----------------------------------------------------------------------------
// Help topic for decimal numbers
// ----------------------------------------------------------------------------
{
return utf8("Decimal numbers");
}
PARSE_BODY(decimal128)
// ----------------------------------------------------------------------------
// Try to parse this as an decimal128

View file

@ -260,6 +260,7 @@ public:
OBJECT_DECL(decimal128);
PARSE_DECL(decimal128);
SIZE_DECL(decimal128);
HELP_DECL(decimal128);
RENDER_DECL(decimal128);
};

View file

@ -68,6 +68,15 @@ PARSE_BODY(equation)
}
HELP_BODY(equation)
// ----------------------------------------------------------------------------
// Help topic for equations
// ----------------------------------------------------------------------------
{
return utf8("Equations");
}
symbol_g equation::parentheses(symbol_g arg)
// ----------------------------------------------------------------------------
// Render, putting parentheses around an argument

View file

@ -127,6 +127,7 @@ public:
OBJECT_DECL(equation);
PARSE_DECL(equation);
RENDER_DECL(equation);
HELP_DECL(equation);
public:
// Dependent and independent variables

View file

@ -63,6 +63,15 @@ SIZE_BODY(fraction)
}
HELP_BODY(fraction)
// ----------------------------------------------------------------------------
// Help topic for fractions
// ----------------------------------------------------------------------------
{
return utf8("Fractions");
}
EVAL_BODY(fraction)
// ----------------------------------------------------------------------------
// Evaluate either as a fraction or decimal

View file

@ -97,6 +97,7 @@ struct fraction : algebraic
public:
OBJECT_DECL(fraction);
SIZE_DECL(fraction);
HELP_DECL(fraction);
EVAL_DECL(fraction);
RENDER_DECL(fraction);
PREC_DECL(MULTIPLICATIVE);

View file

@ -52,6 +52,15 @@ SIZE_BODY(integer)
}
HELP_BODY(integer)
// ----------------------------------------------------------------------------
// Help topic for integers
// ----------------------------------------------------------------------------
{
return utf8("Integers");
}
PARSE_BODY(integer)
// ----------------------------------------------------------------------------
// Try to parse this as an integer
@ -454,6 +463,15 @@ RENDER_BODY(integer)
}
template <>
HELP_BODY(neg_integer)
// ------------------------------------------------------------------------
// Help topic for negative integers
// ----------------------------------------------------------------------------
{
return utf8("Integers");
}
template <>
RENDER_BODY(neg_integer)
// ----------------------------------------------------------------------------
@ -500,6 +518,43 @@ RENDER_BODY(bin_integer)
{
return render_num(r, o, 2, "#b");
}
template <>
HELP_BODY(hex_integer)
// ----------------------------------------------------------------------------
// Help topic for based numbers
// ----------------------------------------------------------------------------
{
return utf8("Based numbers");
}
template <>
HELP_BODY(oct_integer)
// ----------------------------------------------------------------------------
// Help topic for based numbers
// ----------------------------------------------------------------------------
{
return utf8("Based numbers");
}
template <>
HELP_BODY(dec_integer)
// ----------------------------------------------------------------------------
// Help topic for based numbers
// ----------------------------------------------------------------------------
{
return utf8("Based numbers");
}
template <>
HELP_BODY(bin_integer)
// ----------------------------------------------------------------------------
// Help topic for based numbers
// ----------------------------------------------------------------------------
{
return utf8("Based numbers");
}
#endif // CONFIG_FIXED_BASED_OBJECTS
@ -513,6 +568,16 @@ RENDER_BODY(based_integer)
}
template <>
HELP_BODY(based_integer)
// ----------------------------------------------------------------------------
// Help topic for based numbers
// ----------------------------------------------------------------------------
{
return utf8("Based numbers");
}
RENDER_BODY(fraction)
// ----------------------------------------------------------------------------
// Render the fraction as 'num/den'

View file

@ -121,6 +121,7 @@ public:
OBJECT_DECL(integer);
PARSE_DECL(integer);
SIZE_DECL(integer);
HELP_DECL(integer);
RENDER_DECL(integer);
};
@ -138,8 +139,10 @@ public:
static const id static_id = Type;
PARSE_DECL(special_integer) { return SKIP; }
RENDER_DECL(special_integer);
HELP_DECL(special_integer);
};
using neg_integer = special_integer<object::ID_neg_integer>;
#if CONFIG_FIXED_BASED_OBJECTS
using hex_integer = special_integer<object::ID_hex_integer>;

View file

@ -400,6 +400,15 @@ RENDER_BODY(list)
}
HELP_BODY(list)
// ----------------------------------------------------------------------------
// Help topic for lists
// ----------------------------------------------------------------------------
{
return utf8("Lists");
}
// ============================================================================
//

View file

@ -284,6 +284,7 @@ public:
OBJECT_DECL(list);
PARSE_DECL(list);
RENDER_DECL(list);
HELP_DECL(list);
};
typedef const list *list_p;

View file

@ -46,6 +46,15 @@ SIZE_BODY(tag)
}
HELP_BODY(tag)
// ----------------------------------------------------------------------------
// Help topic for tagged objects
// ----------------------------------------------------------------------------
{
return utf8("Tagged objects");
}
PARSE_BODY(tag)
// ----------------------------------------------------------------------------
// Try to parse this as a tag, i.e. :LABEL:Object

View file

@ -102,6 +102,7 @@ public:
OBJECT_DECL(tag);
PARSE_DECL(tag);
SIZE_DECL(tag);
HELP_DECL(tag);
RENDER_DECL(tag);
EXEC_DECL(tag);
};