Esempio n. 1
0
FunctionClosures FunctionClosures_new(ParserEnv* e)
{
    FunctionClosures ret = (FunctionClosures)SMalloc(sizeof(function_closures));
    ret->cmd_cnt = 0;
    ret->cmds = array_new(CommandClosures, 20, NULL);
    ret->func_arg_op_cmds_type_a_1 = array_new(CommandClosures, 20, NULL);
    ret->func_arg_op_cmds_type_b_1 = array_new(CommandClosures, 20, NULL);
    ret->func_arg_op_cmds_type_c_1 = array_new(CommandClosures, 20, NULL);
    ret->func_arg_op_cmds_type_a_2 = array_new(CommandClosures, 20, NULL);
    ret->func_arg_op_cmds_type_b_2 = array_new(CommandClosures, 20, NULL);
    ret->func_arg_op_cmds_type_c_2 = array_new(CommandClosures, 20, NULL);

    ret->branch_stack = FixedStack_new(sizeof(BranchBlock));
    ret->for_loop_stack = FixedStack_new(sizeof(for_loop_block));

    ret->vari_stack_size = _alloc_cons_value(e, IntValue);
    ret->vari_str_stack_size = _alloc_cons_value(e, IntValue);
    ret->vari_tree = Tree_new(String, Vptr, Ealloc, Efree);

    ///ret->input_param_tree = Tree_new(String, Vptr, Ealloc, Efree);
    ///ret->output_param_tree = Tree_new(String, Vptr, Ealloc, Efree);

    ret->input_param_array = array_new(SymbolValue*, 10, NULL);
    ret->output_param_array = array_new(SymbolValue*, 5, NULL);

    ret->status = DeclareInputParamsStatus;
    return ret;
}
Esempio n. 2
0
StructPrototype StructPrototype_new()
{
    StructPrototype ret = (StructPrototype)SMalloc(sizeof(struct_prototype));
    ret->symbol_to_elem_tree = Tree_new(String, Vptr, Ealloc, Efree);
    ret->size = 0;
    return ret;
}
Esempio n. 3
0
void InputSystem::Init(vptr platform_param)
{
#if defined(_WIN32) || defined(_WIN64)
    input_Init((HWND)platform_param);
#elif defined(__APPLE__)
    input_Init();
#endif
    m_input_listen_tree = Tree_new(Vptr, Vptr, Ealloc, Efree);
}
Esempio n. 4
0
RendererBase::RendererBase ( RendererBase *prev_renderer, bool inherit_material_table, RenderableSorter* sorter )
{
	if (sorter)
		renderable_sorter = sorter;
	else
		renderable_sorter = ENEW DefaultRenderableSorter;

	default_rend_matrix = Matrix4x4_new();
	Matrix4x4_set_one(default_rend_matrix);
    render_plane = RenderablePlane_new();
    VertexDecl pdec = RenderablePlane_get_vertex_declaration ( render_plane );

    display_pass = NULL;
    clear_sketchbook_pass = NULL;

    camera_base = prev_renderer->camera_base;
    x = prev_renderer->x;
    y = prev_renderer->y;
    width = prev_renderer->width;
    height = prev_renderer->height;

    curt_render_cam = camera_base;

    ///used_renderable_tree = Tree_new ( Vptr, Vptr, Ealloc, Efree );
    ///unused_renderable_tree = Tree_new ( Vptr, Vptr, Ealloc, Efree );

    if ( !inherit_material_table ) {
        material_table = Tree_new ( String, Vptr, (MALLOC)Ealloc, (MFREE)Efree );
        var key, data;
        key.str_var = "default_material";
        MaterialPrototype mp;
        {
            SdrNdGen sng = ISdrNdGen.New();
            ISdrNdGen.register_default_nodes ( sng );

            SDisplayProc s;
            s.proc = default_material_proc3;
            mp = MaterialPrototype_new ( pdec, 2,
                                         s,
                                         Shaded, false );
            ISdrNdGen.Delete ( sng );
        }
        data.vptr_var = mp;
        Tree_insert ( material_table, key, data );
        material_count = 3;
        own_material_table = true;
    }

    else {
        material_table = prev_renderer->material_table;
        material_count = prev_renderer->material_count;
        own_material_table = false;
    }

    own_camera = false;
}
Esempio n. 5
0
RendererBase::RendererBase ( ViewportPtr view, RenderableSorter* sorter )
{
	if (sorter)
		renderable_sorter = sorter;
	else
		renderable_sorter = ENEW DefaultRenderableSorter;

	default_rend_matrix = Matrix4x4_new();
	Matrix4x4_set_one(default_rend_matrix);
    render_plane = RenderablePlane_new();
    VertexDecl pdec = RenderablePlane_get_vertex_declaration ( render_plane );

    display_pass = NULL;
    clear_sketchbook_pass = create_clear_sketchbook_pass ( pdec );

    camera_base = Camera_new ( view->width, view->height );
    x = view->x;
    y = view->y;
    width = view->width;
    height = view->height;
    Camera_translate ( camera_base, 0.0, 0.0, 1.5f );

    curt_render_cam = camera_base;

    ///used_renderable_tree = Tree_new ( Vptr, Vptr, Ealloc, Efree );
    ///unused_renderable_tree = Tree_new ( Vptr, Vptr, Ealloc, Efree );

    material_table = Tree_new ( String, Vptr, (MALLOC)Ealloc, (MFREE)Efree );
    var key, data;
    key.str_var = "default_material";
    MaterialPrototype mp;
    {
        SdrNdGen sng = ISdrNdGen.New();
        ISdrNdGen.register_default_nodes ( sng );

        SDisplayProc s;
        s.proc = default_material_proc3;
        mp = MaterialPrototype_new ( pdec, 2,
                                     s,
                                     Shaded, false );
        ISdrNdGen.Delete ( sng );
    }
    data.vptr_var = mp;
    Tree_insert ( material_table, key, data );
    material_count = 3;

    own_camera = true;
    own_material_table = true;
}
Esempio n. 6
0
Tree
Tree_insert (Tree t, FMComparison cmp, cast key, cast value)
{
  int discrim;
  if (t==NULL) return Tree_new(key,value);
  discrim = cmp(key,t->key);
  if (discrim==0) {
    t->value = value;	/* overwrite old value */
    return t;
  } else if (discrim<0) {
    return mkBalTree (t, Tree_insert (t->left, cmp, key, value), t->right);
  } else {
    return mkBalTree (t, t->left, Tree_insert (t->right, cmp, key, value));
  }
}
Esempio n. 7
0
/*
   -----------------------
   return a permuted tree

   created -- 96jan04, cca
   -----------------------
*/
Tree *
Tree_permute (
   Tree   *tree,
   int    newToOld[],
   int    oldToNew[]
) {
int    n, u_old, v_new, v_old, w_old ;
Tree   *tree2 ;
/*
   ---------------
   check the input
   ---------------
*/
if (  tree == NULL || (n = tree->n) <= 0 
   || newToOld == NULL || oldToNew == NULL ) {
   fprintf(stderr, "\n fatal error in Tree_permute(%p,%p,%p)"
           "\n bad input\n", tree, newToOld, oldToNew) ;
   spoolesFatal();
}
/*
   -----------------
   create a new tree
   -----------------
*/
tree2 = Tree_new() ;
Tree_init1(tree2, n) ;
/*
   ---------------
   fill the fields
   ---------------
*/
for ( v_new = 0 ; v_new < n ; v_new++ ) {
   v_old = newToOld[v_new] ;
   if ( (w_old = tree->par[v_old]) != -1 ) {
      tree2->par[v_new] = oldToNew[w_old] ;
   }
   if ( (u_old = tree->fch[v_old]) != -1 ) {
      tree2->fch[v_new] = oldToNew[u_old] ;
   }
   if ( (u_old = tree->sib[v_old]) != -1 ) {
      tree2->sib[v_new] = oldToNew[u_old] ;
   }
}
if ( tree->root != -1 ) {
   tree2->root = oldToNew[tree->root] ;
}

return(tree2) ; }
Esempio n. 8
0
/*
   -----------------------------------------------
   initialize the object given the number of nodes

   created -- 96mar10, cca
   -----------------------------------------------
*/
void
DSTree_init1 (
   DSTree   *dstree,
   int      ndomsep,
   int      nvtx
) {
/*
   ---------------
   check the input
   ---------------
*/
if ( dstree == NULL || ndomsep <= 0 ) {
   fprintf(stderr, "\n fatal error in DSTree_init1(%p,%d,%d)"
           "\n bad input\n", dstree, ndomsep, nvtx) ;
   exit(-1) ;
}
DSTree_clearData(dstree) ;
dstree->tree = Tree_new() ;
Tree_init1(dstree->tree, ndomsep) ;
dstree->mapIV = IV_new() ;
IV_init(dstree->mapIV, nvtx, NULL) ;
IV_fill(dstree->mapIV, -1) ;

return ; }
Esempio n. 9
0
void ParserEnv_Init(ParserEnv* e, const char* str)
{
    e->char_count = 0;
    /**
    e->text = "func test2 (a float) (b float)\n"
              "{\n"
              "    b = a / 2.0;\n"
              "    print a;\n"
              "}\n"
              "func ttt (a float, b float) (c float)\n"
              "{\n"
              "    var t float;\n"
              "    var g float;\n"
              "    var i int;\n"
              "    i = 3;\n"
              "    t = 4.0 * i;\n"
              "    g = test2(3.0);\n"
              "    j := t * g;\n"
              "    print j;\n"
              "}";
              **/
    /**
    e->text = "func ttt (a float, b float) (c float)\n"
              "{\n"
              "    var t float;\n"
              "    var g float;\n"
              "    t = 3.0;\n"
              "    g = 1.0;\n"
              "    print t > g;\n"
              "}";
              **/
/**
    e->text = "func test2 (a float) (b float)\n"
              "{\n"
              "    b = a / 2.0;\n"
              "    print b;\n"
              "}\n"
              "func ttt (a float, b float) (c float)\n"
              "{\n"
              "    var t float;\n"
              "    var g float;\n"
              "    t = 1.0;\n"
              "    g = 2.0;\n"
              "    if ( t < g )\n"
              "    {\n"
              "        aaa := t + 1.0;\n"
              "        if (aaa == g)\n"
              "        {\n"
              "            print 100.0;\n"
              "        }\n"
              "        j := 9.0;\n"
              "        j = test2(j);\n"
              "        print j;\n"
              "    }\n"
              "    else if (t > g)\n"
              "    {\n"
              "        j := 12.0;\n"
              "        print j;\n"
              "    }\n"
              "    print 2.0;\n"
              "}\n";
**/
    e->text = (EString)str;
    ///e->sym_2_value_node_tree = Tree_new(String, Vptr, Ealloc, Efree);
    ///e->value_2_value_node_tree = Tree_new(Vptr, Vptr, Ealloc, Efree);
    e->key_word_tree = Tree_new(String, Vptr, Ealloc, Efree);
    e->func_tree = Tree_new(String, Vptr, Ealloc, Efree);
    e->struct_tree = Tree_new(String, Vptr, Ealloc, Efree);
    e->curt_func = NULL;


    _insert_key_word(e, "int", int_type);
    _insert_key_word(e, "float", float_type);
    _insert_key_word(e, "if", _if);
    _insert_key_word(e, "else", _else);
    _insert_key_word(e, "var", _var);
    _insert_key_word(e, "func", _funcdef);
    _insert_key_word(e, "print", _print);
    _insert_key_word(e, "for", _for);

    SymbolStack_Init(&e->sym_stack);
    SymbolStack_push(&e->sym_stack);

    e->return_point_stack = FixedStack_new(sizeof(return_point));

    e->line_count = 0;
    parser_exception null_exce = {-1, NULL};
    e->exce_array = array_new(parser_exception, 5, null_exce);
    /**
    e->vari_mem = SMalloc(128 * 1024);
    e->vari_str_mem = SMalloc(128 * 1024);
    e->cons_mem = SMalloc(128 * 1024);
    e->cons_str_mem = SMalloc(128 * 1024);
    **/
    for (int i = 0; i < MaxMem; i++)
    {
        e->mems[i] = (char*)SMalloc(128 * 1024);
    }

    ValueAllocator_Init(&e->vari_alloc);
    ValueAllocator_Init(&e->vari_str_alloc);
    ValueAllocator_Init(&e->cons_alloc);
    ValueAllocator_Init(&e->cons_str_alloc);
}
Esempio n. 10
0
void ParserEnv_Init(ParserEnv* e, const char* str)
{
    e->char_count = 0;
    /**
    e->text = "func test2 (a float) (b float)\n"
              "{\n"
              "    b = a / 2.0;\n"
              "    print a;\n"
              "}\n"
              "func ttt (a float, b float) (c float)\n"
              "{\n"
              "    var t float;\n"
              "    var g float;\n"
              "    var i int;\n"
              "    i = 3;\n"
              "    t = 4.0 * i;\n"
              "    g = test2(3.0);\n"
              "    j := t * g;\n"
              "    print j;\n"
              "}";
              **/
    /**
    e->text = "func ttt (a float, b float) (c float)\n"
              "{\n"
              "    var t float;\n"
              "    var g float;\n"
              "    t = 3.0;\n"
              "    g = 1.0;\n"
              "    print t > g;\n"
              "}";
              **/
    /**
        e->text = "func test2 (a float) (b float)\n"
                  "{\n"
                  "    b = a / 2.0;\n"
                  "    print b;\n"
                  "}\n"
                  "func ttt (a float, b float) (c float)\n"
                  "{\n"
                  "    var t float;\n"
                  "    var g float;\n"
                  "    t = 1.0;\n"
                  "    g = 2.0;\n"
                  "    if ( t < g )\n"
                  "    {\n"
                  "        aaa := t + 1.0;\n"
                  "        if (aaa == g)\n"
                  "        {\n"
                  "            print 100.0;\n"
                  "        }\n"
                  "        j := 9.0;\n"
                  "        j = test2(j);\n"
                  "        print j;\n"
                  "    }\n"
                  "    else if (t > g)\n"
                  "    {\n"
                  "        j := 12.0;\n"
                  "        print j;\n"
                  "    }\n"
                  "    print 2.0;\n"
                  "}\n";
    **/
    e->text = (EString)str;
    ///e->sym_2_value_node_tree = Tree_new(String, Vptr, Ealloc, Efree);
    ///e->value_2_value_node_tree = Tree_new(Vptr, Vptr, Ealloc, Efree);
    e->key_word_tree = Tree_new(String, Vptr, Ealloc, Efree);
    e->func_tree = Tree_new(String, Vptr, Ealloc, Efree);
    e->struct_tree = Tree_new(String, Vptr, Ealloc, Efree);
    e->curt_func = NULL;

    void _insert_key_word(char* str, int type)
    {
        var key, data;
        key.str_var = str;
        SymbolValue* v = Malloc(sizeof(SymbolValue));
        v->type = type;
        v->data.mem_addr.mem_type = MaxMem;
        data.vptr_var = v;
        Tree_insert(e->key_word_tree, key, data);
    }
Esempio n. 11
0
/*
   -----------------------------------------------------------------
   compress a tree based on a map from old vertices to new vertices.
   the restriction on the map is that the set {u | map[u] = U} must
   be connected for all U.

   created  -- 95nov15, cca
   modified -- 96jan04, cca
      bug fixed, N computed incorrectly
   modified -- 96jun23, cca
      in calling sequence, int map[] converted to IV *mapIV 
   -----------------------------------------------------------------
*/
Tree *
Tree_compress (
   Tree   *tree,
   IV     *mapIV
) {
int    n, N, u, U, v, V ;
int    *head, *link, *map ;
Tree   *tree2 ;
/*
   ---------------
   check the input
   ---------------
*/
if (  tree == NULL 
   || (n = tree->n) <= 0 
   || mapIV == NULL 
   || n != IV_size(mapIV)
   || (map = IV_entries(mapIV)) == NULL ) {
   fprintf(stderr, "\n fatal error in Tree_compress(%p,%p)"
           "\n bad input\n", tree, mapIV) ;
   exit(-1) ;
}
/*
   -----------------------
   initialize the new tree
   -----------------------
*/
N = 1 + IV_max(mapIV) ;
tree2 = Tree_new() ;
Tree_init1(tree2, N) ;
/*
   -----------------------------------------------------------
   get the head/link construct to map old nodes into new nodes
   -----------------------------------------------------------
*/
head = IVinit(N, -1) ;
link = IVinit(n, -1) ;
for ( v = 0 ; v < n ; v++ ) {
   if ( (V = map[v]) < 0 || V >= N ) {
      fprintf(stderr, "\n fatal error in Tree_compress(%p,%p)"
              "\n map[%d] = %d, N = %d\n", tree, map, v, V, N) ;
      exit(-1) ;
   }
   link[v] = head[V] ;
   head[V] =    v    ;
}
/*
   ---------------------
   fill the tree vectors
   ---------------------
*/
for ( U = 0 ; U < N ; U++ ) {
   for ( u = head[U] ; u != -1 ; u = link[u] ) {
      if ( (v = tree->par[u]) == -1 ) {
         tree2->par[U] = -1 ;
         break ;
      } else if ( (V = map[v]) != U ) {
         tree2->par[U] = V ;
         break ;
      }
   }
}
Tree_setFchSibRoot(tree2) ;
/*
   ------------------------
   free the working storage
   ------------------------
*/
IVfree(head) ;
IVfree(link) ;
 
return(tree2) ; }
Esempio n. 12
0
/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
   ----------------------------------------
   draw the tree

   created -- 99jan23, cca
   ----------------------------------------
*/
{
char     coordflag, heightflag ;
char     *inTagsFileName, *inTreeFileName, *outEPSfileName ;
double   fontsize, radius, t1, t2 ;
double   bbox[4], frame[4] ;
DV       *xDV, *yDV ;
int      ierr, msglvl, rc, tagsflag ;
IV       *tagsIV ;
Tree     *tree ;
FILE     *msgFile ;

if ( argc != 19 ) {
   fprintf(stdout, 
"\n\n usage : %s msglvl msgFile inTreeFile inTagsFile outEPSfile "
"\n       heightflag coordflag radius bbox[4] frame[4] tagflag fontsize"
      "\n    msglvl      -- message level"
      "\n    msgFile     -- message file"
      "\n    inTreeFile -- input file, must be *.treef or *.treeb"
      "\n    inTagsFile -- input file, must be *.ivf or *.ivb or none"
      "\n    outEPSfile -- output file"
      "\n    heightflag -- height flag"
      "\n       'D' -- use depth metric"
      "\n       'H' -- use height metric"
      "\n    coordflag -- coordinate flag"
      "\n       'C' -- use (x,y) Cartesian coordinates"
      "\n       'P' -- use (r,theta) polar coordinates"
      "\n    radius   -- radius of node"
      "\n    bbox[4]  -- bounding box"
      "\n    frame[4] -- frame for plot"
      "\n    fontsize -- size of fonts (in points)"
      "\n    tagflag  -- if 1, draw labels, otherwise, do not"
      "\n", argv[0]) ;
   return(0) ;
}
msglvl = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
   msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
   fprintf(stderr, "\n fatal error in %s"
           "\n unable to open file %s\n",
           argv[0], argv[2]) ;
   return(-1) ;
}
inTreeFileName = argv[3] ;
inTagsFileName = argv[4] ;
outEPSfileName = argv[5] ;
heightflag     = argv[6][0] ;
coordflag      = argv[7][0] ;
radius         = atof(argv[8]) ;
bbox[0]        = atof(argv[9]) ;
bbox[1]        = atof(argv[10]) ;
bbox[2]        = atof(argv[11]) ;
bbox[3]        = atof(argv[12]) ;
frame[0]       = atof(argv[13]) ;
frame[1]       = atof(argv[14]) ;
frame[2]       = atof(argv[15]) ;
frame[3]       = atof(argv[16]) ;
fontsize       = atof(argv[17]) ;
tagsflag       = atoi(argv[18]) ;
fprintf(msgFile, 
        "\n %s "
        "\n msglvl     -- %d" 
        "\n msgFile    -- %s" 
        "\n inTreeFile -- %s" 
        "\n inTagsFile -- %s" 
        "\n outEPSfile -- %s" 
        "\n heightflag -- %c" 
        "\n coordflag  -- %d" 
        "\n radius     -- %.3g" 
        "\n bbox       -- %.3g %.3g %.3g %.3g" 
        "\n frame      -- %.3g %.3g %.3g %.3g" 
        "\n fontsize   -- %.3g"
        "\n",
        argv[0], msglvl, argv[2], inTreeFileName, inTagsFileName,
        outEPSfileName, heightflag, coordflag, radius, 
        bbox[0], bbox[1], bbox[2], bbox[3],
        frame[0], frame[1], frame[2], frame[3], fontsize, tagsflag) ;
fflush(msgFile) ;
/*
   ------------------------
   read in the Tree object
   ------------------------
*/
if ( strcmp(inTreeFileName, "none") == 0 ) {
   fprintf(msgFile, "\n no file to read from") ;
   exit(0) ;
}
tree = Tree_new() ;
MARKTIME(t1) ;
rc = Tree_readFromFile(tree, inTreeFileName) ;
/*
Tree_setFchSibRoot(tree) ;
*/
Tree_leftJustify(tree) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %9.5f : read in tree from file %s",
        t2 - t1, inTreeFileName) ;
