void test_lazy()
{
#ifdef DEFERRED_CALLS_FIRST_DRAFT
    Branch branch;

    Term* a = branch.compile("a = add(1 2)");
    set_lazy_call(a, true);

    Stack context;
    push_frame(&context, &branch);
    run_interpreter(&context);

    test_equals(get_register(&context, a), ":Unevaluated");

    Frame* frame = push_frame(&context, &branch);
    frame->pc = a->index;
    frame->startPc = frame->pc;
    frame->endPc = frame->pc + 1;
    frame->strategy = ByDemand;
    run_interpreter(&context);

    test_equals(get_register(&context, a), "3");

    reset_stack(&context);
    Term* b = branch.compile("b = add(a a)");
    push_frame(&context, &branch);
    run_interpreter(&context);

    test_equals(get_register(&context, a), "3");
    test_equals(get_register(&context, b), "6");
#endif
}
Example #2
0
int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
{
	int r;
	struct del_stack *s;

	s = kmalloc(sizeof(*s), GFP_NOIO);
	if (!s)
		return -ENOMEM;
	s->tm = info->tm;
	s->top = -1;

	r = push_frame(s, root, 0);
	if (r)
		goto out;

	while (unprocessed_frames(s)) {
		uint32_t flags;
		struct frame *f;
		dm_block_t b;

		r = top_frame(s, &f);
		if (r)
			goto out;

		if (f->current_child >= f->nr_children) {
			pop_frame(s);
			continue;
		}

		flags = le32_to_cpu(f->n->header.flags);
		if (flags & INTERNAL_NODE) {
			b = value64(f->n, f->current_child);
			f->current_child++;
			r = push_frame(s, b, f->level);
			if (r)
				goto out;

		} else if (is_internal_level(info, f)) {
			b = value64(f->n, f->current_child);
			f->current_child++;
			r = push_frame(s, b, f->level + 1);
			if (r)
				goto out;

		} else {
			if (info->value_type.dec) {
				unsigned i;

				for (i = 0; i < f->nr_children; i++)
					info->value_type.dec(info->value_type.context,
							     value_ptr(f->n, i));
			}
			f->current_child = f->nr_children;
		}
	}

out:
	kfree(s);
	return r;
}
Example #3
0
PUBLIC void vm_raise(VMSTATE vms, OBJ exception, OBJ arg) {
  if (vms->r->vm_trap_closure != NULL) {
    VECTOR argvec = newvector_noinit(5);

    push_frame(vms);

#ifdef DEBUG
    printf("%p raising %s\n", current_thread, ((BVECTOR) AT((OVECTOR) exception, SY_NAME))->vec);
#endif

    ATPUT(argvec, 0, NULL);
    ATPUT(argvec, 1, exception);
    ATPUT(argvec, 2, arg);
    ATPUT(argvec, 3, (OBJ) getcont_from(vms));
    ATPUT(argvec, 4, vms->r->vm_acc);

    vms->c.vm_top = 0;
    apply_closure(vms, vms->r->vm_trap_closure, argvec);
    vms->r->vm_frame = NULL;	/* If it ever returns, the thread dies. */
  } else {
    if (OVECTORP(exception) && ((OVECTOR) exception)->type == T_SYMBOL)
      fprintf(stderr, "excp sym = '%s\n", ((BVECTOR) AT((OVECTOR) exception, SY_NAME))->vec);
    if (OVECTORP(arg) && ((OVECTOR) arg)->type == T_SYMBOL)
      fprintf(stderr, "arg sym = '%s\n", ((BVECTOR) AT((OVECTOR) arg, SY_NAME))->vec);
    if (BVECTORP(arg))
      fprintf(stderr, "arg str = %s\n", ((BVECTOR) arg)->vec);
    fprintf(stderr,
	    "Exception raised, no handler installed -> vm death.\n");
    vms->c.vm_state = VM_STATE_DYING;
  }
}
Example #4
0
void test_custom_object()
{
    g_currentlyAllocated = 0;
    g_totalAllocated = 0;

    Block block;
    block.compile(
        "type MyType; \n"
        "def create_object() -> MyType\n"
        "def check_object(MyType t)\n"
        "s = create_object()\n"
        "check_object(s)\n"
            );

    circa_install_function(&block, "create_object", create_object);
    circa_install_function(&block, "check_object", check_object);

    circa_setup_object_type(circa_find_type_local(&block, "MyType"),
            sizeof(CustomObject), CustomObjectRelease);

    // Shouldn't allocate any objects before running.
    test_equals(g_currentlyAllocated, 0);
    test_equals(g_totalAllocated, 0);

    Stack stack;
    push_frame(&stack, &block);
    run_interpreter(&stack);
    test_assert(&stack);
    circa_clear_stack(&stack);

    // Running the script should only cause 1 object allocation.
    test_equals(g_currentlyAllocated, 0);
    test_equals(g_totalAllocated, 1);
}
Example #5
0
void handle_release(caValue* value)
{
    HandleData* container = as_handle(value);
    ca_assert(container != NULL);

    container->refcount--;

    // Release data, if this is the last reference.
    if (container->refcount <= 0) {

        // Find the type's release function (if any), and call it.
        Term* releaseMethod = find_method(NULL, value->value_type, "release");
        if (releaseMethod != NULL) {
            Stack stack;
            push_frame(&stack, function_contents(releaseMethod));
            caValue* inputSlot = get_input(&stack, 0);

            // Don't copy this value, otherwise we'll get in trouble when the copy
            // needs to be released.
            swap(value, inputSlot);

            run_interpreter(&stack);

            swap(value, inputSlot);
        }

        free(container);
    }
}
Example #6
0
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
    AVFilterContext *ctx = inlink->dst;
    AVFilterLink *outlink = ctx->outputs[0];
    LoopContext *s = ctx->priv;
    int64_t duration;
    int ret = 0;

    if (inlink->frame_count_out >= s->start && s->size > 0 && s->loop != 0) {
        if (s->nb_frames < s->size) {
            if (!s->nb_frames)
                s->start_pts = frame->pts;
            s->frames[s->nb_frames] = av_frame_clone(frame);
            if (!s->frames[s->nb_frames]) {
                av_frame_free(&frame);
                return AVERROR(ENOMEM);
            }
            s->nb_frames++;
            if (frame->pkt_duration)
                duration = frame->pkt_duration;
            else
                duration = av_rescale_q(1, av_inv_q(outlink->frame_rate), outlink->time_base);
            s->duration = frame->pts + duration;
            ret = ff_filter_frame(outlink, frame);
        } else {
            av_frame_free(&frame);
            ret = push_frame(ctx);
        }
    } else {
        frame->pts += s->duration;
        ret = ff_filter_frame(outlink, frame);
    }

    return ret;
}
int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags)
{
    BufferSourceContext *s = ctx->priv;

    s->eof = 1;
    ff_avfilter_link_set_in_status(ctx->outputs[0], AVERROR_EOF, pts);
    return (flags & AV_BUFFERSRC_FLAG_PUSH) ? push_frame(ctx->graph) : 0;
}
Example #8
0
bool ast_translation::visit(ast * n) {
    ast * r;
    if (n->get_ref_count() > 1 && m_cache.find(n, r)) {
        m_result_stack.push_back(r);
        return true;
    }
    push_frame(n);
    return false;
}
Example #9
0
int run_repl()
{
    Stack context;
    Branch branch;
    bool displayRaw = false;

    push_frame(&context, &branch);

    while (true) {
        std::cout << "> ";

        std::string input;

        if (!std::getline(std::cin, input))
            break;

        if (input == "exit" || input == "/exit")
            break;

        if (input == "")
            continue;

        if (input == "/raw") {
            displayRaw = !displayRaw;
            if (displayRaw) std::cout << "Displaying raw output" << std::endl;
            else std::cout << "Not displaying raw output" << std::endl;
            continue;
        }
        if (input == "/clear") {
            clear_branch(&branch);
            std::cout << "Cleared working area" << std::endl;
            continue;
        }
        if (input == "/dump") {
            dump(&branch);
            continue;
        }

        if (input == "/help") {
            std::cout << "Special commands: /raw, /help, /clear, /dump, /exit" << std::endl;
            continue;
        }

        int previousHead = branch.length();
        repl_evaluate_line(&context, input, std::cout);

        if (displayRaw) {
            for (int i=previousHead; i < branch.length(); i++) {
                std::cout << get_term_to_string_extended(branch[i]) << std::endl;
                if (nested_contents(branch[i])->length() > 0)
                    print_branch(std::cout, nested_contents(branch[i]));
            }
        }
    }

    return 0;
}
Example #10
0
File: codegen.c Project: dckc/ponyc
void codegen_pushscope(compile_t* c)
{
  compile_frame_t* frame = push_frame(c);

  frame->fun = frame->prev->fun;
  frame->restore_builder = frame->prev->restore_builder;
  frame->break_target = frame->prev->break_target;
  frame->continue_target = frame->prev->continue_target;
  frame->invoke_target = frame->prev->invoke_target;
}
Example #11
0
void push_repl(void)
{
  struct repl_frame *frame = push_frame(repl_action, sizeof(struct repl_frame));

  frame->state = read_line;
#ifdef USE_READLINE
  frame->line = NULL;
  rl_bind_key('\t', rl_insert);
#endif
}
Example #12
0
File: codegen.c Project: dckc/ponyc
void codegen_pushtry(compile_t* c, LLVMBasicBlockRef invoke_target)
{
  compile_frame_t* frame = push_frame(c);

  frame->fun = frame->prev->fun;
  frame->restore_builder = frame->prev->restore_builder;
  frame->break_target = frame->prev->break_target;
  frame->continue_target = frame->prev->continue_target;
  frame->invoke_target = invoke_target;
}
Example #13
0
void evaluate_unbounded_loop(caStack* stack)
{
    Branch* contents = (Branch*) circa_caller_branch(stack);

    // Check for zero evaluations
    if (!as_bool(circa_input(stack, 0))) {
        return;
    }

    push_frame(stack, contents);
}
Example #14
0
PUBLIC INLINE void apply_closure(VMSTATE vms, OVECTOR closure, VECTOR argvec) {
  if (closure == NULL || TAGGEDP(closure)) {
    vm_raise(vms, (OBJ) newsym("invalid-callable"), (OBJ) closure);
  } else if (closure->type == T_PRIM) {
    int primargc;
    prim_fn fnp = lookup_prim(NUM(AT(closure, PR_NUMBER)), &primargc);

    if (fnp != NULL) {
      if ((primargc >= 0 && argvec->_.length-1 != primargc) ||
	  (primargc < 0 && argvec->_.length-1 < -primargc))
	vm_raise(vms, (OBJ) newsym("wrong-argc"), (OBJ) closure);
      else
	vms->r->vm_acc = fnp(vms, argvec);
    } else
      vm_raise(vms, (OBJ) newsym("invalid-primitive"), AT(closure, PR_NUMBER));
  } else if (closure->type == T_CLOSURE) {
    OVECTOR meth = (OVECTOR) AT(closure, CL_METHOD);

    if (!MS_CAN_X(meth, vms->r->vm_effuid)) {
      vm_raise(vms, (OBJ) newsym("no-permission"), AT(meth, ME_NAME));
      return;
    }

    if (argvec->_.length-1 != NUM(AT(meth, ME_ARGC))) {
      vm_raise(vms, (OBJ) newsym("wrong-argc"), (OBJ) meth);
      return;
    }

    push_frame(vms);

    vms->r->vm_env = argvec;
    ATPUT(vms->r->vm_env, 0, AT(meth, ME_ENV));

    vms->r->vm_lits = (VECTOR) AT(meth, ME_LITS);
    vms->r->vm_code = (BVECTOR) AT(meth, ME_CODE);
    vms->r->vm_self = (OBJECT) AT(closure, CL_SELF);
    vms->c.vm_ip = 0;
    vms->r->vm_method = meth;
    if (NUM(AT(meth, ME_FLAGS)) & O_SETUID)
      vms->r->vm_effuid = (OBJECT) AT(meth, ME_OWNER);
  } else if (closure->type == T_CONTINUATION) {
    int i;
    VECTOR cstk = (VECTOR) AT(closure, CONT_STACK);

    for (i = 0; i < cstk->_.length; i++)
      ATPUT(vms->r->vm_stack, i, AT(cstk, i));
    vms->c.vm_top = cstk->_.length;

    restoreframe(vms, (OVECTOR) AT(closure, CONT_FRAME));
    vms->r->vm_acc = AT(argvec, 1);
  } else {
    vm_raise(vms, (OBJ) newsym("invalid-callable"), (OBJ) closure);
  }
}
Example #15
0
static int request_frame(AVFilterLink *outlink)
{
    AVFilterContext *ctx = outlink->src;
    LoopContext *s = ctx->priv;
    int ret = 0;

    if ((!s->size) ||
            (s->nb_frames < s->size) ||
            (s->nb_frames >= s->size && s->loop == 0)) {
        ret = ff_request_frame(ctx->inputs[0]);
    } else {
        ret = push_frame(ctx);
    }

    if (ret == AVERROR_EOF && s->nb_frames > 0 && s->loop != 0) {
        ret = push_frame(ctx);
    }

    return ret;
}
Example #16
0
void codegen_pushtry(compile_t* c, LLVMBasicBlockRef invoke_target)
{
  compile_frame_t* frame = push_frame(c);

  frame->fun = frame->prev->fun;
  frame->break_target = frame->prev->break_target;
  frame->continue_target = frame->prev->continue_target;
  frame->invoke_target = invoke_target;
  frame->di_file = frame->prev->di_file;
  frame->di_scope = frame->prev->di_scope;
}
void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) {
  // Avoid stack bang as first instruction. It may get overwritten by patch_verified_entry.
  const Register return_pc = R20;
  mflr(return_pc);

  // Make sure there is enough stack space for this method's activation.
  assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
  generate_stack_overflow_check(bang_size_in_bytes);

  std(return_pc, _abi(lr), R1_SP);     // SP->lr = return_pc
  push_frame(frame_size_in_bytes, R0); // SP -= frame_size_in_bytes
}
void acq_image_thread_func(void * lpParam){
	int i = 0 ;
    	unsigned long t_start, t_stop ;
	unsigned long t_diff ;

	RASPIVID_CONFIG * config = (RASPIVID_CONFIG*)malloc(sizeof(RASPIVID_CONFIG));
        RASPIVID_PROPERTIES * properties = (RASPIVID_PROPERTIES*)malloc(sizeof(RASPIVID_PROPERTIES));
        config->width=640;
        config->height=480;
        config->bitrate=0;      // zero: leave as default
        config->framerate=30;
        config->monochrome=1;
	properties->hflip = 1 ;
        properties->vflip = 1 ;
        properties -> sharpness = 0 ;
        properties -> contrast = 0 ;
        properties -> brightness = 45 ;
        properties -> saturation = 0 ;
        properties -> exposure = SPORTS;
        properties -> shutter_speed = 0 ; // 0 is autoo
	printf("Init sensor \n");
        capture = (RaspiCamCvCapture *) raspiCamCvCreateCameraCapture3(0, config, properties, 1);
	free(config);
	printf("Wait stable sensor \n");
        for(i = 0 ; (i < 30) ; ){
                int success = 0 ;
                success = raspiCamCvGrab(capture);
                if(success){
                                IplImage* image = raspiCamCvRetrieve(capture);
                                i ++ ;
                }
        }
	i = 0 ;
	printf("Start Capture !\n");
	t_start = get_long_time();
	while(i < nb_frames && thread_alive){
                int success = 0 ;
                success = raspiCamCvGrab(capture);
                if(success){
                                IplImage* image = raspiCamCvRetrieve(capture);
				t_diff = get_long_time();
                                if(push_frame(image,t_diff, &my_frame_buffer) < 0) printf("lost frame %d ! \n", i);;
                                i ++ ;
				usleep(1000);
                }
        }
        t_stop = get_long_time();
        printf("Capture done \n");
        t_diff =  t_stop - t_start ;;
        printf("Capture took %lu ms\n", t_diff/1000L);
        //printf("Actual frame-rate was %f \n", nb_frames/t_diff);
        raspiCamCvReleaseCapture(&capture);
}
void check_prolog(pTHX_ pMY_CXT) {
    if (!c_prolog_ok) {
	if(!PL_is_initialised(NULL, NULL)) {
	    args2argv();
	    if(!PL_initialise(PL_argc, PL_argv)) {
		die ("unable to start prolog engine");
	    }
	    push_frame(aTHX_ aMY_CXT);
	    c_prolog_init=1;
	}
#ifdef MULTIPLICITY
	if(PL_thread_self()==-1) {
	    if(PL_thread_attach_engine(NULL)==-1) {
		die ("unable to create prolog thread engine");
	    }
	    push_frame(aTHX_ aMY_CXT);
	    c_prolog_init=1;
	}
#endif
	c_prolog_ok=1;
    }
}
Example #20
0
CC compile_and_run(block_t region,
		   struct global_state *gstate,
		   const char *nicename, u8 *noreload,
		   bool dontrun)
{
  struct compile_and_run_frame *frame;
  struct compile_context *ccontext;

  GCPRO1(gstate);
  frame = push_frame(compile_and_run_action, sizeof(struct compile_and_run_frame));
  ccontext = (struct compile_context *)allocate_record(type_vector, 2);

  frame->dontrun = dontrun;
  frame->ps.ccontext = ccontext;
  ccontext->gstate = gstate;
  /* no evaluation_state yet */
  GCPOP(1);

  frame->state = init;
  if (!region)
    region = new_block();
  frame->parser_block = region;
  /* Set filename */
  lexloc.filename = bstrdup(region, nicename);

  normal_lexing();
  if ((frame->f = parse(frame->parser_block)))
    {
      if (noreload)
	{
	  if (frame->f->name &&
	      module_status(frame->ps.ccontext->gstate, frame->f->name) != module_unloaded)
	    {
	      free_block(frame->parser_block);
	      *noreload = TRUE;
	      FA_POP(&fp, &sp);
	      return;
	    }
	  *noreload = FALSE;
	}

      if (mprepare(&frame->ps, frame->parser_block, frame->f))
	{
	  frame->state = preparing;
	  continue_prepare(frame);
	  return;
	}
    }
  runtime_error(error_compile_error);
}
        void operator()(expr * t) {
            SASSERT(m.is_bool(t));
            push_frame(t, true);
            SASSERT(!m_frame_stack.empty());
            while (!m_frame_stack.empty()) {
                frame & fr    = m_frame_stack.back();
                expr * t      = fr.m_t;
                bool form_ctx = fr.m_form_ctx;
                TRACE("cofactor", tout << "processing, form_ctx: " << form_ctx << "\n" << mk_bounded_pp(t, m) << "\n";);

                m_owner.checkpoint();
                
                if (m_processed.is_marked(t)) {
                    save_candidate(t, form_ctx);
                    m_frame_stack.pop_back();
                    continue;
                }

                if (m.is_term_ite(t)) {
                    m_has_term_ite.mark(t);
                    m_processed.mark(t);
                    m_frame_stack.pop_back();
                    continue;
                }
                
                if (fr.m_first) {
                    fr.m_first   = false;
                    bool visited = true;
                    if (is_app(t)) {
                        unsigned num_args = to_app(t)->get_num_args();
                        for (unsigned i = 0; i < num_args; i++)
                            visit(to_app(t)->get_arg(i), form_ctx, visited);
                    }
                    // ignoring quantifiers
                    if (!visited)
                        continue;
                }
                
                if (is_app(t)) {
                    unsigned num_args = to_app(t)->get_num_args();
                    unsigned i;
                    for (i = 0; i < num_args; i++) {
                        if (m_has_term_ite.is_marked(to_app(t)->get_arg(i)))
                            break;
                    }
                    if (i < num_args) {
                        m_has_term_ite.mark(t);
                        TRACE("cofactor", tout << "saving candidate: " << form_ctx << "\n" << mk_bounded_pp(t, m) << "\n";);
                        save_candidate(t, form_ctx);
                    }
Example #22
0
void codegen_pushloop(compile_t* c, LLVMBasicBlockRef continue_target,
  LLVMBasicBlockRef break_target, LLVMBasicBlockRef break_novalue_target)
{
  compile_frame_t* frame = push_frame(c);

  frame->fun = frame->prev->fun;
  frame->bare_function = frame->prev->bare_function;
  frame->break_target = break_target;
  frame->break_novalue_target = break_novalue_target;
  frame->continue_target = continue_target;
  frame->invoke_target = frame->prev->invoke_target;
  frame->di_file = frame->prev->di_file;
  frame->di_scope = frame->prev->di_scope;
}
Example #23
0
void type_name_visible_from_module()
{
    FakeFilesystem fs;
    fs.set("a", "type A { int i }");
    load_module_file(global_world(), "a", "a");

    fs.set("b", "require a\ntest_spy(make(A))");
    Block* b = load_module_file(global_world(), "b", "b");

    Stack stack;
    push_frame(&stack, b);
    test_spy_clear();
    run_interpreter(&stack);
    test_assert(&stack);

    test_equals(test_spy_get_results(), "[{i: 0}]");
}
Example #24
0
void codegen_pushscope(compile_t* c, ast_t* ast)
{
  compile_frame_t* frame = push_frame(c);

  frame->fun = frame->prev->fun;
  frame->break_target = frame->prev->break_target;
  frame->continue_target = frame->prev->continue_target;
  frame->invoke_target = frame->prev->invoke_target;
  frame->di_file = frame->prev->di_file;

  if(frame->prev->di_scope != NULL)
  {
    frame->di_scope = LLVMDIBuilderCreateLexicalBlock(c->di,
      frame->prev->di_scope, frame->di_file,
      (unsigned)ast_line(ast), (unsigned)ast_pos(ast));
  }
}
Example #25
0
static void mload(const char *fname)
{
  FILE *f;

  context.display_error = TRUE;
  context._mudout = context._muderr = mstdout;
  context.call_count = MAX_CALLS;

  if (!(f = fopen(fname, "r")))
    {
      fprintf(stderr, "couldn't find %s\n", fname);
      exit(2);
    }
  push_frame(mload_action, sizeof(struct generic_frame));
  read_from_file(f);
  compile_and_run(NULL, globals, fname, NULL, FALSE);
}
Example #26
0
void codegen_startfun(compile_t* c, LLVMValueRef fun, LLVMMetadataRef file,
  LLVMMetadataRef scope)
{
  compile_frame_t* frame = push_frame(c);

  frame->fun = fun;
  frame->is_function = true;
  frame->di_file = file;
  frame->di_scope = scope;

  if(LLVMCountBasicBlocks(fun) == 0)
  {
    LLVMBasicBlockRef block = codegen_block(c, "entry");
    LLVMPositionBuilderAtEnd(c->builder, block);
  }

  LLVMSetCurrentDebugLocation2(c->builder, 0, 0, NULL);
}
Example #27
0
Object call_function(Object func) {
    Object ret;
    if (IS_FUNC(func)) {
        resolve_method_self(func);
        /* call native */
        if (GET_FUNCTION(func)->native != NULL) {
            return GET_FUNCTION(func)->native();
        } else {
            TmFrame* f = push_frame(func);
            /*
            if (GET_FUNCTION(func)->modifier == 0) {
                return tm_eval(f);
            }*/
            L_recall:
            if (setjmp(f->buf)==0) {
                return tm_eval(f);
            } else {
                f = tm->frame;
                /* handle exception in this frame */
                if (f->jmp != NULL) {
                    f->pc = f->jmp;
                    f->jmp = NULL;
                    goto L_recall;
                /* there is no handler, throw to last frame */
                } else {
                    push_exception(f);
                    tm->frame--;
                    longjmp(tm->frame->buf, 1);
                }
            }
        }
    } else if (IS_DICT(func)) {
        ret = class_new(func);
        Object *_fnc = dict_get_by_str(ret, "__init__");
        if (_fnc != NULL) {
            call_function(*_fnc);
        }
        return ret;
    }
    tm_raise("File %o, line=%d: call_function:invalid object %o", GET_FUNCTION_FILE(tm->frame->fnc), 
        tm->frame->lineno, func);
    return NONE_OBJECT;
}
Example #28
0
File: codegen.c Project: dckc/ponyc
void codegen_startfun(compile_t* c, LLVMValueRef fun, bool has_source)
{
  compile_frame_t* frame = push_frame(c);

  frame->fun = fun;
  frame->restore_builder = LLVMGetInsertBlock(c->builder);
  frame->has_source = has_source;
  frame->is_function = true;
  c->dwarf.has_source = has_source;

  // Reset debug locations
  dwarf_location(&c->dwarf, NULL);

  if(LLVMCountBasicBlocks(fun) == 0)
  {
    LLVMBasicBlockRef block = codegen_block(c, "entry");
    LLVMPositionBuilderAtEnd(c->builder, block);
  }
}
void
power_sum(int n)
{
	int *a, i, j, k;

	// number of terms in the sum

	k = length(p1) - 1;

	// local frame

	push_frame(k * (n + 1));

	// array of powers

	p1 = cdr(p1);
	for (i = 0; i < k; i++) {
		for (j = 0; j <= n; j++) {
			push(car(p1));
			push_integer(j);
			power();
			A(i, j) = pop();
		}
		p1 = cdr(p1);
	}

	push_integer(n);
	factorial();
	p1 = pop();

	a = (int *) malloc(k * sizeof (int));

	if (a == NULL)
		stop("malloc failure");

	push(zero);

	multinomial_sum(k, n, a, 0, n);

	free(a);

	pop_frame(k * (n + 1));
}
Example #30
0
void test_cast_first_inputs()
{
    // Pass an input of [1] to a branch that expects a compound type.
    // The function will need to cast the [1] to T in order for it to work.

    Branch branch;
    branch.compile("type T { int i }");
    Term* f = branch.compile("def f(T t) -> int { return t.i }");

    Stack context;
    push_frame(&context, function_contents(f));

    caValue* in = circa_input((caStack*) &context, 0);
    circa_set_list(in, 1);
    circa_set_int(circa_index(in, 0), 5);

    run_interpreter(&context);

    test_assert(circa_int(circa_output((caStack*) &context, 0)) == 5);
}