Пример #1
0
void lisp_write(struct lisp_object objOut){


 switch(objOut.objectType){
        case T_string :
            printf("%s\n", objOut.stringD);
            break;
        case T_num :
            printf("%lf\n", objOut.numD);
            break;
        case T_bool :
            printf("%d\n", objOut.boolD);
            break;
        case T_char :
            printf("%c\n", objOut.charD);
            break;
        case T_procedure :
            printf("%s\n", (*objOut.proc).opName );
            break;
        case T_pair :
            lisp_write(car(objOut));
            lisp_write(cdr(objOut));
            break;
       }
}
Пример #2
0
Cell* platform_eval(Cell* expr) {
  char* buf=malloc(BUFSZ);
  int i = 0;
  Cell* res = (Cell*)alloc_nil();
  Cell* c;
  int tag;
  
  if (!expr || expr->tag!=TAG_CONS) {
    printf("[platform_eval] error: no expr given.\r\n");
    return NULL;
  }

  while (expr && (c = car(expr))) {
    tag = compile_for_platform(c, &res); 
  
    if (tag) {
      /*printf("~~ expr %d res: %p\r\n",i,res);
      lisp_write(res, buf, 512);
      printf("~> %s\r\n",buf);*/
    } else {
      lisp_write(c, buf, BUFSZ);
      printf("[platform_eval] stopped at expression %d: %s\r\n",i,buf);
      break;
    }
    // TOOD: when to free the code blocks? -> when no bound lambdas involved
    
    i++;
    expr = cdr(expr);
  }
  free(buf);
  
  return res;
}
Пример #3
0
int main()
{
    int i = 0;
    /*
    //initialise opArray with opNames and opPointers
    int i = 0;
    //initialise + operator
    ++i;
    opArray = realloc(opArray, i * sizeof(struct lisp_object));
    opArray[i-1].objectType = T_procedure;
    opArray[i-1].proc.opName = malloc(sizeof("+"));
    strcpy(opArray[i-1].opName, "+");
    opArray[i-1].opPointer = &add;
    //initalise - operator
    ++i;
    opArray = realloc(opArray, i * sizeof(struct op));
    opArray[i-1].opName = malloc(sizeof("-"));
    strcpy(opArray[i-1].opName, "-");
    opArray[i-1].opPointer = &subtract;
    //initalise * operator
    ++i;
    opArray = realloc(opArray, i * sizeof(struct op));
    opArray[i-1].opName = malloc(sizeof("*"));
    strcpy(opArray[i-1].opName, "*");
    opArray[i-1].opPointer = &multiply;
        //initalise - operator
    ++i;
    opArray = realloc(opArray, i * sizeof(struct op));
    opArray[i-1].opName = malloc(sizeof("/"));
    strcpy(opArray[i-1].opName, "/");
    opArray[i-1].opPointer = ÷
    */
    //printf("++Because this is currently all operations have to be done inside a list++\n");
    printf("++++++++++++++++++++Various other things are also a bit shit+++++++++++++++++++\n\n");
    do
    {
        printf(">");
        //struct lisp_object m = lisp_eval(lisp_read());
        lisp_write((lisp_eval(lisp_read())));
    }
    while(1);
}
Пример #4
0
int main(int argc, char *argv[])
{
  Cell* expr = NULL;
  char* in_line = malloc(BUFSZ);
  char* in_buffer = malloc(64*BUFSZ);
  char* out_buf = malloc(BUFSZ);
  char* res;
  int in_offset = 0;
  int parens = 0;
  size_t len = 0;
  int i;
  int in_fd = 0;
  FILE* in_f;

  init_compiler();
  filesystems_init();

#ifdef DEV_SDL2
  void dev_sdl2_init();
  dev_sdl2_init();
#endif

#ifdef DEV_SDL
  void dev_sdl_init();
  dev_sdl_init();
#endif

#ifdef DEV_LINUXFB
  void mount_linux_fbfs();
  mount_linux_fbfs();
#endif

#ifdef DEV_POSIXFS
  void mount_posixfs();
  mount_posixfs();
#endif

#ifdef DEV_BIOS
  void mount_bios();
  mount_bios();
#endif
  
#ifdef DEV_CONSOLEKEYS
  void mount_consolekeys();
  mount_consolekeys();
#endif
  
#ifdef __AMIGA
  mount_amiga();
#endif
  
  if (argc==2) {
    in_fd = open(argv[1],O_RDONLY);
    in_f = fdopen(in_fd,"r");
    if (!in_f) in_f = stdin;
  } else {
    in_f = stdin;
  }

  while (1) {
    if (in_f == stdin) printf("sledge> ");
    expr = NULL;
    len = 0;

    res = fgets(in_line, BUFSZ, in_f);
    if (res) {
      len = strlen(in_line);
    }

    //printf("line: (%d) |%s|\r\n",len,in_line);
    
    if (len>0) {
      // recognize parens
      for (i=0; i<len; i++) {
        if (in_line[i] == ';') break;
        if (in_line[i] == '(') {
          parens++;
        } else if (in_line[i] == ')') {
          parens--;
        }
      }

      strncpy(in_buffer+in_offset, in_line, i);
      in_buffer[in_offset+i]='\n';
      in_buffer[in_offset+i+1]=0;
    
      if (parens>0) {
        if (in_f == stdin) printf("...\r\n");
        in_offset+=i;
      } else {
        in_offset=0;
        if (len>1) {
          expr = (Cell*)read_string(in_buffer);
        } else {
          //printf("\r\n");
        }
      }
    }

    if (feof(in_f) || len==0) {
      if (in_f!=stdin) close(in_fd);
      in_f = stdin;
      in_fd = 0;
      in_offset=0;
      if (feof(stdin)) {
        exit(0);
      }
    }
    
    if (expr) {      
      Cell* res;
      int success = compile_for_platform(expr, &res);
      
      if (success) {
        if (in_f == stdin) {
          if (!res) {
            printf("invalid cell (%p)\r\n",res);
          } else {
            lisp_write(res, out_buf, 1024);
            printf("%s\r\n",out_buf);
          }
        }
      } else {
        printf("<compilation failed>\n");
        res = NULL;
      }
    }
  }
  return 0;
}
Пример #5
0
void uart_repl() {
  uart_puts("~~ trying to malloc repl buffers\r\n");
  char* out_buf = malloc(1024*10);
  char* in_line = malloc(1024*2);
  char* in_buf = malloc(1024*10);
  uart_puts("\r\n\r\n++ welcome to EvaEvangelion arm/32 (c)2019 mntmn.\r\n");

  init_compiler();

  uart_puts("\r\n~~ compiler initialized.\r\n");

  memset(out_buf,0,1024*10);
  memset(in_line,0,1024*2);
  memset(in_buf,0,1024*10);

  long count = 0;
  int fullscreen = 0;

  int in_offset = 0;
  int parens = 0;

  int linec = 0;

  Cell* expr;
  char c = 0; //13;

  //strcpy(in_line,"(eval (load \"/sd/boot.l\"))\n");

  while (1) {
    expr = NULL;

    uart_puts("evangelion> ");

    int i = 0;

    while (c!=13) {
      c = uart_getc();
      uart_putc(c);
      in_line[i++] = c;
      in_line[i] = 0;
    }
    c = 0;

    int len = strlen(in_line);

    // recognize parens

    for (i=0; i<len; i++) {
      if (in_line[i] == '(') {
        parens++;
      } else if (in_line[i] == ')') {
        parens--;
      }
    }

    //printf("parens: %d in_offset: %d\n",parens,in_offset);

    if (len>1) {
      strncpy(in_buf+in_offset, in_line, len-1);
      in_buf[in_offset+len-1] = 0;

      //printf("line: '%s' (%d)\n",in_buf,strlen(in_buf));

      linec++;
      //if (linec>10) while (1) {};
    }
    printf("\r\n[%s]\r\n",in_buf);

    if (parens>0) {
      printf("\r\n...\r\n");
      in_offset+=len-1;
    } else {
      if (len>1) {
        expr = read_string(in_buf);
        in_offset=0;
      }
    }
    //printf("parens: %d offset: %d\n",parens,in_offset);

    //funcptr     compiled;

    if (expr) {

      //jit_prolog();

      int success = 0; //compile_arg(JIT_R0, expr, TAG_ANY);

      if (success) {
        funcptr compiled = NULL; //jit_emit();

        //jit_disassemble();

        //start_clock();

        /*uint32_t compiled[] = {
          0xe3a03005,  // mov     r3, #5
          0xe1a00003,  // mov     r0, r3
          0xe12fff1e   // bx      lr
          };*/

        printf("-- compiled: %p\r\n",compiled);
        memdump(compiled,200,1);

        printf("-- jumping to code…");
        //Cell* res = expr;
        Cell* res = (Cell*)((funcptr)compiled)();
        printf("-- res at: %p\r\n",res);

        // TODO: move to write op
        if (!res || res<(Cell*)heap_end) {
          uart_puts("null\n");
        } else {
          lisp_write(res, out_buf, 1024*10);
          uart_puts(out_buf);
        }
      }

      uart_puts("\r\n");
    }
  }
}