Exemple #1
0
Object module_repl_init() {
    if (repl_module != NULL)
        return repl_module;
    ClassData c = alloc_class("Module<repl>", 12);
    add_Method(c, "asString", &Object_asString);
    add_Method(c, "registerVisitor", &repl_registerVisitor);
    add_Method(c, "createobject", &repl_createobject);
    add_Method(c, "addmethod", &repl_addmethod);
    Object o = alloc_newobj(0, c);
    repl_module = o;
    gc_root(repl_module);
    if (module_ast == NULL)
        module_ast = module_ast_init();
    if (module_interactive == NULL)
        module_interactive = module_interactive_init();
    return o;
}
Exemple #2
0
Object alloc_CudaFloatArray(int n) {
    if (!CudaFloatArray) {
        CudaFloatArray = alloc_class("CudaFloatArray", 4);
        add_Method(CudaFloatArray, "at", &cuda_FloatArray_at);
        add_Method(CudaFloatArray, "at()put", &cuda_FloatArray_at_put);
        add_Method(CudaFloatArray, "[]", &cuda_FloatArray_at);
        add_Method(CudaFloatArray, "[]:=", &cuda_FloatArray_at_put);
    }
    Object o = alloc_obj(sizeof(struct CudaFloatArray) - sizeof(struct Object)
            + sizeof(float) * n,
            CudaFloatArray);
    struct CudaFloatArray *a = (struct CudaFloatArray *)o;
    a->size = n;
    for (int i = 0; i < n; i++) {
        a->data[i] = 0.0f;
    }
    return o;
}
Exemple #3
0
Method * read_Method_line(char * line,FILE * ifp)
{
  Method * out;
  char buffer[MAXLINE];
  char * temp;
  MethodArg * m;

  if( strstartcmp(line,"method") != 0 ) {
    warn("Attempting to read a method with no method line!");
    return NULL;
  }
  
  out = Method_alloc_std();
  out->logical = second_word_alloc(line,spacestr);

  while( fgets(buffer,MAXLINE,ifp) != NULL ) {
    chop_newline(buffer);
    if( strstartcmp(buffer,"end") == 0 ) 
      break;
    else if( strstartcmp(buffer,"map") == 0 ) {
      temp = second_word_alloc(buffer,spacestr);
      if( out->real != NULL ) { 
	warn("For method [%s], second map replacing [%s] with [%s]",out->logical,out->real,temp);
	ckfree(out->real);
      } 
      out->real = temp;
    } else if ( strstartcmp(buffer,"arg") == 0 ) {
      m = MethodArg_from_line(buffer);
      if( m == NULL ) {
	warn("Got a NULL method arg. Yikes!");
      } else {
	add_Method(out,m);
      }
    } else if ( strstartcmp(buffer,"return") == 0 ) {
      out->retstr = second_word_alloc(buffer,spacestr);
    } else {
      warn("In method [%s] did not understand %s",out->logical,buffer);
    }
  }

  return out;
}
Exemple #4
0
Object module_cuda_init() {
    if (cuda_module != NULL)
        return cuda_module;
    CudaError = alloc_Exception("CudaError", ErrorObject);
    gc_root(CudaError);
    ClassData c = alloc_class("Module<cuda>", 13);
    add_Method(c, "over()map", &cuda_over_map);
    add_Method(c, "floatArray", &cuda_floatArray);
    add_Method(c, "deviceName", &cuda_deviceName);
    add_Method(c, "computeCapability", &cuda_computeCapability);
    add_Method(c, "cores", &cuda_cores);
    add_Method(c, "using()do()blockWidth()blockHeight()gridWidth()gridHeight",
        &cuda_using_do_blockWidth_blockHeight_gridWidth_gridHeight);
    add_Method(c, "using()do", &cuda_using_do);
    add_Method(c, "using()times()do", &cuda_using_times_do);
    add_Method(c, "do", &cuda_do_infer);
    add_Method(c, "do()blockWidth()blockHeight()gridWidth()gridHeight",
            &cuda_do_dimensions_infer);
    add_Method(c, "bindir", &cuda_bindir);
    add_Method(c, "includedir", &cuda_includedir);
    Object o = alloc_newobj(0, c);
    cuda_module = o;
    gc_root(o);
    return o;
}
Exemple #5
0
// Create and return a grace object which contains the above functions
Object module_math_init() {

    if (math_module != NULL)
        return math_module;

    srand(time(NULL));

    ClassData c = alloc_class("Module<math>", 13);
    
    add_Method(c, "asString", &math_asString);
    add_Method(c, "asDebugString", &math_asDebugString);
    add_Method(c, "sin", &math_sin);
    add_Method(c, "cos", &math_cos);
    add_Method(c, "tan", &math_tan);
    add_Method(c, "asin", &math_asin);
    add_Method(c, "acos", &math_acos);
    add_Method(c, "atan", &math_atan);
    add_Method(c, "random", &math_random);
    add_Method(c, "pi", &math_pi);
    add_Method(c, "π", &math_pi);
    add_Method(c, "sqrt", &math_sqrt);
    add_Method(c, "abs", &math_abs);

    Object o = alloc_newobj(0, c);
    math_module = o;
    gc_root(math_module);

    return o;
}