- vec_push(localblock->locals, var);
- parser_addlocal(parser, var->name, (ast_expression*)var);
- if (isvector) {
- for (i = 0; i < 3; ++i) {
- parser_addlocal(parser, me[i]->name, (ast_expression*)me[i]);
- ast_block_collect(localblock, (ast_expression*)me[i]);
+ if (is_static) {
+ /* a static adds itself to be generated like any other global
+ * but is added to the local namespace instead
+ */
+ char *defname = NULL;
+ size_t prefix_len, ln;
+
+ ln = strlen(parser->function->name);
+ vec_append(defname, ln, parser->function->name);
+
+ vec_append(defname, 2, "::");
+ /* remember the length up to here */
+ prefix_len = vec_size(defname);
+
+ /* Add it to the local scope */
+ util_htset(vec_last(parser->variables), var->name, (void*)var);
+ /* now rename the global */
+ ln = strlen(var->name);
+ vec_append(defname, ln, var->name);
+ ast_value_set_name(var, defname);
+
+ /* push it to the to-be-generated globals */
+ vec_push(parser->globals, (ast_expression*)var);
+
+ /* same game for the vector members */
+ if (isvector) {
+ for (i = 0; i < 3; ++i) {
+ util_htset(vec_last(parser->variables), me[i]->name, (void*)(me[i]));
+
+ vec_shrinkto(defname, prefix_len);
+ ln = strlen(me[i]->name);
+ vec_append(defname, ln, me[i]->name);
+ ast_member_set_name(me[i], defname);
+
+ vec_push(parser->globals, (ast_expression*)me[i]);
+ }
+ }
+ vec_free(defname);
+ } else {
+ vec_push(localblock->locals, var);
+ parser_addlocal(parser, var->name, (ast_expression*)var);
+ if (isvector) {
+ for (i = 0; i < 3; ++i) {
+ parser_addlocal(parser, me[i]->name, (ast_expression*)me[i]);
+ ast_block_collect(localblock, (ast_expression*)me[i]);
+ }