void visit_form(Process *process, Obj *env, Obj *bytecodeObj, int *position, Obj *form) { if(eval_error) { return; } else if(form->tag == 'C') { if(form->car->car == NULL) { add_literal(bytecodeObj, position, nil); } else if(HEAD_EQ("quote")) { add_literal(bytecodeObj, position, form->car); } else if(HEAD_EQ("if")) { add_if(process, env, bytecodeObj, position, form); } else if(HEAD_EQ("while")) { add_while(process, env, bytecodeObj, position, form); } else if(HEAD_EQ("do")) { add_do(process, env, bytecodeObj, position, form); } else if(HEAD_EQ("let")) { add_let(process, env, bytecodeObj, position, form); } else if(HEAD_EQ("def")) { add_def(process, env, bytecodeObj, position, form); } else if(HEAD_EQ("reset!")) { add_reset(process, env, bytecodeObj, position, form); } else if(HEAD_EQ("ref")) { add_ref(process, env, bytecodeObj, position, form); } /* else if(HEAD_EQ("or")) { */ /* add_or(process, env, bytecodeObj, position, form); */ /* } */ else if(HEAD_EQ("not")) { add_not(process, env, bytecodeObj, position, form); } else if(HEAD_EQ("fn")) { Obj *lambda = obj_new_lambda(form->cdr->car, form_to_bytecode(process, env, form->cdr->cdr->car), env, form); add_literal(bytecodeObj, position, lambda); } else { add_call(process, env, bytecodeObj, position, form); } } else if(form->tag == 'Y') { add_lookup(bytecodeObj, position, form); } else { add_literal(bytecodeObj, position, form); } /* else { */ /* printf("Bytecode can't handle form: "); */ /* obj_print_cout(form); */ /* exit(1); */ /* } */ }
static void push_node(lua_State *L, const GumboNode *node) { luaL_checkstack(L, 10, "element nesting too deep"); switch (node->type) { case GUMBO_NODE_DOCUMENT: { const GumboDocument *document = &node->v.document; lua_createtable(L, document->children.length, 4); add_literal(L, "type", "document"); add_string(L, "quirks_mode", quirksmap[document->doc_type_quirks_mode]); if (document->has_doctype) { lua_createtable(L, 0, 3); add_string(L, "name", document->name); add_string(L, "publicId", document->public_identifier); add_string(L, "systemId", document->system_identifier); lua_setfield(L, -2, "doctype"); } add_children(L, &document->children); return; } case GUMBO_NODE_ELEMENT: { const GumboElement *element = &node->v.element; lua_createtable(L, element->children.length, 7); lua_getfield(L, LUA_REGISTRYINDEX, "gumbo.element"); lua_setmetatable(L, -2); add_tag(L, element); add_string(L, "tag_namespace", tagnsmap[element->tag_namespace]); add_integer(L, "line", element->start_pos.line); add_integer(L, "column", element->start_pos.column); add_integer(L, "offset", element->start_pos.offset); add_parseflags(L, node->parse_flags); add_attributes(L, &element->attributes); add_children(L, &element->children); return; } case GUMBO_NODE_TEXT: create_text_node(L, &node->v.text); add_literal(L, "type", "text"); return; case GUMBO_NODE_COMMENT: create_text_node(L, &node->v.text); add_literal(L, "type", "comment"); return; case GUMBO_NODE_CDATA: create_text_node(L, &node->v.text); add_literal(L, "type", "cdata"); return; case GUMBO_NODE_WHITESPACE: create_text_node(L, &node->v.text); add_literal(L, "type", "whitespace"); return; } }
size_t ewah_add(struct ewah_bitmap *self, eword_t word) { self->bit_size += BITS_IN_EWORD; if (word == 0) return add_empty_word(self, 0); if (word == (eword_t)(~0)) return add_empty_word(self, 1); return add_literal(self, word); }
int luaopen_gumbo(lua_State *L) { if (luaL_newmetatable(L, "gumbo.element")) { lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); lua_newtable(L); lua_setfield(L, -2, "attr"); add_literal(L, "type", "element"); luaL_setfuncs(L, Element, 0); } luaL_newlib(L, lib); return 1; }
void ewah_set(struct ewah_bitmap *self, size_t i) { const size_t dist = (i + BITS_IN_EWORD) / BITS_IN_EWORD - (self->bit_size + BITS_IN_EWORD - 1) / BITS_IN_EWORD; assert(i >= self->bit_size); self->bit_size = i + 1; if (dist > 0) { if (dist > 1) add_empty_words(self, 0, dist - 1); add_literal(self, (eword_t)1 << (i % BITS_IN_EWORD)); return; } if (rlw_get_literal_words(self->rlw) == 0) { rlw_set_running_len(self->rlw, rlw_get_running_len(self->rlw) - 1); add_literal(self, (eword_t)1 << (i % BITS_IN_EWORD)); return; } self->buffer[self->buffer_size - 1] |= ((eword_t)1 << (i % BITS_IN_EWORD)); /* check if we just completed a stream of 1s */ if (self->buffer[self->buffer_size - 1] == (eword_t)(~0)) { self->buffer[--self->buffer_size] = 0; rlw_set_literal_words(self->rlw, rlw_get_literal_words(self->rlw) - 1); add_empty_word(self, 1); } }
int processFileLine(option_block *opts, char *line, int line_len) { FILE *t; char *f; int state; int lno; char *delim; int sze; switch(line[0]) { case '/': if(line[1] != '/') break; case ';': case '#': case 0: case '\n': return 0; case '\r': if(line[1] == '\n') return 0; break; } /*not a comment, regular state*/ #ifndef NOPLUGIN if(!strncasecmp("plugin", line, 6)) { delim = strstr(line, " "); if(delim == NULL) { file_error("plugin line with no file specified. abort!", opts); } plugin_load(delim, opts); return 0; } #endif if(!strncasecmp("literal", line, 7)) { delim = strstr(line, "="); if(delim == NULL) { file_error("literal string not assigned!", opts); } sze = strlen(delim+1); if(sze == 0) { file_error("literal string is null!", opts); } add_literal(opts, delim+1, sze); return 0; } if(!strncasecmp("++", line, 2)) { set_bsym_increment(opts, line+2); return 0; } if(!strncasecmp("sequence", line, 7)) { delim = strstr(line, "="); if(delim == NULL) { file_error("sequence string not assigned!", opts); } sze = strlen(delim+1); if(sze == 0) { file_error("sequence string is null!", opts); } add_sequence(opts, delim+1, sze); return 0; } if(!strncasecmp("reppol", line, 6)) { delim = strstr(line, "="); if(delim == NULL) file_error("replacement policy not specified.", opts); f = delim+1; if(!strncasecmp(f, "always", 6)) { opts->repl_pol = 1; } else if(!strncasecmp(f, "once", 5)) { opts->repl_pol = 2; } else file_error("replacement policy not recognized.", opts); return 0; } if(!strncasecmp("reqwait", line, 7)) { delim = strstr(line, "="); if(delim == NULL) file_error("request wait string not assigned!", opts); sze = strlen(delim+1); if(sze == 0) file_error("request wait string is null!", opts); opts->reqw_inms = atoi(delim+1); return 0; } if(!strncasecmp("lineterm", line, 8)) { delim = strstr(line, "="); if(delim == NULL) file_error("lineterm value not assigned!", opts); sze = strlen(delim+1); state = strlen(line) - sze; if(sze) { if((line[state] == '\\') || (line[state] == '0')) { if(line[state] == 'x') sze = ascii_to_bin(line+state); } memcpy(opts->line_term, line+state, sze); } opts->line_terminator_size = sze; return 0; } if(!strncasecmp("maxseqlen", line, 9)) { delim = strstr(line, "="); if(delim == NULL) file_error("max seq len not assigned!", opts); sze = strlen(delim+1); if(sze == 0) file_error("max seq len is null!", opts); opts->mseql = atoi(delim+1); return 0; } if(!strncasecmp("seqstep", line, 7)) { delim = strstr(line, "="); if(delim == NULL) file_error("seq step not assigned!", opts); sze = strlen(delim+1); if(sze == 0) file_error("seq step is null!", opts); opts->seqstep = atoi(delim+1); return 0; } if(!strncasecmp("endcfg", line, 6)) return 1; if(!strncasecmp("include", line, 7)) { delim = strstr(line, " "); if(delim == NULL) file_error("include not assigned!", opts); sze = strlen(delim+1); if(sze == 0) file_error("include is null!", opts); t = opts->fp; f = malloc(strlen(opts->pFilename)); if(f == NULL) { file_error("unable to include file - out of memory.", opts); } /*yeah yeah...not safe. So fuzz it, already!*/ strcpy(f, opts->pFilename); state = opts->state; strncpy(opts->pFilename, delim+1, MAX_FILENAME_SIZE-1); /*setup for inner parse.*/ opts->state = INIT_READ; lno = opts->lno; /*do inner parse.*/ read_config(opts); strcpy(opts->pFilename, f); opts->state = state; opts->lno = lno; opts->fp = t; free(f); return 0; } if(line[0] == '$') { delim = strstr(line+1, "="); if(delim == NULL) { file_error("symbol not assigned!", opts); } sze = strlen(delim+1); if(sze == 0) { file_error("symbol is null!", opts); } add_symbol(line+1, (delim - (line+1)), delim+1, sze, opts, 0); return 0; } else if (line[0] == '!') { /*binary stuff*/ delim = strstr(line+1, "="); if(delim == NULL) { file_error("binary symbol not assigned!", opts); } sze = strlen(delim+1); if(sze == 0) { file_error("binary symbol is null!", opts); } sze = ascii_to_bin(delim+1); if(sze < 0) { file_error("binary text is invalid!", opts); } add_b_symbol(line+1, (delim - (line+1)), delim+1, sze, opts); return 0; } else if (line[0] == '|') { delim = strstr(line+1, "="); if(delim == NULL) { file_error("symbol not assigned!", opts); } sze = strlen(delim+1); if(sze == 0) { file_error("symbol is null!", opts); } add_subst_symbol(line+1, (delim - (line+1)), delim+1, sze, opts, 0); return 0; } #ifndef NOPLUGIN if(g_plugin != NULL && ((g_plugin->capex() & PLUGIN_PROVIDES_LINE_OPTS) == PLUGIN_PROVIDES_LINE_OPTS)) { return g_plugin->config(opts, line, line_len); } #endif fprintf(stderr, "[%s]\n", line); file_error("invalid config file.", opts); return 1; }
lexer::lexer() { add_literal( "and" ); add_literal( "auto" ); add_literal( "axiom" ); add_literal( "case" ); add_literal( "class" ); add_literal( "concept" ); add_literal( "default" ); add_literal( "delete" ); add_literal( "do" ); add_literal( "else" ); add_literal( "explicit" ); add_literal( "for" ); add_literal( "function" ); add_literal( "if" ); add_literal( "implicit" ); add_literal( "namespace" ); add_literal( "not" ); add_literal( "null" ); add_literal( "or" ); add_literal( "requires" ); add_literal( "return" ); add_literal( "self" ); add_literal( "sizeof" ); add_literal( "switch" ); add_literal( "using" ); add_literal( "while" ); add_literal( "+=" ); add_literal( "-=" ); add_literal( "*=" ); add_literal( "/=" ); add_literal( "%=" ); add_literal( "<<=" ); add_literal( ">>=" ); add_literal( "|=" ); add_literal( "^=" ); add_literal( "&=" ); add_literal( "||" ); add_literal( "&&" ); add_literal( "==" ); add_literal( "!=" ); add_literal( "<=" ); add_literal( ">=" ); add_literal( "<<" ); add_literal( ">>" ); add_literal( "++" ); add_literal( "--" ); add_literal( "->" ); add_literal( "::" ); add_literal( "," ); add_literal( ":" ); add_literal( ";" ); add_literal( "(" ); add_literal( ")" ); add_literal( "[" ); add_literal( "]" ); add_literal( "{" ); add_literal( "}" ); add_literal( "?" ); add_literal( "=" ); add_literal( "|" ); add_literal( "^" ); add_literal( "&" ); add_literal( "<" ); add_literal( ">" ); add_literal( "+" ); add_literal( "-" ); add_literal( "*" ); add_literal( "/" ); add_literal( "%" ); add_literal( "~" ); add_literal( "!" ); add_literal( "." ); self.add( int_literal = "[0-9]+" ); self.add( bool_literal = "true|false" ); self.add( char_literal = "'.'" ); self.add( string_literal = "\\\".*\\\"" ); self.add( identifier = "[a-zA-Z_][a-zA-Z_0-9]*" ); self += lex::string( "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/" ) [ lex::_pass = lex::pass_flags::pass_ignore ] | lex::string( "[ \t\n\r]+" ) [ lex::_pass = lex::pass_flags::pass_ignore ] ; self.add( "." ); // everything else }