Beispiel #1
0
void world_initialize(World* world)
{
    initialize_null(&world->modulesByName);
    initialize_null(&world->modulesByFilename);
    initialize_null(&world->everyModule);
    initialize_null(&world->fileSources);
    initialize_null(&world->moduleSearchPaths);

    set_hashtable(&world->modulesByName);
    set_hashtable(&world->modulesByFilename);
    set_list(&world->everyModule);
    set_list(&world->moduleSearchPaths);
    set_list(&world->fileSources);

    world->moduleSearchPaths.append_str("$builtins");

    world->fileWatchWorld = alloc_file_watch_world();
    world->builtinPatch = circa_create_native_patch(world, "builtins");

    #if CIRCA_ENABLE_LIBUV
        world->libuvWorld = alloc_libuv_world();
    #endif

    perlin_init();
}
Beispiel #2
0
void List__slice(caStack* stack)
{
    caValue* input = circa_input(stack, 0);
    int start = circa_int_input(stack, 1);
    int end = circa_int_input(stack, 2);
    caValue* output = circa_output(stack, 0);

    if (start < 0)
        start = 0;
    else if (start > list_length(input))
        start = list_length(input);

    if (end > list_length(input))
        end = list_length(input);
    else if (end < 0)
        end = list_length(input) + end;

    if (end < start) {
        set_list(output, 0);
        return;
    }

    int length = end - start;
    set_list(output, length);

    for (int i=0; i < length; i++)
        copy(list_get(input, start + i), list_get(output, i));
}
Beispiel #3
0
Type* create_compound_type()
{
    Type* type = create_type();

    list_t::setup_type(type);
    caValue* param = &type->parameter;
    set_list(param, 2);
    set_list(list_get(param, 0), 0);
    set_list(list_get(param, 1), 0);
    return type;
}
Beispiel #4
0
void perf_stats_to_list(caValue* list)
{
    set_list(list, c_numPerfStats);
    for (int i = c_firstStatIndex; i < name_LastStatIndex-1; i++) {
        Name name = i;
        int64 value = PERF_STATS[i - c_firstStatIndex];
        caValue* element = list_get(list, i - c_firstStatIndex);
        set_list(element, 2);
        set_string(list_get(element, 0), builtin_name_to_string(name));
        char buf[100];
        sprintf(buf, "%llu", value);
        set_string(list_get(element, 1), buf);
    }
}
void Branch__get_static_errors_formatted(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    if (branch == NULL)
        return circa_output_error(stack, "NULL branch");

    if (is_null(&branch->staticErrors))
        set_list(circa_output(stack, 0), 0);

    caValue* errors = &branch->staticErrors;
    caValue* out = circa_output(stack, 0);
    set_list(out, circa_count(errors));
    for (int i=0; i < circa_count(out); i++)
        format_static_error(circa_index(errors, i), circa_index(out, i));
}
Beispiel #6
0
/*
 * The parser. This implements the grammar:
 *    setfile::= (arch())+ <EOF>
 *             | <EOF>
 *    arch::= <ARCHITECTURE> "{" (set_list())* "}"
 *    set_list::= (set())+ ";"
 *    set::= <IDENTIFIER> ["[" "WEAK" "]"] ":" "{" (ancestors) "}" ";"
 *    ancestors::= <IDENTIFIER> | <ancestors> "," <IDENTIFIER>
 *    where <ARCHITECTURE> and <IDENTIFIER> are tokens.
 */
