lily_tie *lily_get_string_literal(lily_symtab *symtab, const char *want_string) { lily_tie *lit, *ret; ret = NULL; int want_string_len = strlen(want_string); for (lit = symtab->literals;lit;lit = lit->next) { if (lit->type->cls->id == SYM_CLASS_STRING) { if (lit->value.string->size == want_string_len && strcmp(lit->value.string->string, want_string) == 0) { ret = lit; break; } } } if (ret == NULL) { lily_class *cls = symtab->string_class; ret = make_new_literal(symtab, cls); ret->value.string = lily_new_raw_string(want_string); ret->flags |= VAL_IS_STRING; } return ret; }
lily_literal *lily_get_string_literal(lily_symtab *symtab, const char *want_string) { lily_literal *iter = first_lit_of(symtab->literals, VAL_IS_STRING); int want_string_len = strlen(want_string); while (iter) { if (iter->value.string->size == want_string_len && strcmp(iter->value.string->string, want_string) == 0) return iter; int next = iter->next_index; if (next == 0) break; else iter = (lily_literal *)lily_vs_nth(symtab->literals, next); } if (iter) iter->next_index = lily_vs_pos(symtab->literals); lily_literal *v = (lily_literal *)lily_new_empty_value(); v->flags = VAL_IS_STRING; v->reg_spot = lily_vs_pos(symtab->literals); v->next_index = 0; v->value.string = lily_new_raw_string(want_string); /* Manual ref, because the string isn't being moved/assigned anywhere. */ v->value.string->refcount++; lily_vs_push(symtab->literals, (lily_value *)v); return (lily_literal *)v; }
void lily_list_join(lily_vm_state *vm, uint16_t argc, uint16_t *code) { lily_value **vm_regs = vm->vm_regs; lily_value *result_reg = vm_regs[code[0]]; lily_list_val *lv = vm_regs[code[1]]->value.list; const char *delim = ""; if (argc == 2) delim = vm_regs[code[2]]->value.string->string; lily_msgbuf *vm_buffer = vm->vm_buffer; lily_msgbuf_flush(vm_buffer); if (lv->num_values) { int i, stop = lv->num_values - 1; lily_value **values = lv->elems; for (i = 0;i < stop;i++) { lily_vm_add_value_to_msgbuf(vm, vm_buffer, values[i]); lily_msgbuf_add(vm_buffer, delim); } if (stop != -1) lily_vm_add_value_to_msgbuf(vm, vm_buffer, values[i]); } lily_move_string(result_reg, lily_new_raw_string(vm_buffer->message)); }
/** var httpmethod: String This is the method that was used to make the request to the server. Common values are "GET", and "POST". */ static lily_value *load_var_httpmethod(lily_options *options, uint16_t *unused) { lily_value *v = lily_new_empty_value(); request_rec *r = (request_rec *)options->data; lily_move_string(v, lily_new_raw_string(r->method)); return v; }
void lily_pg_result_each_row(lily_vm_state *vm, uint16_t argc, uint16_t *code) { lily_value **vm_regs = vm->vm_regs; lily_pg_result *boxed_result = (lily_pg_result *) vm_regs[code[1]]->value.generic; PGresult *raw_result = boxed_result->pg_result; if (raw_result == NULL || boxed_result->row_count == 0) return; lily_value *function_reg = vm_regs[code[2]]; int cached = 0; int row; for (row = 0;row < boxed_result->row_count;row++) { lily_list_val *lv = lily_new_list_val_0(); lily_value fake_reg; lv->elems = lily_malloc(boxed_result->column_count * sizeof(lily_value *)); int col; for (col = 0;col < boxed_result->column_count;col++) { char *field_text; if (PQgetisnull(raw_result, row, col)) field_text = "(null)"; else field_text = PQgetvalue(raw_result, row, col); lily_string_val *sv = lily_new_raw_string(field_text); lv->elems[col] = lily_new_value(VAL_IS_STRING, (lily_raw_value){.string = sv}); } lv->num_values = col; fake_reg.value.list = lv; fake_reg.flags = VAL_IS_LIST | VAL_IS_DEREFABLE; lily_foreign_call(vm, &cached, 0, function_reg, 1, &fake_reg); }