Major progress, multiply now almost works

There's a premature free() somewhere, and I'm not sure why.

Print depends on divide, which is easy, but also on mod and floor (of rationals) which isn't.
This commit is contained in:
Simon Brooke 2019-01-21 16:14:25 +00:00
parent 64fc43e9fc
commit 3fd322af6f
5 changed files with 287 additions and 144 deletions

View file

@ -17,66 +17,40 @@ bool zerop( struct cons_pointer arg );
struct cons_pointer negative( struct cons_pointer frame,
struct cons_pointer arg );
/**
* \todo cannot throw an exception out of here, which is a problem.
* if a ratio may legally have zero as a divisor, or something which is
* not a number is passed in.
*/
bool is_negative( struct cons_pointer arg);
struct cons_pointer absolute( struct cons_pointer frame_pointer, struct cons_pointer arg);
long double to_long_double( struct cons_pointer arg );
/**
* Add an indefinite number of numbers together
* @param env the evaluation environment - ignored;
* @param frame the stack frame.
* @return a pointer to an integer or real.
*/
struct cons_pointer lisp_absolute( struct stack_frame
*frame, struct cons_pointer frame_pointer, struct
cons_pointer env );
struct cons_pointer
lisp_add( struct stack_frame *frame, struct cons_pointer frame_pointer,
struct cons_pointer env );
/**
* Multiply an indefinite number of numbers together.
* @param env the evaluation environment - ignored;
* @param frame the stack frame.
* @return a pointer to an integer or real.
*/
struct cons_pointer lisp_is_negative( struct stack_frame
*frame, struct cons_pointer frame_pointer, struct
cons_pointer env );
struct cons_pointer
lisp_multiply( struct stack_frame *frame,
struct cons_pointer frame_pointer, struct cons_pointer env );
/**
* return a cons_pointer indicating a number which is the
* 0 - the number indicated by `arg`.
*/
struct cons_pointer negative( struct cons_pointer frame,
struct cons_pointer arg );
/**
* return a cons_pointer indicating a number which is the result of
* subtracting the numbers indicated by `arg2` from that indicated by `arg1`,
* in the context of this `frame`.
*/
struct cons_pointer subtract_2( struct stack_frame *frame,
struct cons_pointer frame_pointer,
struct cons_pointer arg1,
struct cons_pointer arg2 );
/**
* Subtract one number from another.
* @param env the evaluation environment - ignored;
* @param frame the stack frame.
* @return a pointer to an integer or real.
*/
struct cons_pointer
lisp_subtract( struct stack_frame *frame,
struct cons_pointer frame_pointer, struct cons_pointer env );
/**
* Divide one number by another.
* @param env the evaluation environment - ignored;
* @param frame the stack frame.
* @return a pointer to an integer or real.
*/
struct cons_pointer
lisp_divide( struct stack_frame *frame, struct cons_pointer frame_pointer,
struct cons_pointer env );