Beispiel #1
0
int main(void)
{
   ast_t * a;
   int jval;
   jit_t * jit;
   
   GC_INIT();
   GREG g;
 
   ast_init();
   sym_tab_init();
   types_init();
   scope_init();
   loc_tab_init();
   intrinsics_init();
   jit = llvm_init();
   ZZ_init(jit);
   
   yyinit(&g);

   printf("Welcome to Bacon v0.1\n\n");
   printf("> ");

   while (1)
   {
      if (!(jval = setjmp(exc)))
      {
         if (!yyparse(&g))
         {
            printf("Error parsing\n");
            abort();
         } else if (root)
         {
#if DEBUG1
            printf("\n");
            ast_print(root, 0);
#endif
            inference(root);
#if DEBUG2
            printf("\n");
            /*ast2_print(root, 0);*/
#endif
            exec_root(jit, root);
            root = NULL;
         }
      } else if (jval == 1)
         root = NULL;
      else /* jval == 2 */
         break;
      
      printf("\n> ");
   }

   llvm_cleanup(jit);
   yydeinit(&g);
    
   printf("\n");

   return 0;
}
Beispiel #2
0
int main(void) {
    GC_INIT();
    GREG g;
 
    int jval, jval2;
    char c;

    sym_tab_init();
    ast_init();
    type_init();
    scope_init();
    rel_assign_init();

    jit_t * jit = llvm_init();

    yyinit(&g);

    printf("Welcome to Cesium v 0.2\n");
    printf("To exit press CTRL-D\n\n");

    printf("> ");

    while (1)
    {
       if (!(jval = setjmp(exc)))
       {
          if (!yyparse(&g))
          {
             printf("Error parsing\n");
             abort();
          } else if (root != NULL)
          {
             rel_stack_init();
             rel_assign_mark();
             scope_mark();
             annotate_ast(root);
             if (TRACE) 
                ast_print(root, 0);
             unify(rel_stack, rel_assign);
             if (TRACE)
                print_assigns(rel_assign);
             exec_root(jit, root);
             if (root->tag != AST_FNDEC)
                 rel_assign_rewind();
           }
        } else if (jval == 1)
              root = NULL;
        else if (jval == 2)
              break;
        printf("\n> ");
    }
  
    yydeinit(&g);
    llvm_cleanup(jit);

    return 0;
}
Beispiel #3
0
/******************************************************************************
 * non-static function definitions
 ******************************************************************************/
