Exemplo n.º 1
0
void hopc_ffi__sleep(hopc_runtime *runtime, hcell cell) {
    if( CURRENT(runtime) ) {
        CURRENT(runtime)->tsleep_since = hopc_getcputime(runtime);
        CURRENT(runtime)->tsleep = HOPC_TICKS_OF_MILLIS(W(cell));
        runtime->tasktime = 0;
    }
}
Exemplo n.º 2
0
void hopc_detach_current(hopc_runtime *runtime) {
    if( CURRENT(runtime) ) {
        task_sweep(CURRENT(runtime));
/*        fprintf(stderr, "DETACH TASK %08X\n", CURRENT(runtime));*/
        runtime->tasktime = 0;
    }
}
Exemplo n.º 3
0
hopc_ar *hopc_push_activation_record2(hopc_runtime *runtime, memchunk *chunk) {
    hopc_ar *arp = (hopc_ar*)hopc_gc_chunk_start(runtime, (hcell*)chunk);
    if( CURRENT(runtime) ) {
        arp->next = CURRENT(runtime)->arhead;
        CURRENT(runtime)->arhead = arp;
    }
    return arp;
}
Exemplo n.º 4
0
static gboolean
typelib_attr_dcl(TreeState *state)
{
    XPTInterfaceDescriptor *id = CURRENT(state);
    XPTMethodDescriptor *meth;
    gboolean read_only = IDL_ATTR_DCL(state->tree).f_readonly;

    /* XXX this only handles the first ident; elsewhere too... */
    IDL_tree ident =
        IDL_LIST(IDL_ATTR_DCL(state->tree).simple_declarations).data;

    /* If it's marked [noscript], mark it as hidden in the typelib. */
    gboolean hidden = (IDL_tree_property_get(ident, "noscript") != NULL);

    gboolean wantsJSContext =
        (IDL_tree_property_get(ident, "implicit_jscontext") != NULL);

    if (!verify_attribute_declaration(state->tree))
        return FALSE;

    if (!XPT_InterfaceDescriptorAddMethods(ARENA(state), id, 
                                           (PRUint16) (read_only ? 1 : 2)))
        return FALSE;

    meth = &id->method_descriptors[NEXT_METH(state)];

    return typelib_attr_accessor(state, meth, TRUE, hidden, wantsJSContext) &&
        (read_only ||
         typelib_attr_accessor(state, meth + 1, FALSE, hidden, wantsJSContext));
}
Exemplo n.º 5
0
void __noprof kernel_main_thread(void *data)
{
	struct thread *me = CURRENT();
	struct thread_queue tmp_q;

	tq_init(&tmp_q);
	tq_insert_head(me, &tmp_q);

	bug_on(!scheduler_enqueue(&tmp_q));

	mach_running();

	kprintf("Initializing vfs core... ");
	fs_init();
	kprintf("Done.\n");

	call_late_init();

	run_tests();

	load_init();

	for (;;) {
		scheduler_yield();
		arch_idle();
	}

	bug();
}
Exemplo n.º 6
0
str
MALparser(Client c)
{
	InstrPtr p;
	MalBlkRecord oldstate;

	c->curprg->def->errors = 0;
	oldstate = *c->curprg->def;

	prepareMalBlk(c->curprg->def, CURRENT(c));
	if (parseMAL(c, c->curprg, 0) || c->curprg->def->errors) {
		/* just complete it for visibility */
		pushEndInstruction(c->curprg->def);
		/* caught errors */
		showErrors(c);
		if (c->listing)
			printFunction(c->fdout, c->curprg->def, 0, c->listing);
		MSresetVariables(c, c->curprg->def, c->glb, oldstate.vtop);
		resetMalBlk(c->curprg->def, 1);
		/* now the parsing is done we should advance the stream */
		c->fdin->pos += c->yycur;
		c->yycur = 0;
		throw(SYNTAX, "mal.parser", SYNTAX_GENERAL MANUAL_HELP);
	}

	/* now the parsing is done we should advance the stream */
	c->fdin->pos += c->yycur;
	c->yycur = 0;

	/* check for unfinished blocks */
	if (c->blkmode)
		return MAL_SUCCEED;
	/* empty files should be skipped as well */
	if (c->curprg->def->stop == 1)
		return MAL_SUCCEED;

	p = getInstrPtr(c->curprg->def, 0);
	if (p->token != FUNCTIONsymbol) {
		if (c->listing)
			printFunction(c->fdout, c->curprg->def, 0, c->listing);
		MSresetVariables(c, c->curprg->def, c->glb, oldstate.vtop);
		resetMalBlk(c->curprg->def, 1);
		throw(SYNTAX, "mal.parser", SYNTAX_SIGNATURE);
	}
	pushEndInstruction(c->curprg->def);
	chkProgram(c->fdout, c->nspace, c->curprg->def);
	if (c->curprg->def->errors) {
		showErrors(c);
		if (c->listing)
			printFunction(c->fdout, c->curprg->def, 0, c->listing);
		MSresetVariables(c, c->curprg->def, c->glb, oldstate.vtop);
		resetMalBlk(c->curprg->def, 1);
		throw(MAL, "MAL.parser", SEMANTIC_GENERAL);
	}
	return MAL_SUCCEED;
}
Exemplo n.º 7
0
static gboolean
typelib_const_dcl(TreeState *state)
{
    struct _IDL_CONST_DCL *dcl = &IDL_CONST_DCL(state->tree);
    const char *name = IDL_IDENT(dcl->ident).str;
    gboolean is_long;
    gboolean sign;
    IDL_tree real_type;
    XPTInterfaceDescriptor *id;
    XPTConstDescriptor *cd;
    IDL_longlong_t value;

    if (!verify_const_declaration(state->tree))
        return FALSE;

    /* Could be a typedef; try to map it to the real type. */
    real_type = find_underlying_type(dcl->const_type);
    real_type = real_type ? real_type : dcl->const_type;
    is_long = (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG);

    id = CURRENT(state);
    if (!XPT_InterfaceDescriptorAddConsts(ARENA(state), id, 1))
        return FALSE;
    cd = &id->const_descriptors[NEXT_CONST(state)];
    
    cd->name = IDL_IDENT(dcl->ident).str;
#ifdef DEBUG_shaver_const
    fprintf(stderr, "DBG: adding const %s\n", cd->name);
#endif
    if (!fill_td_from_type(state, &cd->type, dcl->const_type))
        return FALSE;
    
    value = IDL_INTEGER(dcl->const_exp).value;
    sign = IDL_TYPE_INTEGER(dcl->const_type).f_signed;
    if (is_long) {
        if (sign)
            cd->value.i32 = value;
        else
            cd->value.ui32 = value;
    } else {
        if (sign)
            cd->value.i16 = value;
        else
            cd->value.ui16 = value;
    }
    NEXT_CONST(state)++;
    return TRUE;
}
Exemplo n.º 8
0
static gboolean
fill_td_from_type(TreeState *state, XPTTypeDescriptor *td, IDL_tree type)
{
    IDL_tree up;
    int16 size_is_argnum;
    int16 length_is_argnum;
    gboolean has_size_is;
    gboolean has_length_is;
    gboolean is_array = FALSE;

    if (type) {

        /* deal with array */

        if (IDL_NODE_TYPE(state->tree) == IDLN_PARAM_DCL) {
            IDL_tree sd = IDL_PARAM_DCL(state->tree).simple_declarator;
            if (IDL_tree_property_get(sd, "array")) {

                is_array = TRUE;

                /* size_is is required! */
                if (!get_size_and_length(state, type, 
                                         &size_is_argnum, &length_is_argnum,
                                         &has_size_is, &has_length_is)) {
                    /* error was reported by helper function */
                    return FALSE;
                }

                if (!has_size_is) {
                   IDL_tree_error(state->tree, "[array] requires [size_is()]\n");
                    return FALSE;
                }

                td->prefix.flags = TD_ARRAY | XPT_TDP_POINTER;
                td->argnum = size_is_argnum;

                if (has_length_is)
                    td->argnum2 = length_is_argnum;
                else
                    td->argnum2 = size_is_argnum;

                /* 
                * XXX - NOTE - this will be broken for multidimensional 
                * arrays because of the realloc XPT_InterfaceDescriptorAddTypes
                * uses. The underlying 'td' can change as we recurse in to get
                * additional dimensions. Luckily, we don't yet support more
                * than on dimension in the arrays
                */
                /* setup the additional_type */                
                if (!XPT_InterfaceDescriptorAddTypes(ARENA(state), 
                                                     CURRENT(state), 1)) {
                    g_error("out of memory\n");
                    return FALSE;
                }
                td->type.additional_type = NEXT_TYPE(state);
                td = &CURRENT(state)->additional_types[NEXT_TYPE(state)];
                NEXT_TYPE(state)++ ;
            }
        }

handle_typedef:
        switch (IDL_NODE_TYPE(type)) {
          case IDLN_TYPE_INTEGER: {
              gboolean sign = IDL_TYPE_INTEGER(type).f_signed;
              switch(IDL_TYPE_INTEGER(type).f_type) {
                case IDL_INTEGER_TYPE_SHORT:
                  td->prefix.flags = sign ? TD_INT16 : TD_UINT16;
                  break;
                case IDL_INTEGER_TYPE_LONG:
                  td->prefix.flags = sign ? TD_INT32 : TD_UINT32;
                  break;
                case IDL_INTEGER_TYPE_LONGLONG:
                  td->prefix.flags = sign ? TD_INT64 : TD_UINT64;
                  break;
              }
              break;
          }
          case IDLN_TYPE_CHAR:
            td->prefix.flags = TD_CHAR;
            break;
          case IDLN_TYPE_WIDE_CHAR:
            td->prefix.flags = TD_WCHAR;
            break;
          case IDLN_TYPE_STRING:
            if (is_array) {
                td->prefix.flags = TD_PSTRING | XPT_TDP_POINTER;
            } else {
                if (!get_size_and_length(state, type, 
                                         &size_is_argnum, &length_is_argnum,
                                         &has_size_is, &has_length_is)) {
                    /* error was reported by helper function */
                    return FALSE;
                }
                if (has_size_is) {
                    td->prefix.flags = TD_PSTRING_SIZE_IS | XPT_TDP_POINTER;
                    td->argnum = size_is_argnum;
                    if (has_length_is)
                        td->argnum2 = length_is_argnum;
                    else
                        td->argnum2 = size_is_argnum;
                } else {
                    td->prefix.flags = TD_PSTRING | XPT_TDP_POINTER;
                }
            }
            break;
          case IDLN_TYPE_WIDE_STRING:
            if (is_array) {
                td->prefix.flags = TD_PWSTRING | XPT_TDP_POINTER;
            } else {
                if (!get_size_and_length(state, type, 
                                         &size_is_argnum, &length_is_argnum,
                                         &has_size_is, &has_length_is)) {
                    /* error was reported by helper function */
                    return FALSE;
                }
                if (has_size_is) {
                    td->prefix.flags = TD_PWSTRING_SIZE_IS | XPT_TDP_POINTER;
                    td->argnum = size_is_argnum;
                    if (has_length_is)
                        td->argnum2 = length_is_argnum;
                    else
                        td->argnum2 = size_is_argnum;
                } else {
                    td->prefix.flags = TD_PWSTRING | XPT_TDP_POINTER;
                }
            }
            break;
          case IDLN_TYPE_BOOLEAN:
            td->prefix.flags = TD_BOOL;
            break;
          case IDLN_TYPE_OCTET:
            td->prefix.flags = TD_UINT8;
            break;
          case IDLN_TYPE_FLOAT:
            switch (IDL_TYPE_FLOAT (type).f_type) {
              case IDL_FLOAT_TYPE_FLOAT:
                td->prefix.flags = TD_FLOAT;
                break;
              case IDL_FLOAT_TYPE_DOUBLE:
                td->prefix.flags = TD_DOUBLE;
                break;
              /* XXX 'long double' just ignored, or what? */
              default: break;
            }
            break;
          case IDLN_IDENT:
            if (!(up = IDL_NODE_UP(type))) {
                IDL_tree_error(state->tree,
                               "ERROR: orphan ident %s in param list\n",
                               IDL_IDENT(type).str);
                return FALSE;
            }
            switch (IDL_NODE_TYPE(up)) {
                /* This whole section is abominably ugly */
              case IDLN_FORWARD_DCL:
              case IDLN_INTERFACE: {
                XPTInterfaceDirectoryEntry *ide, *ides;
                uint16 num_ifaces;
                char *className;
                const char *iid_is;
handle_iid_is:
                ides = HEADER(state)->interface_directory;
                num_ifaces = HEADER(state)->num_interfaces;
                /* might get here via the goto, so re-check type */
                if (IDL_NODE_TYPE(up) == IDLN_INTERFACE)
                    className = IDL_IDENT(IDL_INTERFACE(up).ident).str;
                else if (IDL_NODE_TYPE(up) == IDLN_FORWARD_DCL)
                    className = IDL_IDENT(IDL_FORWARD_DCL(up).ident).str;
                else
                    className = IDL_IDENT(IDL_NATIVE(up).ident).str;
                iid_is = NULL;

                if (IDL_NODE_TYPE(state->tree) == IDLN_PARAM_DCL) {
                    iid_is =
                        IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
                                              "iid_is");
                }
                if (iid_is) {
                    int16 argnum;
                    if (!find_arg_with_name(state, iid_is, &argnum)) {
                        IDL_tree_error(state->tree,
                                       "can't find matching argument for "
                                       "[iid_is(%s)]\n", iid_is);
                        return FALSE;
                    }
                    td->prefix.flags = TD_INTERFACE_IS_TYPE | XPT_TDP_POINTER;
                    td->argnum = argnum;
                } else {
                    td->prefix.flags = TD_INTERFACE_TYPE | XPT_TDP_POINTER;
                    ide = FindInterfaceByName(ides, num_ifaces, className);
                    if (!ide || ide < ides || ide > ides + num_ifaces) {
                        IDL_tree_error(state->tree,
                                       "unknown iface %s in param\n",
                                       className);
                        return FALSE;
                    }
                    td->type.iface = ide - ides + 1;
#ifdef DEBUG_shaver_index
                    fprintf(stderr, "DBG: index %d for %s\n",
                            td->type.iface, className);
#endif
                }
                break;
              }
              case IDLN_NATIVE: {
                  char *ident;

                  /* jband - adding goto for iid_is when type is native */
                  if (IDL_NODE_TYPE(state->tree) == IDLN_PARAM_DCL &&
                      IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
                                              "iid_is"))
                      goto handle_iid_is;

                  ident = IDL_IDENT(type).str;
                  if (IDL_tree_property_get(type, "nsid")) {
                      td->prefix.flags = TD_PNSIID;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_POINTER | XPT_TDP_REFERENCE;
                      else if (IDL_tree_property_get(type,"ptr"))
                          td->prefix.flags |= XPT_TDP_POINTER;
                  } else if (IDL_tree_property_get(type, "domstring")) {
                      td->prefix.flags = TD_DOMSTRING | XPT_TDP_POINTER;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_REFERENCE;
                  } else if (IDL_tree_property_get(type, "astring")) {
                      td->prefix.flags = TD_ASTRING | XPT_TDP_POINTER;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_REFERENCE;
                  } else if (IDL_tree_property_get(type, "utf8string")) {
                      td->prefix.flags = TD_UTF8STRING | XPT_TDP_POINTER;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_REFERENCE;
                  } else if (IDL_tree_property_get(type, "cstring")) {
                      td->prefix.flags = TD_CSTRING | XPT_TDP_POINTER;
                      if (IDL_tree_property_get(type, "ref"))
                          td->prefix.flags |= XPT_TDP_REFERENCE;
                  } else if (IDL_tree_property_get(type, "jsval")) {
                      td->prefix.flags = TD_JSVAL;
                      if (IDL_tree_property_get(type, "ptr"))
                          td->prefix.flags |= XPT_TDP_POINTER;
                  } else {
                      td->prefix.flags = TD_VOID | XPT_TDP_POINTER;
                  }
                  break;
                }
              default:
                if (IDL_NODE_TYPE(IDL_NODE_UP(up)) == IDLN_TYPE_DCL) {
                    /* restart with the underlying type */
                    IDL_tree new_type;
                    new_type = IDL_TYPE_DCL(IDL_NODE_UP(up)).type_spec;
#ifdef DEBUG_shaver_misc
                    fprintf(stderr, "following %s typedef to %s\n",
                            IDL_IDENT(type).str, IDL_NODE_TYPE_NAME(new_type));
#endif
                    /* 
                    *  Do a nice messy goto rather than recursion so that
                    *  we can avoid screwing up the *array* information.
                    */
/*                    return fill_td_from_type(state, td, new_type); */
                    if (new_type) {
                        type = new_type;
                        goto handle_typedef;
                    } else {
                        /* do what we would do in recursion if !type */
                        td->prefix.flags = TD_VOID;
                        return TRUE;
                    }
                }
                IDL_tree_error(state->tree,
                               "can't handle %s ident in param list\n",
#ifdef DEBUG_shaver
                               /* XXX is this safe to use on Win now? */
                               IDL_NODE_TYPE_NAME(IDL_NODE_UP(type))
#else
                               "that type of"
#endif
                               );
#ifdef DEBUG_shaver
                XPT_ASSERT(0);
#endif
                return FALSE;
            }
            break;
          default:
            IDL_tree_error(state->tree, "can't handle %s in param list\n",
#ifdef DEBUG_shaver
                           /* XXX is this safe to use on Win now? */
                           IDL_NODE_TYPE_NAME(IDL_NODE_UP(type))
#else
                        "that type"
#endif
            );
            return FALSE;
        }
    } else {
        td->prefix.flags = TD_VOID;
    }

    return TRUE;
}
Exemplo n.º 9
0
static gboolean
typelib_interface(TreeState *state)
{
    IDL_tree iface = state->tree, iter;
    char *name = IDL_IDENT(IDL_INTERFACE(iface).ident).str;
    XPTInterfaceDirectoryEntry *ide;
    XPTInterfaceDescriptor *id;
    uint16 parent_id = 0;
    PRUint8 interface_flags = 0;

    if (!verify_interface_declaration(iface))
        return FALSE;

    if (IDL_tree_property_get(IDL_INTERFACE(iface).ident, "scriptable"))
        interface_flags |= XPT_ID_SCRIPTABLE;

    if (IDL_tree_property_get(IDL_INTERFACE(iface).ident, "function"))
        interface_flags |= XPT_ID_FUNCTION;

    ide = FindInterfaceByName(HEADER(state)->interface_directory,
                              HEADER(state)->num_interfaces, name);
    if (!ide) {
        IDL_tree_error(iface, "ERROR: didn't find interface %s in "
                       "IDE block. Giving up.\n", name);
        return FALSE;
    }

    if ((iter = IDL_INTERFACE(iface).inheritance_spec)) {
        char *parent;
        if (IDL_LIST(iter).next) {
            IDL_tree_error(iface,
                           "ERROR: more than one parent interface for %s\n",
                           name);
            return FALSE;
        }
        parent = IDL_IDENT(IDL_LIST(iter).data).str;
        parent_id = (uint16)(uint32)g_hash_table_lookup(IFACE_MAP(state),
                                                        parent);
        if (!parent_id) {
            IDL_tree_error(iface,
                           "ERROR: no index found for %s. Giving up.\n",
                           parent);
            return FALSE;
        }
    }

    id = XPT_NewInterfaceDescriptor(ARENA(state), parent_id, 0, 0, 
                                    interface_flags);
    if (!id)
        return FALSE;

    CURRENT(state) = ide->interface_descriptor = id;
#ifdef DEBUG_shaver_ifaces
    fprintf(stderr, "DBG: starting interface %s @ %p\n", name, id);
#endif

    NEXT_METH(state) = 0;
    NEXT_CONST(state) = 0;
    NEXT_TYPE(state) = 0;

    state->tree = IDL_INTERFACE(iface).body;
    if (state->tree && !xpidl_process_node(state))
        return FALSE;
#ifdef DEBUG_shaver_ifaces
    fprintf(stderr, "DBG: ending interface %s\n", name);
#endif
    return TRUE;
}
Exemplo n.º 10
0
static gboolean
typelib_op_dcl(TreeState *state)
{
    XPTInterfaceDescriptor *id = CURRENT(state);
    XPTMethodDescriptor *meth;
    struct _IDL_OP_DCL *op = &IDL_OP_DCL(state->tree);
    IDL_tree iter;
    uint16 num_args = 0;
    uint8 op_flags = 0;
    gboolean op_notxpcom = (IDL_tree_property_get(op->ident, "notxpcom")
                            != NULL);
    gboolean op_noscript = (IDL_tree_property_get(op->ident, "noscript")
                            != NULL);
    gboolean op_context = (IDL_tree_property_get(op->ident,
                                                 "implicit_jscontext") != NULL);
    gboolean op_opt_argc = (IDL_tree_property_get(op->ident, "optional_argc")
                            != NULL);

    if (!verify_method_declaration(state->tree))
        return FALSE;

    if (!XPT_InterfaceDescriptorAddMethods(ARENA(state), id, 1))
        return FALSE;

    meth = &id->method_descriptors[NEXT_METH(state)];

    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next)
        num_args++;             /* count params */
    if (op->op_type_spec && !op_notxpcom)
        num_args++;             /* fake param for _retval */

    if (op_noscript)
        op_flags |= XPT_MD_HIDDEN;
    if (op_notxpcom)
        op_flags |= XPT_MD_NOTXPCOM;
    if (op_opt_argc)
        op_flags |= XPT_MD_OPT_ARGC;
    if (op_context)
        op_flags |= XPT_MD_CONTEXT;

    /* XXXshaver constructor? */