if ( rc != 1 ) {
   fprintf(msgFile, "\n return value %d from Tree_readFromFile(%p,%s)",
           rc, tree, inTreeFileName) ;
   exit(-1) ;
}
fprintf(msgFile, "\n\n after reading Tree object from file %s",
        inTreeFileName) ;
if ( msglvl > 2 ) {
   Tree_writeForHumanEye(tree, msgFile) ;
} else {
   Tree_writeStats(tree, msgFile) ;
}
fflush(msgFile) ;
if ( Tree_maxNchild(tree) > 2 ) {
   fprintf(msgFile, "\n\n maximum number of children = %d",
           Tree_maxNchild(tree)) ;
}
if ( strcmp(inTagsFileName, "none") != 0 ) {
/*
   --------------------------
   read in the tags IV object
   --------------------------
*/
   tagsIV = IV_new() ;
   MARKTIME(t1) ;
   rc = IV_readFromFile(tagsIV, inTagsFileName) ;
   MARKTIME(t2) ;
   fprintf(msgFile, "\n CPU %9.5f : read in tagsIV from file %s",
           t2 - t1, inTagsFileName) ;
   if ( rc != 1 ) {
      fprintf(msgFile, "\n return value %d from IV_readFromFile(%p,%s)",
              rc, tagsIV, inTagsFileName) ;
      exit(-1) ;
   }
   fprintf(msgFile, "\n\n after reading IV object from file %s",
           inTagsFileName) ;
   if ( msglvl > 2 ) {
      IV_writeForHumanEye(tagsIV, msgFile) ;
   } else {
      IV_writeStats(tagsIV, msgFile) ;
   }
   fflush(msgFile) ;
   if ( IV_size(tagsIV) != tree->n ) {
      fprintf(stderr, 
              "\n fatal error, IV_size(tagsIV) = %d, tree->n = %d",
              IV_size(tagsIV), tree->n) ;
      exit(-1) ;
   }
} else {
   tagsIV = NULL ;
}
/*
   -------------------------------
   get the coordinates of the tree
   -------------------------------
*/
xDV = DV_new() ;
yDV = DV_new() ;
rc = Tree_getSimpleCoords(tree, heightflag, coordflag, xDV, yDV) ;
if ( rc != 1 ) {
   fprintf(stderr, "\n error return %d from Tree_getSimpleCoords()",rc);
   exit(-1) ;
}
if ( msglvl > 1 ) {
   fprintf(msgFile, "\n\n x-coordinates") ;
   DV_writeForHumanEye(xDV, msgFile) ;
   fprintf(msgFile, "\n\n y-coordinates") ;
   DV_writeForHumanEye(yDV, msgFile) ;
   fflush(msgFile) ;
}
/*
   -------------
   draw the Tree
   -------------
*/
rc = Tree_drawToEPS(tree, outEPSfileName, xDV, yDV, radius, NULL,
                    tagsflag, fontsize, tagsIV, bbox, frame, NULL) ;
if ( rc != 1 ) {
   fprintf(stderr, "\n error return %d from Tree_drawToEPSfile()", rc) ;
   exit(-1) ;
}
/*
   ---------------------
   free the Tree object
   ---------------------
*/
Tree_free(tree) ;
if ( tagsIV != NULL ) {
   IV_free(tagsIV) ;
}

fprintf(msgFile, "\n") ;
fclose(msgFile) ;

return(1) ; }