예제 #1
0
파일: lambda.c 프로젝트: 74AC153/lam
int term_print(FILE *outstream, struct term *t)
{
    if(!t)
        return -1;
    switch(t->type) {
    case TYPE_VAR:
        if(0 <= fprintf(outstream, "%.*s", VAR_LEN, t->var))
            break;
        return -1;
    case TYPE_LAMBDA:
        if(0 <= fprintf(outstream, "\\%.*s", VAR_LEN, t->lambda.var))
            if(0 <= fprintf(outstream, "."))
                if(0 <= term_print(outstream, t->lambda.body))
                    break;
        return -1;
    case TYPE_APPL:
        if(0 <= fprintf(outstream, "("))
            if(0 <= term_print(outstream, t->appl.fun))
                if(0 <= fprintf(outstream, " "))
                    if(0 <= term_print(outstream, t->appl.arg))
                        if(0 <= fprintf(outstream, ")"))
                            break;
        return -1;
    }

    return 0;
}
예제 #2
0
파일: mm.c 프로젝트: gerow/redwood
int mm_init(multiboot_info_t *boot_info) {
  if (!(boot_info->flags & MULTIBOOT_INFO_MEMORY)) {
    term_print("Boot info memory entries invalid, bailing out\n");
    return -1;
  }
  term_printf("Upper memory %dk\n", boot_info->mem_upper);
  term_printf("Lower memory %dk\n", boot_info->mem_lower);

  if (!(boot_info->flags & MULTIBOOT_INFO_MEM_MAP)) {
    term_print("Boot info mem map invalid, bailing out\n");
    return -1;
  }
  multiboot_memory_map_t *mmap = (void *)boot_info->mmap_addr;
  term_print("Memory map:\n");
  while ((multiboot_uint32_t)mmap < boot_info->mmap_addr + boot_info->mmap_length) {
    const char *type =
      mmap->type == MULTIBOOT_MEMORY_AVAILABLE ? "Available" : "Reserved ";
    /* 
     * These are technically 64-bit values, so we need to convert them before passing 
     * them to printf
     */
    uint32_t start = mmap->addr;
    uint32_t len = mmap->len;
    term_printf("  %s [0x%lx - 0x%lx]\n", type, start, start + len);
    mmap = (void *)((uintptr_t)mmap + mmap->size + 4);
  }

  return 0;
}
예제 #3
0
파일: kern_main.c 프로젝트: gerow/redwood
void kern_main(multiboot_info_t *boot_info) {
  term_clear();
  term_color(TERM_GREEN, TERM_BLACK);
  term_print("Booting\n");
  term_print("Initializing memory manager\n");
  if (mm_init(boot_info)) {
    term_print("Failed to initialize memory manager\n");
    return;
  }

  com_init();
  com_print(COM1, "Hello COM1!\n");
  log_info("This is a logging test!");
  return;
}
예제 #4
0
파일: terminal.c 프로젝트: surki/hipl
/** Connect to server. */
void cmd_connect(char *x)
{
	/* Variables. */
	char *server, *nick;

	if (strlen(x) < 1)
	{
		term_print("* No server address specified\n");
		return;
	}
	
	server = x;
	nick = strpbrk(x, " ");
	if (nick)
	{
		while (strlen(nick) > 0 && nick[0] == ' ')
		{
			nick[0] = '\0';
			nick = &nick[1];
		}
		if (strlen(nick) > 0) set_nick(nick);
	}
	
	term_mode = TERM_MODE_CLIENT;
	term_set_server_addr(server);
	term_client_init();
}
예제 #5
0
파일: server.c 프로젝트: BlackBoxe/minuit
void *__server(void *ptr)
{
	t_context *C=ctx_get();
	char msg[30];

	if(!server_init)
	{
		socket_connect(C->server->socket,9901);
		server_init=1;
		sprintf(msg,"listening on port %d",C->server->socket->portno);
		term_print(C->term,msg);

		if(C->app->off_screen)
		{
			printf("listening on port %d\n",C->server->socket->portno);
		}
	}
	else
	{
		socket_listen(C->server->socket);
		if(C->app->off_screen)
		{
			printf("waiting for connection");
		}

	}
	return NULL;
}
예제 #6
0
파일: term.c 프로젝트: gerow/redwood
int term_printf(const char *format, ...) {
  /* This is a hack. Should probably be able to print directly to the term. */
  char buf[256];

  va_list ap;
  va_start(ap, format);
  int rv = vsnprintf(buf, sizeof(buf), format, ap);
  term_print(buf);
  va_end(ap);
  return rv;
}
예제 #7
0
파일: term.c 프로젝트: BlackBoxe/minuit
void term_log(char *fmt, ...)
{
	t_context *C = ctx_get();
	char msg[40];
	va_list ap;
	va_start(ap,fmt);
	vsprintf(msg,fmt,ap);
	va_end(ap);

	term_print(C->term,msg);
}
예제 #8
0
파일: plug_cls.c 프로젝트: BlackBoxe/minuit
void plug_warning(t_plug *dst_plug,t_plug *src_plug)
{

	t_context *C=ctx_get();
	char msg[40];
	char *src_plug_type=data_name_get(src_plug->data_type);
	char *dst_plug_type=data_name_get(dst_plug->data_type);

	sprintf(msg,"%d(%s)(%s)-(%s)(%s)",C->app->frame,src_plug->name,src_plug_type,dst_plug->name,dst_plug_type);

	term_print(C->term,msg);
}
예제 #9
0
파일: terminal.c 프로젝트: surki/hipl
/** Help-command. */
void cmd_help(char *x)
{
	term_print("\n"
	           "* HIP GUI terminal help:\n"
	           "*  help          - Prints this help.\n"
	           "*  exec          - Show application execute dialog.\n"
	           "*  server [nick] - Create new server. Close old server/client\n"
	           "                   automatically. Nick is optional.\n"
	           "*  connect server [nick]\n"
	           "*                - Connect to server. Close old server/client\n"
	           "                   automatically. Nick is optional.\n"
	           "\n");
}
예제 #10
0
파일: obj.c 프로젝트: BlackBoxe/minuit
void obj_add(const char *object_name,int tot_vert,int tot_face,int tot_quad,int tot_tri)
{
	//printf("adding object:%s\n",object_name);
	t_context *C=ctx_get();
	term_print(C->term,"+ obj");
	t_obj *obj=obj_new(object_name);

	obj->tot_vert=tot_vert;
	obj->tot_face=tot_face;
	obj->tot_quad=tot_quad;
	obj->tot_tri=tot_tri;

	if(tot_vert) obj->verts=(float *)malloc(sizeof(float)*obj->tot_vert*3);
	if(tot_tri) obj->tris=(int *)malloc(sizeof(int)*obj->tot_tri*3);
	if(tot_quad) obj->quads=(int *)malloc(sizeof(int)*obj->tot_quad*4);

	lst_add(OBJECTS,obj,"obj");
}
예제 #11
0
파일: terminal.c 프로젝트: surki/hipl
/**
	Execute command.
*/
void term_exec_command(char *cmd)
{
	/* Variables. */
	int i;
	int k;
	char b = 0;
	
	/* Check empty command. */
	if (strlen(cmd) < 1)
	{
		return;
	}
	
	/* Find space. */
	for (k = 0;
	     cmd[k] != '\0' && cmd[k] != ' ';
	     k++);

	cmd[k] = '\0';
	k++;
			
	/* Compare commands. */
	for (i = 0; cmds[i].func != 0; i++)
	{
		if (strcmp(cmd, cmds[i].cmd) == 0)
		{
			cmds[i].func(&cmd[k]);
			b = 1;
			break;
		}
	}
	
	/* If command not found. */
	if (!b)
	{
		term_print("* Invalid command.\n");
	}
	
	/* Return. */
	return;
}
예제 #12
0
void isr_handler(registers_t regs) {
  term_print("Recieved interrupt!\n");
}
예제 #13
0
void bios_boot_demo(void)
{
	VDP_clearPlan(VDP_PLAN_A, 0);
	VDP_clearPlan(VDP_PLAN_B, 0);

	VDP_setHInterrupt(0);
	term_print("  ___   ___  ___   ___     ___   ___       ___  ___     ___", 1);
	term_print(" |___  |__  |  _  |___|   |  _  |__  |\\ | |__  |___  | |___ ", 1);
	term_print("  ___| |___ |___| |   |   |___| |___ | \\| |___  ___| |  ___|", 1);
	term_print("", 20);
	term_print(" Entry Vector 0x202", 2);
	term_print(" CSHBIOS(C)2016 Computer Science House", 2);
	term_print(" MD-VA6 BOOT ROM Revision 3", 30);
	term_print("", 0);
	term_print(" CPU1 : Motorola 68000 7.6MHz", 2);
	term_print("   Speed : 7.61 MHz", 2);
	term_print("", 0);
	term_print(" CPU2 : Zilog Z80 3.8MHz", 2);
	term_print("   Speed : 3.80 MHz", 60);
	term_print("", 0);

	term_print(" Press DEL to run Setup", 0);
	term_print(" Press <F8> for BBS POPUP", 170);
	term_print("", 0);

	term_print(" SRAM Asynchronous 2 x 65256 (64k x 8), single channel, parallel", 16);
	term_print("  Checking SRAM...", 60);
	term_print(" 8K  OK", 7);
	term_print(" 16K OK", 7);
	term_print(" 24K OK", 7);
	term_print(" 32K OK", 7);
	term_print(" 40K OK", 7);
	term_print(" 48K OK", 7);
	term_print(" 56K OK", 7);
	term_print(" 64K OK", 60);
	term_print("", 0);

	term_print(" VDP : Sega 315-5313 (Yamaha YM7101)", 2);
	term_print("   Speed: 56MHz", 2);
	term_print("   VRAM: 64K Serial Out Parallel Load DRAM", 2);
	term_print("   CRAM: 64 x 9", 2);
	term_print("   TMSS Enabled", 1);
	term_print("", 60);
	term_print(" 0xC00000 : Data Port", 20);
	term_print(" 0xC00004 : Control Port", 20);
	term_print(" 0xC00008 : H/V counter", 20);
	term_print(" 0xC00011 : SN76489", 20);
	term_print(" 0xC0001C : Debug Register", 70);
	term_print("", 0);
	term_print(" Starting demo...", 120);
}
예제 #14
0
파일: server.c 프로젝트: BlackBoxe/minuit
void server_print(char *msg)
{
	t_context *C=ctx_get();
	t_term *term = C->term;
	term_print(term,msg);
}
예제 #15
0
파일: lam.c 프로젝트: 74AC153/lam
int main(int argc, char *argv[])
{
	if(argc == 1) {
		printf("usage: %s <cmds> ...\n", argv[0]);
		printf("<cmds> is one of:\n");
		printf("<expr> -- push <expr> onto stack\n");
		printf("<expr> <name> -alpha -- push alpha rename of <expr> using <name>\n");
		printf("<expr> -beta -- push beta reduce of <expr>\n");
		printf("<expr> -eta -- push eta convert of <expr>\n");
		printf("<body> <var> -lambda -- push lambda binding free <var> in <body>\n");
		printf("<fun> <arg> -apply -- push apply of <fun> and <arg>\n");
		printf("<expr1> <expr2> -alpheq -- push \\x.\\y.x (true) or \\x.\\y.y (false) if <expr1> and <expr2> are alpha equivalent\n");
		printf("-body -- move cursor into body of lambda\n");
		printf("-fun -- move cursor into func of apply\n");
		printf("-arg -- move cursor into arg of apply\n");
		printf("-up -- move cursor up one level\n");
		printf("-top -- move cursor to top level\n");
		printf("<expr1> <expr2> -swap -- swap <expr1> and <expr2>\n");
		printf("<expr> -dup -- duplicate <expr>\n");
		printf("<expr1> <expr2> -repl -- replace <expr1> with <expr2> and remove <expr2>\n");
		printf("-print -- print expression stack\n");
		return 0;
	}
	struct termnode *term_top = NULL;

	struct term *church_true, *church_false;
	{
		enum term_parse_res res;
		char *expr = "\\a.\\b.a";
		FILE *stream = fmemopen(expr, strlen(expr), "r");
		church_true = term_parse(stream, &res);
		fclose(stream);
		expr = "\\a.\\b.b";
		stream = fmemopen(expr, strlen(expr), "r");
		church_false = term_parse(stream, &res);
		fclose(stream);
	}
	
	for(int i = 1; i < argc; i++) {
		if(strcmp(argv[i], "-alpha") == 0) {
			if(! termstack_get(term_top, 1)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			struct term *var = termstack_get(term_top, 0);
			if(var->type != TYPE_VAR) {
				fprintf(stderr, "alpha requires second arg VAR, got ");
				term_print(stderr, var);
				fputc('\n', stderr);
				break;
			}
			struct term *expr = termstack_get(term_top, 1);
			struct term *renamed = alpha_rename(expr, var->var);
			if(renamed) {
				termstack_push(&term_top, renamed);
			} else {
				fprintf(stderr, "alpha rename failed\n");
				break;
			}
		} else if(strcmp(argv[i], "-beta") == 0) {
			if(! termstack_get(term_top, 0)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			struct term *term = termstack_get(term_top, 0);
			struct term *reduced = beta_reduce(term);
			if(reduced) {
				termstack_push(&term_top, reduced);
			} else {
				fprintf(stderr, "beta reduction failed\n");
				break;
			}
		} else if(strcmp(argv[i], "-eta") == 0) {
			if(! termstack_get(term_top, 0)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			struct term *converted = eta_convert(term_top->t);
			if(converted) {
				termstack_push(&term_top, converted);
			} else {
				fprintf(stderr, "eta conversion failed\n");
				break;
			}
		} else if(strcmp(argv[i], "-lambda") == 0) {
			if(! termstack_get(term_top, 1)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			struct term *var = termstack_get(term_top, 0);
			struct term *body = termstack_get(term_top, 1);

			if(var->type != TYPE_VAR) {
				fprintf(stderr, "lambda requires VAR, got ");
				term_print(stderr, var);
				fputc('\n', stderr);
				break;
			}
			struct term *lambda = make_lambda(var->var, body);
			if(lambda) {
				termstack_push(&term_top, lambda);
			} else {
				fprintf(stderr, "create lambda failed\n");
				break;
			}
		} else if(strcmp(argv[i], "-apply") == 0) {
			if(! termstack_get(term_top, 1)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			struct term *arg = termstack_get(term_top, 0);
			struct term *fun = termstack_get(term_top, 1);

			struct term *appl = make_appl(fun, arg);
			if(appl) {
				termstack_push(&term_top, appl);
			} else {
				fprintf(stderr, "create apply failed\n");
				break;
			}
		} else if(strcmp(argv[i], "-alpheq") == 0) {
			if(! termstack_get(term_top, 1)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			struct term *t1_term = termstack_get(term_top, 0);
			struct term *t2_term = termstack_get(term_top, 1);

			if(alpha_eq(t1_term, t2_term)) {
				termstack_push(&term_top, term_duplicate(church_true));
			} else {
				termstack_push(&term_top, term_duplicate(church_false));
			}
		} else if(strcmp(argv[i], "-print") == 0) {
			for(struct termnode *n = term_top; n; n = n->next) {
				term_print(stdout, termtrace_current(n->trace));
				fprintf(stdout, "\n");
			}
		} else if(strcmp(argv[i], "-body") == 0) {
			if(! termstack_get(term_top, 0)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			if(termtrace_current(term_top->trace)->type != TYPE_LAMBDA) {
				fprintf(stderr, "not a lambda\n");
				break;
			}
			termtrace_go_body(&term_top->trace);
		} else if(strcmp(argv[i], "-fun") == 0) {
			if(! termstack_get(term_top, 0)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			if(termtrace_current(term_top->trace)->type != TYPE_APPL) {
				fprintf(stderr, "not an apply\n");
				break;
			}
			termtrace_go_fun(&term_top->trace);
		} else if(strcmp(argv[i], "-arg") == 0) {
			if(! termstack_get(term_top, 0)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			if(termtrace_current(term_top->trace)->type != TYPE_APPL) {
				fprintf(stderr, "not an apply\n");
				break;
			}
			termtrace_go_arg(&term_top->trace);
		} else if(strcmp(argv[i], "-up") == 0) {
			if(term_top->trace->prev)
				termtrace_go_prev(&term_top->trace);
		} else if(strcmp(argv[i], "-top") == 0) {
			while(term_top->trace->prev)
				termtrace_go_prev(&term_top->trace);
		} else if(strcmp(argv[i], "-swap") == 0) {
			if(! termstack_get(term_top, 1)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			struct termnode *next = term_top->next;
			term_top->next = next->next;
			next->next = term_top;
			term_top = next;
		} else if(strcmp(argv[i], "-dup") == 0) {
			if(! termstack_get(term_top, 0)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			termstack_push(&term_top,
			               term_duplicate(termtrace_current(term_top->trace)));
		} else if(strcmp(argv[i], "-repl") == 0) {
			if(! termstack_get(term_top, 1)) {
				fprintf(stderr, "stack underflow\n");
				break;
			}
			struct term *newterm = term_duplicate(termtrace_current(term_top->trace));
			destroy_term(termstack_pop(&term_top));
			destroy_term(termtrace_replace(term_top->trace, newterm));
		} else {
			FILE *stream = fmemopen(argv[i], strlen(argv[i]), "r");
			if(! stream)
				continue;

			enum term_parse_res res;
			struct term *term = term_parse(stream, &res);
			fclose(stream);

			if(term == NULL) {
				long loc = ftell(stream);
				if(! feof(stream))
					loc--;
				printf("parse error: %s at char %lu\n", term_parse_str(res), loc+1);
				printf("%s\n", argv[i]);
				for(long i = 0; i < loc; i++)
					printf(" ");
				printf("^\n");
				break;
			}
			termstack_push(&term_top, term);
		}
	}

	struct term *t;
	while(NULL != (t = termstack_get(term_top, 0))) {
		destroy_term(termstack_pop(&term_top));
	}

	destroy_term(church_true);
	destroy_term(church_false);
	return 0;
}