#ifdef DEBUG_shaver_method
    fprintf(stdout, "DBG: adding method %s (nargs %d)\n",
            IDL_IDENT(op->ident).str, num_args);
#endif
    if (!XPT_FillMethodDescriptor(ARENA(state), meth, op_flags, 
                                  IDL_IDENT(op->ident).str,
                                  (uint8) num_args))
        return FALSE;

    for (num_args = 0, iter = op->parameter_dcls; iter;
         iter = IDL_LIST(iter).next, num_args++) {
        XPTParamDescriptor *pd = &meth->params[num_args];
        if (!fill_pd_from_param(state, pd, IDL_LIST(iter).data))
            return FALSE;
    }

    /* stick retval param where we can see it later */
    state->tree = op->op_type_spec;

    /* XXX unless [notxpcom] */
    if (!op_notxpcom) {
        if (op->op_type_spec) {
            uint8 pdflags = DIPPER_TYPE(op->op_type_spec) ?
                                (XPT_PD_RETVAL | XPT_PD_IN | XPT_PD_DIPPER) :
                                (XPT_PD_RETVAL | XPT_PD_OUT);
    
            if (!fill_pd_from_type(state, &meth->params[num_args],
                                   pdflags, op->op_type_spec))
                return FALSE;
        }

        if (!fill_pd_as_nsresult(meth->result))
            return FALSE;
    } else {
#ifdef DEBUG_shaver_notxpcom
        fprintf(stderr, "%s is notxpcom\n", IDL_IDENT(op->ident).str);
#endif
        if (!fill_pd_from_type(state, meth->result, XPT_PD_RETVAL,
                               op->op_type_spec))
            return FALSE;
    }
    NEXT_METH(state)++;
    return TRUE;
}
Exemplo n.º 11
0
/*
 * Input to be processed is collected in a Client specific buffer.  It
 * is filled by reading information from a stream, a terminal, or by
 * scheduling strings constructed internally.  The latter involves
 * removing any escape character needed to manipulate the string within
 * the kernel.  The buffer space is automatically expanded to
 * accommodate new information and the read pointers are adjusted.
 *
 * The input is read from a (blocked) stream and stored in the client
 * record input buffer. The storage area grows automatically upon need.
 * The origin of the input stream depends on the connectivity mode.
 *
 * Each operation received from a front-end consists of at least one
 * line.  To simplify misaligned communication with front-ends, we use
 * different prompts structures.
 *
 * The default action is to read information from an ascii-stream one
 * line at a time. This is the preferred mode for reading from terminal.
 * 
 * The next statement block is to be read. Send a prompt to warn the
 * front-end to issue the request.
 */
