DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦6c9f32a89⟧ TextFile

    Length: 5194 (0x144a)
    Types: TextFile
    Notes: UNIX file
    Names: »bcmch.h«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »cmd/bc/bcmch.h« 

TextFile

/*
 *	The typedef rvalue defines the basic entity upon which bc
 *	operates.
 */

typedef struct {
	mint	mantissa;
	int	scale;
}	rvalue;


/*
 *	The typedef array defines the concept of an array of rvalues.
 */

typedef struct {
	rvalue	*avalue;
	int	size;
}	array;


/*
 *	The typedef bcstate is used to hold the state of the bc-
 *	pseudo machine which should be restored when returning from
 *	a function call.
 */

typedef struct {
	union code	*spc;		/* pc to return to */
	union stkent	*sfp,		/* frame pointer to return to */
			*stos;		/* stack pointer to return to */
} bcstate;


/*
 *	The typedef stkent defines the union used for run-time stack
 *	entries.
 */

typedef union  stkent {
	rvalue		rvalue,
			*lvalue;
	array		*alvalue;
	bcstate		bcstate;
}	stkent;


/*
 *	The typedef opcode is the list of opcodes for the hypothetical
 *	bc-machine.
 */

typedef enum {
	LOAD,		/*
			 * Convert TOS from an l_value to an r_value.
			 */

	LIBASE, LOBASE, LSCALE,
			/*
			 * Push the r_value of the special variable ibase
			 * (resp. obase, scale).
			 */

	STORE,		/*
			 * Store the r_value TOS at the l_value
			 * TOS[-1].  Leave the r_value on the stack
			 * but remove the l_value.
			 */

	SIBASE, SOBASE, SSCALE,
			/*
			 * Copy the r_value in TOS into ibase (rep. obase,
			 * scale).  Also, check to see that the value is
			 * acceptable.
			 */

	POP,		/*
			 * Throw away the r_value TOS.
			 */

	PRVAL,		/*
			 * Push the r_value corresponding to the l_value TOS
			 * onto the stack.  Note that the old TOS is left
			 * on the stack.
			 */

	PGLSC, PLOSC,	/*
			 * Push the l_value of a global (local) scalar onto
			 * the stack.  The address (resp. stack frame offset)
			 * of the scalar follows the opcode.
			 */

	PGLAE, PLOAE,	/*
			 * Push the l_value of a global (local) array
			 * element onto the stack.  The address (resp. stack
			 * frame offset) of the array follows the opcode
			 * and TOS is the subscript.  Note that the subscript
			 * is first removed from the stack.
			 */

	PGLAR, PLOAR,	/*
			 * Push the l_value of a global (local) array onto
			 * the stack.  The address (resp. stack fram offset)
			 * of the array follows the opcode.  (Used to pass
			 * an entire array as a function argument.)
			 */

	STOP,		/*
			 * Stop interpreting bc-machine pseudo-instructions
			 * and return.  This is only used at the end of
			 * the code compiled for immediate execution.
			 */

	CALL,		/*
			 * Call the function whoose dictionary entry
			 * is pointed to by the word following this
			 * opcode.  The number of arguments is contained
			 * in the word following that.
			 * Just before the CALL, the stack looks like:
			 *	TOS->	last parameter
			 *		...
			 *		first parameter
			 *		rest of stack
			 * and just after the CALL, it looks like:
			 *	TOS->	state to return to
			 *		last automatic variable
			 *		...
			 *		first automatic variable
			 *		last parameter
			 *		...
			 *	FRAME->	first parameter
			 *		rest of stack
			 */

	RETURN,		/*
			 * Return from the function whoose dictionary entry
			 * is pointed to by the word following this opcode.
			 * Just before the RETURN, the stack looks like:
			 *	TOS->	r_value to return
			 *		state to return to
			 *		last automatic variable
			 *		...
			 *		first automatic variable
			 *		last parameter
			 *		...
			 *	FRAME->	first parameter
			 *		rest of stack
			 * Just after the RETURN, the stack looks like:
			 *	TOS->	r_value returned
			 *		rest of stack
			 * Note that all prameters and automatic variables
			 * must be freed and removed from the stack.
			 */

	INC, DEC,	/*
			 * Add 1 (resp. -1) to the r_value TOS.
			 */

	PRNUM,		/*
			 * Print the r_value TOS and then remove it from
			 * the stack.
			 */

	PRSTR,		/*
			 * Print the string whoose address follows this
			 * opcode.  Note that no newline is added.
			 */

	PRNL,		/*
			 * Print a new line character.
			 */

	LENGTH, SCALE, SQRT,
			/*
			 * Replace the r_value TOS with its length in bytes,
			 * scale factor, or square root respectively.
			 */

	ADD, SUB, MUL, DIV, REM, EXP,
			/*
			 * Replace the r_values TOS and TOS[-1] with
			 * TOS + TOS[-1] (resp. TOS - TOS[-1], TOS * TOS[-1],
			 * TOS / TOS[-1], TOS % TOS[-1], TOS ^ TOS[-1]).
			 */

	NEG,		/*
			 * Replace the r_value TOS with -TOS.
			 */

	BRALW, BRNEV,	/*
			 * Branch always (respectively never).  The new
			 * pc will be the address of the following code
			 * item plus its contents.
			 */
	BRLT, BRLE, BREQ, BRGE, BRGT, BRNE
			/*
			 * Branch if the r_value TOS[-1] is less than
			 * (respectively less or equal, equal,
			 * greater or equal, greater and unequal)
			 * then the r_value TOS.  Note that both TOS and
			 * TOS[-1] are removed from the stack.
			 */
} opcode;


/*
 *	The typedef code is the type of entry in the array of
 *	pseudo-code which the pseudo-machine executes.
 */

typedef union code {
	opcode		opcode;
	int		address;	/* relative code address */
	rvalue		*lvalue;	/* global scalar or constant */
	array		*alvalue;	/* global array */
	char		*svalue;	/* string */
	int		ivalue;		/* stack offset and misc. counts */
	struct dicent	*dvalue;	/* function name */
} code;