Skip to content

Commit

Permalink
help: Move selection of help to hel() method
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
c3d committed Sep 30, 2023
1 parent 2577732 commit 5d2d16f
Show file tree
Hide file tree
Showing 23 changed files with 170 additions and 34 deletions.
9 changes: 9 additions & 0 deletions src/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ RENDER_BODY(array)
}


HELP_BODY(array)
// ----------------------------------------------------------------------------
// Help topic for arrays
// ----------------------------------------------------------------------------
{
return utf8("Vectors and matrices");
}



// ============================================================================
//
Expand Down
1 change: 1 addition & 0 deletions src/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct array : list
OBJECT_DECL(array);
PARSE_DECL(array);
RENDER_DECL(array);
HELP_DECL(array);
};


Expand Down
9 changes: 9 additions & 0 deletions src/bignum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ struct bignum : text
OBJECT_DECL(bignum);
PARSE_DECL(bignum);
RENDER_DECL(bignum);
HELP_DECL(bignum);
};


Expand Down
36 changes: 2 additions & 34 deletions src/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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();
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/complex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct complex : algebraic
SIZE_DECL(complex);
PARSE_DECL(complex);
PREC_DECL(COMPLEX);
HELP_DECL(complex);

public:
// Complex implementation for main functions
Expand Down
9 changes: 9 additions & 0 deletions src/decimal-32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/decimal-32.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ struct decimal32 : algebraic
OBJECT_DECL(decimal32);
PARSE_DECL(decimal32);
SIZE_DECL(decimal32);
HELP_DECL(decimal32);
RENDER_DECL(decimal32);
};

Expand Down
9 changes: 9 additions & 0 deletions src/decimal-64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/decimal-64.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ struct decimal64 : algebraic
OBJECT_DECL(decimal64);
PARSE_DECL(decimal64);
SIZE_DECL(decimal64);
HELP_DECL(decimal64);
RENDER_DECL(decimal64);
};

Expand Down
9 changes: 9 additions & 0 deletions src/decimal128.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/decimal128.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ struct decimal128 : algebraic
OBJECT_DECL(decimal128);
PARSE_DECL(decimal128);
SIZE_DECL(decimal128);
HELP_DECL(decimal128);
RENDER_DECL(decimal128);
};

Expand Down
9 changes: 9 additions & 0 deletions src/equation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/equation.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct equation : program
OBJECT_DECL(equation);
PARSE_DECL(equation);
RENDER_DECL(equation);
HELP_DECL(equation);

public:
// Dependent and independent variables
Expand Down
9 changes: 9 additions & 0 deletions src/fraction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/fraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
65 changes: 65 additions & 0 deletions src/integer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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


Expand All @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions src/integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct integer : algebraic
OBJECT_DECL(integer);
PARSE_DECL(integer);
SIZE_DECL(integer);
HELP_DECL(integer);
RENDER_DECL(integer);
};

Expand All @@ -138,8 +139,10 @@ struct special_integer : integer
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>;
Expand Down
9 changes: 9 additions & 0 deletions src/list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ RENDER_BODY(list)
}


HELP_BODY(list)
// ----------------------------------------------------------------------------
// Help topic for lists
// ----------------------------------------------------------------------------
{
return utf8("Lists");
}



// ============================================================================
//
Expand Down
1 change: 1 addition & 0 deletions src/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ struct list : text
OBJECT_DECL(list);
PARSE_DECL(list);
RENDER_DECL(list);
HELP_DECL(list);
};
typedef const list *list_p;

Expand Down
9 changes: 9 additions & 0 deletions src/tag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5d2d16f

Please sign in to comment.