int
MCreadClient(Client c)
{
	bstream *in = c->fdin;

#ifdef MAL_CLIENT_DEBUG
	printf("# streamClient %d %d\n", c->idx, isa_block_stream(in->s));
#endif

	while (in->pos < in->len &&
		   (isspace((int) (in->buf[in->pos])) ||
			in->buf[in->pos] == ';' || !in->buf[in->pos]))
		in->pos++;

	if (in->pos >= in->len || in->mode) {
		ssize_t rd, sum = 0;

		if (in->eof || !isa_block_stream(c->fdout)) {
			if (!isa_block_stream(c->fdout) && c->promptlength > 0)
				mnstr_write(c->fdout, c->prompt, c->promptlength, 1);
			mnstr_flush(c->fdout);
			in->eof = 0;
		}
		while ((rd = bstream_next(in)) > 0 && !in->eof) {
			sum += rd;
			if (!in->mode) /* read one line at a time in line mode */
				break;
		}
		if (in->mode) { /* find last new line */
			char *p = in->buf + in->len - 1;

			while (p > in->buf && *p != '\n') {
				*(p + 1) = *p;
				p--;
			}
			if (p > in->buf)
				*(p + 1) = 0;
			if (p != in->buf + in->len - 1)
				in->len++;
		}
		if (sum == 0 && in->eof && isa_block_stream(in->s)) {
			/* we hadn't seen the EOF before, so just try again
			   (this time with prompt) */
#ifdef MAL_CLIENT_DEBUG
			printf("# retry stream reading %d %d\n", c->idx, in->eof);
#endif
			return MCreadClient(c);
		}
#ifdef MAL_CLIENT_DEBUG
		printf("# simple stream received %d sum " SZFMT "\n", c->idx, sum);
#endif
	}
	if (in->pos >= in->len) {
		/* end of stream reached */
#ifdef MAL_CLIENT_DEBUG
		printf("# end of stream received %d %d\n", c->idx, c->bak == 0);
#endif
		if (c->bak) {
			MCpopClientInput(c);
			if (c->fdin == NULL)
				return 0;
			return MCreadClient(c);
		}
		return 0;
	}
	if (*CURRENT(c) == '?') {
		showHelp(c->nspace, CURRENT(c) + 1, c->fdout);
		in->pos = in->len;
		return MCreadClient(c);
	}
#ifdef MAL_CLIENT_DEBUG
	printf("# finished stream read %d %d\n", (int) in->pos, (int) in->len);
	printf("#%s\n", in->buf);
#endif
	return 1;
}
Exemplo n.º 12
0
/* #define _SQL_READER_DEBUG */
str
SQLreader(Client c)
{
	int go = TRUE;
	int more = TRUE;
	int commit_done = FALSE;
	backend *be = (backend *) c->sqlcontext;
	bstream *in = c->fdin;
	int language = -1;
	mvc *m = NULL;
	int blocked = isa_block_stream(in->s);

	if (SQLinitialized == FALSE) {
		c->mode = FINISHCLIENT;
		return NULL;
	}
	if (!be || c->mode <= FINISHCLIENT) {
#ifdef _SQL_READER_DEBUG
		mnstr_printf(GDKout, "#SQL client finished\n");
#endif
		c->mode = FINISHCLIENT;
		return NULL;
	}
#ifdef _SQL_READER_DEBUG
	mnstr_printf(GDKout, "#SQLparser: start reading SQL %s %s\n", (be->console ? " from console" : ""), (blocked ? "Blocked read" : ""));
#endif
	language = be->language;	/* 'S' for SQL, 'D' from debugger */
	m = be->mvc;
	m->errstr[0] = 0;
	/*
	 * Continue processing any left-over input from the previous round.
	 */

#ifdef _SQL_READER_DEBUG
	mnstr_printf(GDKout, "#pos %d len %d eof %d \n", in->pos, in->len, in->eof);
#endif
	/*
	 * Distinguish between console reading and mclient connections.
	 * The former comes with readline functionality.
	 */
	while (more) {
		more = FALSE;

		/* Different kinds of supported statements sequences
		   A;   -- single line                  s
		   A \n B;      -- multi line                   S
		   A; B;   -- compound single block     s
		   A;   -- many multi line
		   B \n C; -- statements in one block   S
		 */
		/* auto_commit on end of statement */
		if (m->scanner.mode == LINE_N && !commit_done) {
			go = SQLautocommit(c, m);
			commit_done = TRUE;
		}

		if (go && in->pos >= in->len) {
			ssize_t rd;

			if (c->bak) {
#ifdef _SQL_READER_DEBUG
				mnstr_printf(GDKout, "#Switch to backup stream\n");
#endif
				in = c->fdin;
				blocked = isa_block_stream(in->s);
				m->scanner.rs = c->fdin;
				c->fdin->pos += c->yycur;
				c->yycur = 0;
			}
			if (in->eof || !blocked) {
				language = (be->console) ? 'S' : 0;

				/* The rules of auto_commit require us to finish
				   and start a transaction on the start of a new statement (s A;B; case) */
				if (!(m->emod & mod_debug) && !commit_done) {
					go = SQLautocommit(c, m);
					commit_done = TRUE;
				}

				if (go && ((!blocked && mnstr_write(c->fdout, c->prompt, c->promptlength, 1) != 1) || mnstr_flush(c->fdout))) {
					go = FALSE;
					break;
				}
				in->eof = 0;
			}
			if (in->buf == NULL) {
				more = FALSE;
				go = FALSE;
			} else if (go && (rd = bstream_next(in)) <= 0) {
#ifdef _SQL_READER_DEBUG
				mnstr_printf(GDKout, "#rd %d  language %d eof %d\n", rd, language, in->eof);
#endif
				if (be->language == 'D' && in->eof == 0)
					return 0;

				if (rd == 0 && language !=0 && in->eof && !be->console) {
					/* we hadn't seen the EOF before, so just try again
					   (this time with prompt) */
					more = TRUE;
					continue;
				}
				go = FALSE;
				break;
			} else if (go && !be->console && language == 0) {
				if (in->buf[in->pos] == 's' && !in->eof) {
					while ((rd = bstream_next(in)) > 0)
						;
				}
				be->language = in->buf[in->pos++];
				if (be->language == 's') {
					be->language = 'S';
					m->scanner.mode = LINE_1;
				} else if (be->language == 'S') {
					m->scanner.mode = LINE_N;
				}
			}
#ifdef _SQL_READER_DEBUG
			mnstr_printf(GDKout, "#SQL blk:%s\n", in->buf + in->pos);
#endif
		}
	}
	if ( (c->stimeout && (GDKusec() - c->session) > c->stimeout) || !go || (strncmp(CURRENT(c), "\\q", 2) == 0)) {
		in->pos = in->len;	/* skip rest of the input */
		c->mode = FINISHCLIENT;
		return NULL;
	}
	return 0;
}
Exemplo n.º 13
0
hcell hopc_unspill(hopc_runtime *r, hword_t slot) {
    return CURRENT(r)->arhead->slots[slot];
}
Exemplo n.º 14
0
void hopc_spill(hopc_runtime *r, hword_t slot, hcell data) {
    CURRENT(r)->arhead->slots[slot] = data;
}
Exemplo n.º 15
0
void hopc_pop_activation_record(hopc_runtime *r) {
    hopc_ar *arp = CURRENT(r) ? CURRENT(r)->arhead : 0;
    if( arp ) {
        CURRENT(r)->arhead = arp->next;
    }
}
Exemplo n.º 16
0
Arquivo: main.c Projeto: jmikulka/des
//#define debug(fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#define debug(fmt, ...) ((void)0)

/* Facilities and stores */
struct facility_t fac;

/* Number of sewers in the facility */
static const unsigned int sewers = 10;

static void *foo(void *arg __unused__)
{
	/* actual time */
	double _time = cur_time;

	/* seize the facility */
	debug("< Seize(fac)   PID: %d >", CURRENT());
	Seize(&fac, CURRENT());

	/* after succesfull seize, save time into stats */
	save_time(fac.stats, cur_time - _time);

	/* wait for time */
	debug("< Wait(fac)    PID: %d >", CURRENT());
	Wait(Exponential(1.25));

	/* release the facility */
	debug("< Release(fac) PID: %d >", CURRENT());
	Release(&fac);

	/* terminating the process */
	debug("< Quit()       PID: %d >", CURRENT());