Example #1
0
static void dump_param_list(struct param_list *params)
{
    struct param *p;
    int nparams = 0;

    for (p = params->required_params; p != NULL; p = p->next)
        nparams++;
    dump_integer(nparams);
    for (p = params->required_params; p != NULL; p = p->next) {
        dump_id(p->id);
        if (p->type)
            dump_expr(p->type);
        else
            dump_op(fop_FALSE);
    }

    if (params->next_param)
        dump_id(params->next_param);
    else
        dump_op(fop_FALSE);

    if (params->rest_param)
        dump_id(params->rest_param);
    else
        dump_op(fop_FALSE);

    if (params->allow_keys) {
        struct keyword_param *k;
        int nkeys = 0;

        for (k = params->keyword_params; k != NULL; k = k->next)
            nkeys++;
        dump_integer(nkeys);

        for (k = params->keyword_params; k != NULL; k = k->next) {
            dump_symbol(k->keyword);
            dump_id(k->id);
            if (k->type)
                dump_expr(k->type);
            else
                dump_op(fop_FALSE);
            if (k->def)
                dump_expr(k->def);
            else
                dump_op(fop_FALSE);
        }
    }
    else
        dump_op(fop_FALSE);
}
Example #2
0
static void dump_debug_info(struct component *c)
{
    struct debug_info *info;

    dump_vector_header(c->ndebug_infos);
    for (info = c->debug_info; info != NULL; info = info->next) {
        dump_op(fop_VECTOR3);
        dump_integer(info->line);
        dump_integer(info->bytes);
        if (info->scope)
            dump_vars(info->scope);
        else
            dump_op(fop_NIL);
    }
}
Example #3
0
static void dump_vars(struct scope_info *scope)
{
    struct var_info *var_info;

    if (scope->handle != -1)
        dump_ref(scope->handle);
    else {
        scope->handle = dump_store();

        if (scope->outer)
            dump_op(fop_DOTTED_LIST1);
        else
            dump_op(fop_LIST1);

        dump_vector_header(scope->nvars);
        for (var_info=scope->vars; var_info != NULL; var_info=var_info->next) {
            int loc_info = var_info->offset << 2;
            if (var_info->indirect)
                loc_info |= 2;
            if (var_info->argument)
                loc_info |= 1;

            dump_op(fop_VECTOR2);
            dump_symbol(var_info->var->symbol);
            dump_integer(loc_info);
        }

        if (scope->outer)
            dump_vars(scope->outer);
    }
}
Example #4
0
static void dump_plist(struct plist *plist)
{
    if (plist) {
        struct property *p;
        int nprops = 0;

        for (p = plist->head; p != NULL; p = p->next)
            nprops++;
        dump_integer(nprops);
        for (p = plist->head; p != NULL; p = p->next) {
            dump_symbol(p->keyword);
            dump_expr(p->expr);
        }
    }
    else
        dump_integer(0);
}
Example #5
0
void dump_setup_output(char *source, FILE *file)
{
    struct stat buf;
    time_t tv;
    int statres;

    File = file;

#if ! NO_SHARP_BANG
    fprintf(File, "#! /usr/bin/env mindy -x\n");
#endif
    fprintf(File, "# %s (%d.%d) of %s\n", "compilation",
            file_MajorVersion, file_MinorVersion, source);
    statres = stat(source, &buf);
    if (statres >= 0)
        fprintf(File, "# last modified on %s", ctime(&buf.st_mtime));
    fprintf(File, "# produced with the %s version of mindycomp\n", Version);
    time(&tv);
    fprintf(File, "# at %s", ctime(&tv));

    dump_op(fop_HEADER);
    dump_byte(file_MajorVersion);
    dump_byte(file_MinorVersion);
    dump_byte(sizeof(short));
    dump_byte(sizeof(int));
    dump_byte(sizeof(long));
    dump_byte(sizeof(float));
    dump_byte(sizeof(double));
    dump_byte(sizeof(long double));
    dump_short(1);
    dump_int(dbc_MagicNumber);
    dump_op(fop_IN_LIBRARY);
    if (LibraryName)
        dump_symbol(LibraryName);
    else
        dump_symbol(sym_DylanUser);
    if (source != NULL) {
        dump_op(fop_SOURCE_FILE);
        if (statres >= 0)
            dump_integer(buf.st_mtime);
        else
            dump_integer(0);
        dump_string_guts(fop_SHORT_STRING, fop_STRING, source, strlen(source));
    }
}
Example #6
0
static void dump_body(struct body *body)
{
    struct constituent *c;
    int nconstits = 0;

    for (c = body->head; c != NULL; c = c->next)
        nconstits++;
    dump_integer(nconstits);
    for (c = body->head; c != NULL; c = c->next)
        (*DumpConstituents[(int)c->kind])(c);
}
Example #7
0
static void dump_call_expr(struct call_expr *expr)
{
    struct argument *args;
    int nargs = 0;

    dump_op(fop_CALL_EXPR);
    dump_expr(expr->func);
    for (args = expr->args; args != NULL; args = args->next)
        nargs++;
    dump_integer(nargs);
    for (args = expr->args; args != NULL; args = args->next)
        dump_expr(args->expr);
}
Example #8
0
static void dump_local_constituent(struct local_constituent *c)
{
    struct method *m;
    int nlocals = 0;

    dump_op(fop_LOCAL_CONSTITUENT);
    for (m = c->methods; m != NULL; m = m->next_local)
        nlocals++;
    dump_integer(nlocals);
    for (m = c->methods; m != NULL; m = m->next_local)
        dump_method_parse(m);
    dump_body(c->body);
}
Example #9
0
static void dump_defconst_or_var(struct param_list *params)
{
    int count;
    struct param *p;

    count = 0;
    for (p = params->required_params; p != NULL; p = p->next)
        count++;
    if (params->rest_param)
        count++;

    dump_integer(count);
    for (p = params->required_params; p != NULL; p = p->next)
        dump_symbol(p->id->symbol);
    if (params->rest_param)
        dump_symbol(params->rest_param->symbol);
}
Example #10
0
static void dump_rettypes(struct return_type_list *rettypes)
{
    struct return_type *r;
    int nreq = 0;

    if (rettypes != NULL) {
        for (r = rettypes->req_types; r != NULL; r = r->next)
            nreq++;
        dump_integer(nreq);
        for (r = rettypes->req_types; r != NULL; r = r->next)
            if (r->type)
                dump_expr(r->type);
            else
                dump_op(fop_FALSE);
        if (rettypes->rest_type)
            dump_expr(r->type);
        else
            dump_op(fop_FALSE);
    }
    else
        dump_op(fop_FALSE);
}
Example #11
0
static void dump_component(struct component *c)
{
    struct constant *constant;
    struct block *block;
    int bytes;

    if (c->nconstants <= UCHAR_MAX && c->bytes <= USHRT_MAX) {
        dump_op(fop_SHORT_COMPONENT);
        dump_byte(c->nconstants);
        dump_short((short)(c->bytes));
    }
    else {
        dump_op(fop_COMPONENT);
        dump_int(c->nconstants);
        dump_int(c->bytes);
    }

    if (c->debug_name)
        dump_literal(c->debug_name);
    else
        dump_op(fop_FALSE);

    dump_integer(c->frame_size);

    dump_debug_info(c);

    for (constant = c->constants; constant != NULL; constant = constant->next)
        dump_constant(constant);

    bytes = 0;
    for (block = c->blocks; block != NULL; block = block->next) {
        int count = block->end - block->bytes;
        dump_bytes(block->bytes, count);
        bytes += count;
    }
    if (bytes != c->bytes)
        lose("Planned on writing %d bytes, but ended up writing %d instead.",
             c->bytes, bytes);
}
Example #12
0
static void dump_defclass_constituent(struct defclass_constituent *c)
{
    struct superclass *super;
    struct slot_spec *slot;
    struct initarg_spec *initarg;
    struct inherited_spec *inherited;
    int n;

    dump_op(fop_DEFINE_CLASS);

    n = 0;
    for (super = c->supers; super != NULL; super = super->next)
        n++;
    dump_integer(n);
    for (super = c->supers; super != NULL; super = super->next)
        dump_expr(super->expr);

    n = 0;
    for (slot = c->slots; slot != NULL; slot = slot->next)
        n++;
    dump_integer(n);
    for (slot = c->slots; slot != NULL; slot = slot->next) {
        switch (slot->alloc) {
          case alloc_INSTANCE:
            dump_symbol(sym_Instance);
            break;
          case alloc_CLASS:
            dump_symbol(sym_Class);
            break;
          case alloc_EACH_SUBCLASS:
            dump_symbol(sym_Each_Subclass);
            break;
          case alloc_VIRTUAL:
            dump_symbol(sym_Virtual);
            break;
          default:
            lose("strange slot allocation");
        }
        if (slot->name)
            dump_id(slot->name);
        else
            dump_op(fop_FALSE);
        if (slot->type)
            dump_expr(slot->type);
        else
            dump_op(fop_FALSE);
        dump_plist(slot->plist);
    }

    n = 0;
    for (initarg = c->initargs; initarg != NULL; initarg = initarg->next)
        n++;
    dump_integer(n);
    for (initarg = c->initargs; initarg != NULL; initarg = initarg->next) {
        dump_symbol(initarg->keyword);
        dump_plist(initarg->plist);
    }

    n = 0;
    for (inherited = c->inheriteds; inherited != NULL;
         inherited = inherited->next)
        n++;
    dump_integer(n);
    for (inherited = c->inheriteds; inherited != NULL;
         inherited = inherited->next) {
        dump_id(inherited->name);
        dump_plist(inherited->plist);
    }
}
Example #13
0
static void dump_id(struct id *id)
{
    dump_symbol(id->symbol);
    dump_op(id->internal ? fop_TRUE : fop_FALSE);
    dump_integer(id->line);
}
Example #14
0
static void dump_integer_literal(struct integer_literal *literal)
{
    dump_integer(literal->value);
}
Example #15
0
    /*!
    @brief internal implementation of the serialization function

    This function is called by the public member function dump and organizes
    the serialization internally. The indentation level is propagated as
    additional parameter. In case of arrays and objects, the function is
    called recursively.

    - strings and object keys are escaped using `escape_string()`
    - integer numbers are converted implicitly via `operator<<`
    - floating-point numbers are converted to a string using `"%g"` format

    @param[in] val             value to serialize
    @param[in] pretty_print    whether the output shall be pretty-printed
    @param[in] indent_step     the indent level
    @param[in] current_indent  the current indent level (only used internally)
    */
    void dump(const BasicJsonType& val, const bool pretty_print,
              const bool ensure_ascii,
              const unsigned int indent_step,
              const unsigned int current_indent = 0)
    {
        switch (val.m_type)
        {
            case value_t::object:
            {
                if (val.m_value.object->empty())
                {
                    o->write_characters("{}", 2);
                    return;
                }

                if (pretty_print)
                {
                    o->write_characters("{\n", 2);

                    // variable to hold indentation for recursive calls
                    const auto new_indent = current_indent + indent_step;
                    if (JSON_UNLIKELY(indent_string.size() < new_indent))
                    {
                        indent_string.resize(indent_string.size() * 2, ' ');
                    }

                    // first n-1 elements
                    auto i = val.m_value.object->cbegin();
                    for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
                    {
                        o->write_characters(indent_string.c_str(), new_indent);
                        o->write_character('\"');
                        dump_escaped(i->first, ensure_ascii);
                        o->write_characters("\": ", 3);
                        dump(i->second, true, ensure_ascii, indent_step, new_indent);
                        o->write_characters(",\n", 2);
                    }

                    // last element
                    assert(i != val.m_value.object->cend());
                    assert(std::next(i) == val.m_value.object->cend());
                    o->write_characters(indent_string.c_str(), new_indent);
                    o->write_character('\"');
                    dump_escaped(i->first, ensure_ascii);
                    o->write_characters("\": ", 3);
                    dump(i->second, true, ensure_ascii, indent_step, new_indent);

                    o->write_character('\n');
                    o->write_characters(indent_string.c_str(), current_indent);
                    o->write_character('}');
                }
                else
                {
                    o->write_character('{');

                    // first n-1 elements
                    auto i = val.m_value.object->cbegin();
                    for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
                    {
                        o->write_character('\"');
                        dump_escaped(i->first, ensure_ascii);
                        o->write_characters("\":", 2);
                        dump(i->second, false, ensure_ascii, indent_step, current_indent);
                        o->write_character(',');
                    }

                    // last element
                    assert(i != val.m_value.object->cend());
                    assert(std::next(i) == val.m_value.object->cend());
                    o->write_character('\"');
                    dump_escaped(i->first, ensure_ascii);
                    o->write_characters("\":", 2);
                    dump(i->second, false, ensure_ascii, indent_step, current_indent);

                    o->write_character('}');
                }

                return;
            }

            case value_t::array:
            {
                if (val.m_value.array->empty())
                {
                    o->write_characters("[]", 2);
                    return;
                }

                if (pretty_print)
                {
                    o->write_characters("[\n", 2);

                    // variable to hold indentation for recursive calls
                    const auto new_indent = current_indent + indent_step;
                    if (JSON_UNLIKELY(indent_string.size() < new_indent))
                    {
                        indent_string.resize(indent_string.size() * 2, ' ');
                    }

                    // first n-1 elements
                    for (auto i = val.m_value.array->cbegin();
                            i != val.m_value.array->cend() - 1; ++i)
                    {
                        o->write_characters(indent_string.c_str(), new_indent);
                        dump(*i, true, ensure_ascii, indent_step, new_indent);
                        o->write_characters(",\n", 2);
                    }

                    // last element
                    assert(not val.m_value.array->empty());
                    o->write_characters(indent_string.c_str(), new_indent);
                    dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);

                    o->write_character('\n');
                    o->write_characters(indent_string.c_str(), current_indent);
                    o->write_character(']');
                }
                else
                {
                    o->write_character('[');

                    // first n-1 elements
                    for (auto i = val.m_value.array->cbegin();
                            i != val.m_value.array->cend() - 1; ++i)
                    {
                        dump(*i, false, ensure_ascii, indent_step, current_indent);
                        o->write_character(',');
                    }

                    // last element
                    assert(not val.m_value.array->empty());
                    dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);

                    o->write_character(']');
                }

                return;
            }

            case value_t::string:
            {
                o->write_character('\"');
                dump_escaped(*val.m_value.string, ensure_ascii);
                o->write_character('\"');
                return;
            }

            case value_t::boolean:
            {
                if (val.m_value.boolean)
                {
                    o->write_characters("true", 4);
                }
                else
                {
                    o->write_characters("false", 5);
                }
                return;
            }

            case value_t::number_integer:
            {
                dump_integer(val.m_value.number_integer);
                return;
            }

            case value_t::number_unsigned:
            {
                dump_integer(val.m_value.number_unsigned);
                return;
            }

            case value_t::number_float:
            {
                dump_float(val.m_value.number_float);
                return;
            }

            case value_t::discarded:
            {
                o->write_characters("<discarded>", 11);
                return;
            }

            case value_t::null:
            {
                o->write_characters("null", 4);
                return;
            }
        }
    }