static int
arch(void)
{
	int olderrors;

	errlog(BEGIN, "arch() {");
	if (comment()) {
		errlog(END, "} /* arch */");
		return (TRUE);
	}
	if (arch_name() == FALSE) {
		errlog(END, "} /* arch */");
		return (FALSE);
	}
	if (accept_token("{") == FALSE) {
		errlog(END, "} /* arch */");
		return (FALSE);
	}

	olderrors = Errors;
	if (set_list() == FALSE) {
		if (olderrors != Errors) {
			errlog(END, "} /* arch */");
			return (FALSE);
		}
	}

	errlog(END, "} /* arch */");
	return (TRUE);
}
Beispiel #7
0
void get_relative_name_as_list(Term* term, Block* relativeTo, Value* nameOutput)
{
    set_list(nameOutput, 0);

    // Walk upwards and build the name, stop when we reach relativeTo.
    // The output list will be reversed but we'll fix that.

    while (true) {
        set_value(list_append(nameOutput), unique_name(term));

        if (term->owningBlock == relativeTo) {
            break;
        }

        term = parent_term(term);

        // If term is null, then it wasn't really a child of relativeTo
        if (term == NULL) {
            set_null(nameOutput);
            return;
        }
    }

    // Fix output list
    list_reverse(nameOutput);
}
Beispiel #8
0
void config_address(void)
{
  struct Buffer err;
  mutt_buffer_init(&err);
  err.dsize = 256;
  err.data = mutt_mem_calloc(1, err.dsize);
  mutt_buffer_reset(&err);

  struct ConfigSet *cs = cs_new(30);

  address_init(cs);
  dont_fail = true;
  if (!cs_register_variables(cs, Vars, 0))
    return;
  dont_fail = false;

  cs_add_listener(cs, log_listener);

  set_list(cs);

  TEST_CHECK(test_initial_values(cs, &err));
  TEST_CHECK(test_string_set(cs, &err));
  TEST_CHECK(test_string_get(cs, &err));
  TEST_CHECK(test_native_set(cs, &err));
  TEST_CHECK(test_native_get(cs, &err));
  TEST_CHECK(test_reset(cs, &err));
  TEST_CHECK(test_validator(cs, &err));
  TEST_CHECK(test_inherit(cs, &err));

  cs_free(&cs);
  FREE(&err.data);
}
Beispiel #9
0
List*
List::lazyCast(caValue* v)
{
    if (!is_list(v))
        set_list(v, 0);
    return (List*) v;
}
Beispiel #10
0
static void update_patch_function_lookup_for_module(NativePatch* module)
{
    World* world = module->world;
    caValue* everyPatchedFunction = &world->nativePatchWorld->everyPatchedFunction;

    caValue* targetName = &module->targetName;

    // Look at every function that this module patches.
    std::map<std::string, EvaluateFunc>::const_iterator it;

    for (it = module->patches.begin(); it != module->patches.end(); it++) {

        Value functionName;
        set_string(&functionName, it->first.c_str());

        // Construct a global name for this function, using the block's global name.

        Value globalName;
        copy(targetName, &globalName);
        string_append_qualified_name(&globalName, &functionName);

        // Save this line.
        caValue* entry = hashtable_insert(everyPatchedFunction, &globalName);
        set_list(entry, 2);
        copy(&module->targetName, list_get(entry, 0));
        copy(&functionName, list_get(entry, 1));
    }
}
Beispiel #11
0
void symbol_initialize_global_table()
{
    g_runtimeSymbolMap = new Value();
    set_hashtable(g_runtimeSymbolMap);
    g_runtimeSymbolTable = new Value();
    set_list(g_runtimeSymbolTable, 0);
}
void CommandList::clean_history_callback()
{
	QStringList list;
	//model->setStringList(list);
	project_history.clear();
	set_list(list);
}
Beispiel #13
0
void Block__get_static_errors_formatted(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    Value* errors = block_get_static_errors(block);
    if (errors == NULL) {
        set_list(vm->output(), 0);
        return;
    }

    Value* out = vm->output();
    set_list(out, circa_count(errors));
    for (int i=0; i < circa_count(out); i++)
        format_static_error(circa_index(errors, i), circa_index(out, i));
}
Beispiel #14
0
Control::Control(const Parameter&               parameter,
                 const ParameterDescriptor&     desc,
                 boost::shared_ptr<ControlList> list)
	: _parameter(parameter)
	, _user_value(list ? list->default_value() : desc.normal)
{
	set_list (list);
}
void overload__get_contents(caStack* stack)
{
    Branch* self = (Branch*) circa_branch(circa_input(stack, 0));
    caValue* out = circa_output(stack, 0);
    set_list(out, 0);

    list_overload_contents(self, out);
}
Beispiel #16
0
FileWatch* add_file_watch_native_patch(World* world, const char* filename, const char* moduleName)
{
    circa::Value action;
    set_list(&action, 2);
    set_int(list_get(&action, 0), name_NativePatch);
    set_string(list_get(&action, 1), moduleName);
    return add_file_watch_action(world, filename, &action);
}
Beispiel #17
0
FileWatch* add_file_watch_module_load(World* world, const char* filename, const char* moduleName)
{
    circa::Value action;
    set_list(&action, 2);
    set_symbol(list_get(&action, 0), sym_PatchBlock);
    set_string(list_get(&action, 1), moduleName);
    return add_file_watch_action(world, filename, &action);
}
void Branch__get_static_errors(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));

    if (is_null(&branch->staticErrors))
        set_list(circa_output(stack, 0), 0);
    else
        copy(&branch->staticErrors, circa_output(stack, 0));
}
Beispiel #19
0
/**
 * Adds the actor to the Repsheet
 *
 * @param context the Redis connection
 * @param actor the actors user data or ip address
 * @param type IP or USER
 * @reason string to describe the reason for marking
 *
 * @returns an integer result
 */
