Пример #1
0
	cons_ptr_t cdr(const cons_ptr_t& arg, environment_t& env) 
	{ 
		if (length(arg) != 1)
			throw std::exception("invalid number of arguments for car");

		return as_list(eval(arg->car(), env))->cdr();
	}
Пример #2
0
	bool is_nil(const cons_ptr_t& arg, environment_t& env) 
	{
		if (length(arg) != 1)
			throw std::exception("invalid number of arguments for is_nil");

		return !as_list(eval(arg->car(), env));
	}
Пример #3
0
	cons_ptr_t quote(const cons_ptr_t& arg) 
	{ 
		if (length(arg) != 1)
			throw std::exception("invalid number of arguments for quote");

		return as_list(arg->car()); 
	}
Пример #4
0
static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams,
                       const environment_t &vars) {
    const wchar_t *scope_name;
    switch (scope) {
        case ENV_LOCAL: {
            scope_name = L"local";
            break;
        }
        case ENV_GLOBAL: {
            scope_name = L"global";
            break;
        }
        case ENV_UNIVERSAL: {
            scope_name = L"universal";
            break;
        }
        default: {
            DIE("invalid scope");
            break;
        }
    }

    const auto var = vars.get(var_name, scope);
    if (!var) {
        streams.out.append_format(_(L"$%ls: not set in %ls scope\n"), var_name, scope_name);
        return;
    }

    const wchar_t *exportv = var->exports() ? _(L"exported") : _(L"unexported");
    wcstring_list_t vals = var->as_list();
    streams.out.append_format(_(L"$%ls: set in %ls scope, %ls, with %d elements\n"), var_name,
                              scope_name, exportv, vals.size());
    for (size_t i = 0; i < vals.size(); i++) {
        if (vals.size() > 100) {
            if (i == 50) streams.out.append(L"...\n");
            if (i >= 50 && i < vals.size() - 50) continue;
        }
        const wcstring value = vals[i];
        const wcstring escaped_val =
            escape_string(value, ESCAPE_NO_QUOTED, STRING_STYLE_SCRIPT);
        streams.out.append_format(_(L"$%ls[%d]: length=%d value=|%ls|\n"), var_name, i + 1,
                                  value.size(), escaped_val.c_str());
    }
}
Пример #5
0
module * module_parser::parse(const module_source & source, istream & text_stream)
{
    if (verbose<module_parser>::enabled())
        cout << "Parsing " << source.path << endl;

    ast::node_ptr ast;

    {
        stream::parsing::driver parser(text_stream, cout, source);

        int error = parser.parse();

        if (error)
            throw parser_error();

        ast = parser.ast();

        if (verbose<ast::output>::enabled())
        {
            cout << endl << "## AST for file " << source.path << " ##" << endl;
            ast::printer p;
            p.print(ast.get());
            cout << endl;
        }
    }

    auto & elems = ast->as_list()->elements;

    string mod_name;
    if (elems[0])
        mod_name = elems[0]->as_leaf<string>()->value;
    else
        mod_name = "m";

#if 0
    if (m_named_modules.find(mod_name) != m_named_modules.end())
    {
        ostringstream msg;
        msg << "Module " << mod_name << " is already imported.";
        throw io_error(msg.str());
    }
#endif

    if (verbose<module_parser>::enabled())
        cout << "Module name = " << mod_name << endl;

    auto mod = new module;
    mod->source = source;
    mod->name = mod_name;
    mod->ast = ast;
    m_named_modules.emplace(mod_name, mod);

    unordered_map<string, module*> imported_mods;

    auto imports_node = elems[1];
    if (imports_node)
    {
        for (auto & import_node : imports_node->as_list()->elements)
        {
            auto import_decl = parse_import(mod, import_node);
            imported_mods.insert(import_decl);
        }
    }

    mod->imports = imported_mods;

    m_ordered_modules.push_back(mod);

    if (verbose<module_parser>::enabled())
        cout << "Done parsing " << source.path << endl;

    return mod;
}
Пример #6
0
		list_t *entity_list;

		if (value_type(val) == BOOLTYPE) {
			if (as_bool(val)) {
				entity_list = create_list();
				list_t *iplist = dsui_get_ips_byfamily(fam_name);
				list_for_each(pos, iplist) {
					struct datastream_ip *ip = pos->item;
					list_append(entity_list, encap_string(ip->ip->name));
				}
				list_free(iplist);
			} else {
				continue;
			}
		} else {
			entity_list = as_list(val);
		}

		list_for_each(pos, entity_list) {
			invocation_t *hist_invoc = NULL;
			char *ent_name;
			struct datastream_ip *ip;
			union ds_entity_info *info = NULL;

			if (!unlist_invoc(pos, &hist_invoc)) {
				ent_name = hist_invoc->name;
			} else {
				unlist_string(pos, &ent_name);
			}

			ip = dsui_get_ip_byname(