#include "semval.h"

#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include "../jmpcond.h"

#include "../deadcode/deadcode.h"
#include "../symtab/symtab.h"
#include "../stringstore/stringstore.h"

//#define msgx
#include "../../msg.h"

extern Opcode s_lastOpcode;

    // 'pos' == 0 means: jump back to the begin of the code,
    //    otherwise jump forward to the end of the code
void sp_patchup(SemVal *sv, unsigned *list, unsigned listlen, int pos);

void sp_appendCode(SemVal *sv, int value, register unsigned size);

void sp_patchTrue(SemVal *sv);
void sp_patchFalse(SemVal *sv);
void sp_patchContinue(SemVal *sv);
void sp_patchAdd(register unsigned value, unsigned **dest, 
                 unsigned *dlen, unsigned *source, unsigned slen);

void sp_upType(SemVal *sv, int exprTypeOrValue);

    // args is a SemVal Argument structure
unsigned sp_argsCodelen(SemVal *args, unsigned begin, unsigned count);

    // dest: first code destination address (must already have been allocated
    //       to contain the code of the nArgs arguments)
    // arg: SemVal argument structure (code pushing arguments)
    // nArgs: #arguments to push.
void sp_pushReversed(int8_t *dest, SemVal *arg, unsigned nArgs);

void sp_downType(SemVal *sv, int exprTypeOrValue);

void sp_upType(SemVal *sv, int exprTypeOrValue);