int main(int argc, char **argv)
{
	int retval;
	struct handles handles = {
			.sock = -1,
			.sock2 = -1,
			.server_sock = -1,
			.file = NULL,
			.file2 = NULL,
	};
	struct scope_parameter param;

	if(0 != handle_options(argc,argv, &g_options))
	{
		usage(argv[0]);
		return 1;
	}

	signal_init();

	if (scope_init(&param, &g_options)) {
		retval = 2;
		goto cleanup;
	}

	if (g_options.mode == client || g_options.mode == server) {
		if (connection_init(&g_options, &handles)) {
			retval = 3;
			goto cleanup_scope;
		}
	} else if (g_options.mode == file) {
		if (file_open(&g_options, &handles)) {
			retval = 4;
			goto cleanup_scope;
		}
	}

	retval = 0;
	while (!transfer_interrupted()) {
		if (g_options.mode == client || g_options.mode == server) {
			if (connection_start(&g_options, &handles) < 0) {
				fprintf(stderr, "%s: problem opening connection.\n", __func__);
				continue;
			}
		}

		retval = transfer_data(&param, &g_options, &handles);
		if (retval && !transfer_interrupted())
			fprintf(stderr, "%s: problem transferring data.\n", __func__);

		if (g_options.mode == client || g_options.mode == server)
			connection_stop(&handles);

		if (g_options.mode == file)
			break;
	}

	connection_cleanup(&handles);
	file_close(&handles);

cleanup_scope:
	scope_cleanup(&param, &g_options);
cleanup:
	signal_exit();

	return retval;
}
Beispiel #4
0
int test_scope(float **data, int data_l, float* output)
{	
	// setpoint buffer reader
	struct sig_buf_read_param_f pid_setpoint_p = {
		.buffer = data[0],
		.size = data_l,
		.delta = 0,
		.circular = 0,
		.check_buffer = 1,
		.n_last = 0
	};
	struct signal_float pid_setpoint = SIGN_FN("setpoint", sig_buf_read_f, &pid_setpoint_p);
	
	// setpoint buffer reader
	struct sig_buf_read_param_f pid_feedback_p = {
		.buffer = data[1],
		.size = data_l,
		.delta = 0,
		.circular = 0,
		.check_buffer = 1,
		.n_last = 0
	};
	struct signal_float pid_feedback = SIGN_FN("pid_feedback", sig_buf_read_f, &pid_feedback_p);
	
	// setpoint buffer reader
	struct sig_buf_read_param_f pid_ff0_p = {
		.buffer = data[2],
		.size = data_l,
		.delta = 0,
		.circular = 0,
		.check_buffer = 1,
		.n_last = 0
	};
	struct signal_float pid_ff0 = SIGN_FN("ff0", sig_buf_read_f, &pid_ff0_p);
	
	// setpoint buffer reader
	struct sig_buf_read_param_f pid_ff1_p = {
		.buffer = data[3],
		.size = data_l,
		.delta = 0,
		.circular = 0,
		.check_buffer = 1,
		.n_last = 0
	};
	struct signal_float pid_ff1 = SIGN_FN("ff1", sig_buf_read_f, &pid_ff1_p);
	
	// setpoint buffer reader
	struct sig_buf_read_param_f pid_ff2_p = {
		.buffer = data[4],
		.size = data_l,
		.delta = 0,
		.circular = 0,
		.check_buffer = 1,
		.n_last = 0
	};
	struct signal_float pid_ff2 = SIGN_FN("ff2", sig_buf_read_f, &pid_ff2_p);
	
	
	// PID controller
	struct sig_pid_param_f pid_p= {
		.p = 1.0,
		.i = 0.1,
		.d = 1.0,
		.k = {0.0, 0.0, 0.0},
		.max_output = 5.0,
		.integral = 0.0,
		.history = {0.0, 0.0, 0.0},
		.setpoint = &pid_setpoint,
		.feedback = &pid_feedback,
		.ff = {1.0, 2.0, 3.0},
		.sh = {0.0, 0.0},
		.ff0 = &pid_ff0,
		.ff1 = &pid_ff1,
		.ff2 = &pid_ff2
	};
	struct signal_float pid = SIGN_FN("pid_out", sig_pid_opt_f, &pid_p);

	sig_pid_compute_k_f(&pid);

	scope_init(&scope, scope_data, sizeof(scope_data));
	scope_enlist_sig_float(&scope, &pid);
	scope_enlist_sig_float(&scope, &pid_ff2);
	scope_enlist_sig_float(&scope, &pid_feedback);
	scope_setup(&scope, signals, 1);
	
	n_t n;
	for(n=0; n<data_l; n++)
	{
		output[n] = sig_get_value_f(&pid, n);
		scope_update(&scope, n);
	}

	printf("scope got %d samples\n", scope.samples);
	printf("scope state is %d (is SAMPLED:%d)\n", scope.state, (scope.state == SCOPE_SAMPLED ? 1 : 0));
	printf("scope signals count: %d\n", scope.signals_count_float);
	
	int i;
	for(i=0; i< scope.signals_count_float; i++)
		printf("%s%c", scope.signals_float[i]->name, (i == (scope.signals_count_float - 1) ? '\n': ','));

	for(i=0; i<(scope.samples * scope.signals_count_float); i++)
		printf("%f%c", ((float*)scope.buffer)[i], ( (i+1) % scope.signals_count_float ? ',' : '\n'));
	
	return 0;
}