Пример #1
0
int main()
{
    char buff[256];
    int result[256];
    int  i = 0;
    printf("Input the origin list of (DI):\n");
    while(1){
         if(i > 255){
             i--;
             break;
         }
         scanf("%c",&buff[i]);
         if(buff[i] == '\n'){
             break;
         }
         i++;
    }

    int len = 0;
    if((len = gen_string(buff, i, result)) > 0){
        printf("String result:\n");
        int j = 0;
        for(j=0;j<len;j++){
            printf("%d ", result[j]);
        }
        printf("\n");
    }
}
Пример #2
0
void cpp_gen::visit(const mfast::unicode_field_instruction* inst, void*)
{
  gen_string(inst, "unicode");
  if (inst->length_name()) {
    out_ << ", // initial value\n"
         << "  " << inst->length_id() << ", // length id\n"
         << "  \"" <<  inst->length_name() << "\", // length name\n"
         << "  \"" << inst->length_ns() << "\"); // length ns\n\n";
  }
  else {
    out_ << "); // initial value\n\n";
  }
}
Пример #3
0
static VALUE rb_cFixnum_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
  VALUE str = rb_funcall(self, rb_intern("to_s"), 0);
  char *cptr = RSTRING_PTR(str);

  if (memcmp(cptr, "NaN", sizeof("NaN")) == 0 || memcmp(cptr, "Infinity", sizeof("Infinity")) == 0 || memcmp(cptr, "-Infinity", sizeof("-Infinity")) == 0) {
    rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
  }

  if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
    gen_string(rb_yajl_gen, str);
  } else {
    gen_number(rb_yajl_gen, str);
  }

  return Qnil;
}
Пример #4
0
static VALUE rb_cArray_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
  if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
    gen_string(rb_yajl_gen, rb_funcall(self, rb_intern("to_s"), 0));
  } else {
    VALUE val;
    long i;
    ID sym_ffi_yajl = rb_intern("ffi_yajl");

    gen_array_open(rb_yajl_gen);

    for(i=0; i<RARRAY_LEN(self); i++) {
      val = rb_ary_entry(self, i);
      rb_funcall(val, sym_ffi_yajl, 2, rb_yajl_gen, state);
    }

    gen_array_close(rb_yajl_gen);
  }

  return Qnil;
}
Пример #5
0
void jvmcodegen::gen_node(const ast::node_ptr &node) {

    switch (node->type) {
//    case ast::no_node: gen_node(node); break;
    case ast::integer_node: gen_integer(node); break;
    case ast::string_node: gen_string(node); break;
    case ast::if_stmt_node: gen_if_stmt(node); break;
    case ast::while_stmt_node: gen_while_stmt(node); break;
    case ast::return_stmt_node: gen_return_stmt(node); break;
    case ast::variable_node: gen_variable(node); break;
    case ast::assign_stmt_node: gen_assign_stmt(node); break;
    case ast::call_node: gen_call(node); break;
    case ast::op_arithm_node: gen_op_arithm(node); break;
    case ast::op_logical_node: gen_op_logical(node); break;
    case ast::program_node: gen_program(node); break;
    case ast::type_node: gen_type(node); break;
    case ast::argument_node: gen_argument(node); break;
    case ast::variable_decl_node: gen_variable_decl(node); break;
    case ast::function_decl_node: gen_function_decl(node); break;
    case ast::read_stmt_node: gen_read_stmt(node); break;
    case ast::write_stmt_node: gen_write_stmt(node); break;
    }
}
Пример #6
0
static VALUE rb_cHash_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
  if ( rb_hash_aref(state, rb_str_new2("processing_key")) == Qtrue ) {
    gen_string(rb_yajl_gen, rb_funcall(self, rb_intern("to_s"), 0));
  } else {

    /* FIXME: i think this got refactored from something else and it is now pointless --
       should just pass rb_yajl_gen directly instead of this 'extra' hash -- i don't
       *think* this indirection is doing anything useful to mark memory against the GC */

    VALUE extra = rb_hash_new();

    rb_hash_aset(extra, rb_str_new2("yajl_gen"), rb_yajl_gen);

    rb_hash_aset(extra, rb_str_new2("state"), state);

    gen_map_open(rb_yajl_gen);

    rb_hash_foreach(self, rb_cHash_ffi_yajl_callback, extra);

    gen_map_close(rb_yajl_gen);
  }

  return Qnil;
}
Пример #7
0
LLVMValueRef gen_expr(compile_t* c, ast_t* ast)
{
  LLVMValueRef ret;
  bool has_scope = ast_has_scope(ast);
  bool has_source = codegen_hassource(c);

  if(has_scope)
  {
    codegen_pushscope(c);

    // Dwarf a new lexical scope, if necessary.
    if(has_source)
      dwarf_lexicalscope(&c->dwarf, ast);
  }

  switch(ast_id(ast))
  {
    case TK_SEQ:
      ret = gen_seq(c, ast);
      break;

    case TK_FVARREF:
    case TK_FLETREF:
      ret = gen_fieldload(c, ast);
      break;

    case TK_PARAMREF:
      ret = gen_param(c, ast);
      break;

    case TK_VAR:
    case TK_LET:
      ret = gen_localdecl(c, ast);
      break;

    case TK_VARREF:
    case TK_LETREF:
      ret = gen_localload(c, ast);
      break;

    case TK_IF:
      ret = gen_if(c, ast);
      break;

    case TK_WHILE:
      ret = gen_while(c, ast);
      break;

    case TK_REPEAT:
      ret = gen_repeat(c, ast);
      break;

    case TK_TRY:
    case TK_TRY_NO_CHECK:
      ret = gen_try(c, ast);
      break;

    case TK_MATCH:
      ret = gen_match(c, ast);
      break;

    case TK_CALL:
      ret = gen_call(c, ast);
      break;

    case TK_CONSUME:
      ret = gen_expr(c, ast_childidx(ast, 1));
      break;

    case TK_RECOVER:
      ret = gen_expr(c, ast_childidx(ast, 1));
      break;

    case TK_BREAK:
      ret = gen_break(c, ast);
      break;

    case TK_CONTINUE:
      ret = gen_continue(c, ast);
      break;

    case TK_RETURN:
      ret = gen_return(c, ast);
      break;

    case TK_ERROR:
      ret = gen_error(c, ast);
      break;

    case TK_IS:
      ret = gen_is(c, ast);
      break;

    case TK_ISNT:
      ret = gen_isnt(c, ast);
      break;

    case TK_ASSIGN:
      ret = gen_assign(c, ast);
      break;

    case TK_THIS:
      ret = gen_this(c, ast);
      break;

    case TK_TRUE:
      ret = LLVMConstInt(c->i1, 1, false);
      break;

    case TK_FALSE:
      ret = LLVMConstInt(c->i1, 0, false);
      break;

    case TK_INT:
      ret = gen_int(c, ast);
      break;

    case TK_FLOAT:
      ret = gen_float(c, ast);
      break;

    case TK_STRING:
      ret = gen_string(c, ast);
      break;

    case TK_TUPLE:
      ret = gen_tuple(c, ast);
      break;

    case TK_FFICALL:
      ret = gen_ffi(c, ast);
      break;

    case TK_AMP:
      ret = gen_addressof(c, ast);
      break;

    case TK_IDENTITY:
      ret = gen_identity(c, ast);
      break;

    case TK_DONTCARE:
      ret = GEN_NOVALUE;
      break;

    case TK_COMPILER_INTRINSIC:
      ast_error(ast, "unimplemented compiler intrinsic");
      LLVMBuildUnreachable(c->builder);
      ret = GEN_NOVALUE;
      break;

    default:
      ast_error(ast, "not implemented (codegen unknown)");
      return NULL;
  }

  if(has_scope)
  {
    codegen_popscope(c);

    if(has_source)
      dwarf_finish(&c->dwarf);
  }

  return ret;
}
Пример #8
0
/* calls #to_s on an object to encode it as a yajl string */
static VALUE gen_string_to_s(VALUE rb_yajl_gen, VALUE self) {
  return gen_string(rb_yajl_gen, RB_FUNC0("to_s"));
}
Пример #9
0
static VALUE rb_cStringIO_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
  return gen_string(rb_yajl_gen, RB_FUNC0("read"));
}
Пример #10
0
static VALUE rb_cTime_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
  ID sym_strftime = rb_intern("strftime");
  VALUE str = rb_funcall(self, sym_strftime, 1, rb_str_new2("%Y-%m-%d %H:%M:%S %z"));

  return gen_string(rb_yajl_gen, str);
}
Пример #11
0
static VALUE rb_cString_ffi_yajl(VALUE self, VALUE rb_yajl_gen, VALUE state) {
  return gen_string(rb_yajl_gen, self);
}
Пример #12
0
LLVMValueRef gen_expr(compile_t* c, ast_t* ast)
{
  LLVMValueRef ret;
  bool has_scope = ast_has_scope(ast);

  if(has_scope)
    codegen_pushscope(c, ast);

  switch(ast_id(ast))
  {
    case TK_SEQ:
      ret = gen_seq(c, ast);
      break;

    case TK_FVARREF:
    case TK_FLETREF:
      ret = gen_fieldload(c, ast);
      break;

    case TK_EMBEDREF:
      ret = gen_fieldptr(c, ast);
      break;

    case TK_PARAMREF:
      ret = gen_param(c, ast);
      break;

    case TK_VAR:
    case TK_LET:
    case TK_MATCH_CAPTURE:
      ret = gen_localdecl(c, ast);
      break;

    case TK_VARREF:
    case TK_LETREF:
      ret = gen_localload(c, ast);
      break;

    case TK_IF:
      ret = gen_if(c, ast);
      break;

    case TK_WHILE:
      ret = gen_while(c, ast);
      break;

    case TK_REPEAT:
      ret = gen_repeat(c, ast);
      break;

    case TK_TRY:
    case TK_TRY_NO_CHECK:
      ret = gen_try(c, ast);
      break;

    case TK_MATCH:
      ret = gen_match(c, ast);
      break;

    case TK_CALL:
      ret = gen_call(c, ast);
      break;

    case TK_CONSUME:
      ret = gen_expr(c, ast_childidx(ast, 1));
      break;

    case TK_RECOVER:
      ret = gen_expr(c, ast_childidx(ast, 1));
      break;

    case TK_BREAK:
      ret = gen_break(c, ast);
      break;

    case TK_CONTINUE:
      ret = gen_continue(c, ast);
      break;

    case TK_RETURN:
      ret = gen_return(c, ast);
      break;

    case TK_ERROR:
      ret = gen_error(c, ast);
      break;

    case TK_IS:
      ret = gen_is(c, ast);
      break;

    case TK_ISNT:
      ret = gen_isnt(c, ast);
      break;

    case TK_ASSIGN:
      ret = gen_assign(c, ast);
      break;

    case TK_THIS:
      ret = gen_this(c, ast);
      break;

    case TK_TRUE:
      ret = LLVMConstInt(c->i1, 1, false);
      break;

    case TK_FALSE:
      ret = LLVMConstInt(c->i1, 0, false);
      break;

    case TK_INT:
      ret = gen_int(c, ast);
      break;

    case TK_FLOAT:
      ret = gen_float(c, ast);
      break;

    case TK_STRING:
      ret = gen_string(c, ast);
      break;

    case TK_TUPLE:
      ret = gen_tuple(c, ast);
      break;

    case TK_FFICALL:
      ret = gen_ffi(c, ast);
      break;

    case TK_ADDRESS:
      ret = gen_addressof(c, ast);
      break;

    case TK_DIGESTOF:
      ret = gen_digestof(c, ast);
      break;

    case TK_DONTCARE:
      ret = GEN_NOVALUE;
      break;

    case TK_COMPILE_INTRINSIC:
      ast_error(c->opt->check.errors, ast, "unimplemented compile intrinsic");
      return NULL;

    case TK_COMPILE_ERROR:
    {
      ast_t* reason_seq = ast_child(ast);
      ast_t* reason = ast_child(reason_seq);
      ast_error(c->opt->check.errors, ast, "compile error: %s",
        ast_name(reason));
      return NULL;
    }

    default:
      ast_error(c->opt->check.errors, ast, "not implemented (codegen unknown)");
      return NULL;
  }

  if(has_scope)
    codegen_popscope(c);

  return ret;
}
Пример #13
0
char *
Generator::gen_string (void)
{
  return gen_string (TEST_BUFSIZE);
}
Пример #14
0
void cpp_gen::visit(const mfast::ascii_field_instruction* inst, void*)
{
  gen_string(inst, "ascii");
  out_ <<  "); // initial value\n\n";
}