int mark(redisContext *context, const char *actor, int type, const char *reason)
{
  redisReply *reply;

  switch(type) {
  case IP:
    return set_list(context, actor, "ip", "marked", reason);
    break;
  case USER:
    return set_list(context, actor, "user", "marked", reason);
    break;
  case BLOCK:
    return set_block(context, actor, "marked", reason);
  default:
    return UNSUPPORTED;
    break;
  }
}
Beispiel #20
0
void test_write_fake_file(const char* filename, int version, const char* contents)
{
    Value key;
    set_string(&key, filename);
    Value* entry = hashtable_insert(gFakeFileMap, &key);
    set_list(entry, 2);
    set_int(list_get(entry, 0), version);
    set_string(list_get(entry, 1), contents);
}
Beispiel #21
0
int run_command_line(caWorld* world, int argc, const char* args[])
{
    Value args_v;
    set_list(&args_v, 0);
    for (int i=1; i < argc; i++)
        circa_set_string(circa_append(&args_v), args[i]);

    return run_command_line(world, &args_v);
}
Beispiel #22
0
int main()
{
	int readsocks;
	int i;
	int x;
	struct timeval tv;
	tv.tv_sec = 0;
	tv.tv_usec = 10;
	
    while(1) {
	i=0;
	while(i < MAX_CLIENT)
	{
		cli_con();
		i++;	
	        printf(".");
		fflush(stdout);
                usleep(100);
	}
	i=0;
	while(i < MAX_CLIENT)
	{
		printf("list[%d] = %d\n",i,list[i]);
		i++;
        usleep(100);
	}
	i = 0;
        x = 0;
	while(x < 2)
	{
		set_list();
                readsocks = 0;
//		readsocks = select(highfd+1, &fdset, NULL, NULL, &tv);
		if(readsocks < 0) {
			perror("select\n");
			exit(1);
		}
		 
		/*printf("else scan_clients\n");*/
	       scan_clients();
               sleep(20);
               x++;
	}
     
	i=0;
	while(i < MAX_CLIENT)
	{
                printf("closing : %d %d\n", i, list[i]);
		fflush(stdout);
                close(list[i]);
		i++;
	}
      

        }
	return 0;
}
Beispiel #23
0
void empty_list(caStack* stack)
{
    caValue* out = circa_output(stack, 0);
    int size = circa_int_input(stack, 1);
    caValue* initialValue = circa_input(stack, 0);
    set_list(out, size);
    for (int i=0; i < size; i++) {
        copy(initialValue, list_get(out, i));
    }
}
Beispiel #24
0
void list_initialize_parameter_from_type_decl(Block* typeDecl, caValue* parameter)
{
    set_list(parameter, 2);
    caValue* types = set_list(list_get(parameter, 0), 0);
    caValue* names = set_list(list_get(parameter, 1), 0);

    // Iterate through the type definition.
    for (int i=0; i < typeDecl->length(); i++) {
        Term* term = typeDecl->get(i);

        if (!is_function(term))
            continue;

        Type* type = function_get_output_type(term, 0);

        set_type(list_append(types), type);
        set_string(list_append(names), term->name);
    }
}
Beispiel #25
0
void append_internal_error(Value* result, int index, std::string const& message)
{
    const int INTERNAL_ERROR_TYPE = 1;

    Value* error = list_append(result);
    set_list(error, 3);
    set_int(list_get(error, 0), INTERNAL_ERROR_TYPE);
    set_int(list_get(error, 1), index);
    set_string(list_get(error, 2), message);
}
Beispiel #26
0
void Block__walk_terms(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    Value* out = vm->output();
    set_list(out, 0);
    for (BlockIterator it(block); it; ++it)
        set_term_ref(list_append(out), *it);
}
void Branch__terms(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    if (branch == NULL)
        return circa_output_error(stack, "NULL branch");

    caValue* out = circa_output(stack, 0);
    set_list(out, branch->length());

    for (int i=0; i < branch->length(); i++)
        set_term_ref(circa_index(out, i), branch->get(i));
}
void Branch__inputs(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    caValue* output = circa_output(stack, 0);
    set_list(output, 0);
    for (int i=0;; i++) {
        Term* term = get_input_placeholder(branch, i);
        if (term == NULL)
            break;
        set_term_ref(list_append(output), term);
    }
}
Beispiel #29
0
void Block__terms(VM* vm)
{
    Block* block = as_block(vm->input(0));
    if (block == NULL)
        return vm->throw_str("NULL block");

    Value* out = vm->output();
    set_list(out, block->length());

    for (int i=0; i < block->length(); i++)
        set_term_ref(circa_index(out, i), block->get(i));
}
Beispiel #30
0
void Block__outputs(VM* vm)
{
    Block* block = as_block(vm->input(0));
    Value* output = vm->output();
    set_list(output, 0);
    for (int i=0;; i++) {
        Term* term = get_output_placeholder(block, i);
        if (term == NULL)
            break;
        set_term_ref(list_append(output), term);
    }
}