Esempio n. 1
0
tp_obj initClasspyDFMenu(tp_vm *vm)
{
  tp_obj myClass = tp_class(vm);
  tp_set(vm,myClass, tp_string("__init__"), tp_fnc(vm,myCtorpyDFMenu));
  tp_set(vm,myClass, tp_string("__set__"), tp_fnc(vm,zzpy__pyDFMenu_set));
  tp_set(vm,myClass, tp_string("__get__"), tp_fnc(vm,zzpy__pyDFMenu_get));
  tp_set(vm,myClass, tp_string("help"), tp_fnc(vm,zzpy__pyDFMenu_help));
  return myClass;
}
Esempio n. 2
0
tp_obj kolibri_socket_module(TP)
{
    tp_obj socket_mod = tp_dict(tp);

    tp_set(tp, socket_mod, tp_string("AF_INET"), tp_number(AF_INET));
    tp_set(tp, socket_mod, tp_string("SOCK_STREAM"), tp_number(SOCK_STREAM));
    tp_set(tp, socket_mod, tp_string("SOCK_DGRAM"), tp_number(SOCK_DGRAM));
    tp_set(tp, socket_mod, tp_string("inet_pton"), tp_fnc(tp, kolibri_inet_pton));
    tp_set(tp, socket_mod, tp_string("socket"), tp_fnc(tp, kolibri_socket));
    return socket_mod;
}
Esempio n. 3
0
/* Socket listen method.
 * 
 * Example:
 * s.listen('10.10.1.1', 5000)
 */
tp_obj kolibri_listen(TP)
{
    tp_obj self = TP_TYPE(TP_DICT);
    tp_obj remote_addr_obj = TP_OBJ();
    __u32  remote_addr;
    __u32  remote_port = (__u32)TP_TYPE(TP_NUMBER).number.val;
    __u32  local_port  = tp_get(tp, self, tp_string("local_port")).number.val;
    __u32  socktype = (__u32)tp_get(tp, self, tp_string("type")).number.val;
    int  s = -1; /* Socket descriptor */

    if (socktype != SOCK_STREAM)
        tp_raise(tp_None, "IOError: attempt to listen on non-TCP socket", tp_None);

    if (remote_addr_obj.type == TP_NUMBER)
        remote_addr = remote_addr_obj.number.val;
    else if (remote_addr_obj.type == TP_STRING)
        inet_pton(tp, (const char *)remote_addr_obj.string.val, remote_addr_obj.string.len, &remote_addr);

    if ((s = __menuet__open_TCP_socket(local_port, remote_port, remote_addr, 0)) >= 0)
    {
        tp_set(tp, self, tp_string("socket"), tp_number(s));
        return tp_True;
    }
    else
        return tp_False;
}
Esempio n. 4
0
/* Socket connect method.
 *
 * Example:
 * s.connect('10.10.1.1', 7000) #Connects to 10.10.1.1:7000
 */
tp_obj kolibri_connect(TP)
{
    tp_obj self = TP_TYPE(TP_DICT);
    tp_obj  remote_addr_obj = TP_OBJ();
    __u32  remote_addr;
    __u32  remote_port = (__u32)TP_TYPE(TP_NUMBER).number.val;
    __u32  local_port  = tp_get(tp, self, tp_string("local_port")).number.val;
    __u32  socktype = (__u32)tp_get(tp, self, tp_string("type")).number.val;
    int  s = -1; /* Socket descriptor */


    if (remote_addr_obj.type == TP_NUMBER)
        remote_addr = remote_addr_obj.number.val;
    else if (remote_addr_obj.type == TP_STRING)
        inet_pton(tp, (const char *)remote_addr_obj.string.val, remote_addr_obj.string.len, &remote_addr);

    if (socktype == SOCK_STREAM)
        s = __menuet__open_TCP_socket(local_port, remote_port, remote_addr, 1);
    else if (socktype == SOCK_DGRAM)
        s = __menuet__open_UDP_socket(local_port, remote_port, remote_addr);
    if (s >= 0)
    {
        tp_set(tp, self, tp_string("socket"), tp_number(s));
        return tp_True;
    }
    else
        return tp_False;
}
Esempio n. 5
0
/* Socket bind method.
 *
 * In KolibriOS it just sets local address and port.
 *
 * Example:
 * s.bind('10.10.1.2', 6000) #Connects to 10.10.1.2:6000
 */
tp_obj kolibri_bind(TP)
{
    tp_obj self = TP_TYPE(TP_DICT);
    tp_obj local_addr_obj = TP_OBJ();
    __u32  local_port = (__u32)TP_TYPE(TP_NUMBER).number.val;
    __u32  local_addr;

    if (local_addr_obj.type == TP_NUMBER)
        local_addr = local_addr_obj.number.val;
    else if (local_addr_obj.type == TP_STRING)
        inet_pton(tp, (const char *)local_addr_obj.string.val, local_addr_obj.string.len, &local_addr);

    tp_set(tp, self, tp_string("local_addr"), tp_number(local_addr));
    tp_set(tp, self, tp_string("local_port"), tp_number(local_port));
    return tp_None;
}
Esempio n. 6
0
// Ctor (str)
static tp_obj myCtorpyDFMenu(tp_vm *vm)
{
  tp_obj self = tp_getraw(vm);
  TinyParams pm(vm);
  const char *p0 = pm.asString();
  ADM_scriptDFMenuHelper *me = new ADM_scriptDFMenuHelper(p0);
  tp_obj cdata = tp_data(vm, ADM_PYID_DF_INTEGER, me);
  cdata.data.info->xfree = myDtorpyDFMenu;
  tp_set(vm, self, tp_string("cdata"), cdata);
  return tp_None;
}
Esempio n. 7
0
/* Exported function.
 *
 * Example:
 *
 * s = socket(socket.AF_INET, socket.SOCK_DGRAM)
 *
 * Returns socket object.
 */
tp_obj kolibri_socket(TP)
{
    tp_obj s;
    tp_obj sockfamily = TP_TYPE(TP_NUMBER);
    tp_obj socktype = TP_TYPE(TP_NUMBER);

    if (fabs(sockfamily.number.val - AF_INET) > PRECISION ||
        (fabs(socktype.number.val - SOCK_STREAM) > PRECISION &&
         fabs(socktype.number.val - SOCK_DGRAM) > PRECISION))
        return tp_None;
    s = tp_dict(tp);
    tp_set(tp, s, tp_string("family"), sockfamily);
    tp_set(tp, s, tp_string("type"), socktype);
    tp_set(tp, s, tp_string("bind"), tp_method(tp, s, kolibri_bind));
    tp_set(tp, s, tp_string("connect"), tp_method(tp, s, kolibri_connect));
    tp_set(tp, s, tp_string("send"), tp_method(tp, s, kolibri_send));
    tp_set(tp, s, tp_string("recv"), tp_method(tp, s, kolibri_recv));
    tp_set(tp, s, tp_string("close"), tp_method(tp, s, kolibri_close_socket));
    if (fabs(socktype.number.val - SOCK_STREAM) < PRECISION)
        tp_set(tp, s, tp_string("listen"), tp_method(tp, s, kolibri_listen));
    return s;
}
Esempio n. 8
0
File: init.c Progetto: Saruta/pyr0
void cpuinfo_init(TP)
{
	/* module */
	tp_obj cpuinfo_mod = tp_dict(tp);

	/* methods */
	tp_set(tp, cpuinfo_mod, tp_string("processor"),
	       tp_fnc(tp, cpuinfo_processor));
	tp_set(tp, cpuinfo_mod, tp_string("vendor_id"),
	       tp_fnc(tp, cpuinfo_vendor_id));
	tp_set(tp, cpuinfo_mod, tp_string("cpu_family"),
	       tp_fnc(tp, cpuinfo_cpu_family));
	tp_set(tp, cpuinfo_mod, tp_string("model"),
	       tp_fnc(tp, cpuinfo_model));
	tp_set(tp, cpuinfo_mod, tp_string("model_name"),
	       tp_fnc(tp, cpuinfo_model_name));
	tp_set(tp, cpuinfo_mod, tp_string("stepping"),
	       tp_fnc(tp, cpuinfo_stepping));
	tp_set(tp, cpuinfo_mod, tp_string("flags"),
	       tp_fnc(tp, cpuinfo_flags));
	tp_set(tp, cpuinfo_mod, tp_string("cpuinfo"),
	       tp_fnc(tp, cpuinfo_cpuinfo));

	/* special attributes */
	tp_set(tp, cpuinfo_mod, tp_string("__doc__"),
	       tp_string(help));
	tp_set(tp, cpuinfo_mod, tp_string("__name__"), tp_string("cpuinfo"));
	tp_set(tp, cpuinfo_mod, tp_string("__file__"), tp_string(__FILE__));

	/* bind */
	tp_set(tp, tp->modules, tp_string("cpuinfo"), cpuinfo_mod);
}
Esempio n. 9
0
tp_vm *_tp_init(void) {
    int i;
    tp_vm *tp = (tp_vm*)calloc(sizeof(tp_vm),1);
    tp->time_limit = TP_NO_LIMIT;
    tp->clocks = clock();
    tp->time_elapsed = 0.0;
    tp->mem_limit = TP_NO_LIMIT;
    tp->mem_exceeded = 0;
    tp->mem_used = sizeof(tp_vm);
    tp->cur = 0;
    tp->jmp = 0;
    tp->ex = tp_None;
    tp->root = tp_list_nt(tp);
    for (i=0; i<256; i++) { tp->chars[i][0]=i; }
    tp_gc_init(tp);
    tp->_regs = tp_list(tp);
    for (i=0; i<TP_REGS; i++) { tp_set(tp,tp->_regs,tp_None,tp_None); }
    tp->builtins = tp_dict(tp);
    tp->modules = tp_dict(tp);
    tp->_params = tp_list(tp);
    for (i=0; i<TP_FRAMES; i++) { tp_set(tp,tp->_params,tp_None,tp_list(tp)); }
    tp_set(tp,tp->root,tp_None,tp->builtins);
    tp_set(tp,tp->root,tp_None,tp->modules);
    tp_set(tp,tp->root,tp_None,tp->_regs);
    tp_set(tp,tp->root,tp_None,tp->_params);
    tp_set(tp,tp->builtins,tp_string("MODULES"),tp->modules);
    tp_set(tp,tp->modules,tp_string("BUILTINS"),tp->builtins);
    tp_set(tp,tp->builtins,tp_string("BUILTINS"),tp->builtins);
    tp_obj sys = tp_dict(tp);
    tp_set(tp, sys, tp_string("version"), tp_string("tinypy 1.2+SVN"));
    tp_set(tp,tp->modules, tp_string("sys"), sys);
    tp->regs = tp->_regs.list.val->items;
    tp_full(tp);
    return tp;
}
Esempio n. 10
0
/*
 * init math module, namely, set its dictionary
 */
void math_init(TP)
{
    /*
     * new a module dict for math
     */
    tp_obj math_mod = tp_dict(tp);

    /*
     * initialize pi and e
     */
    math_pi = tp_number(M_PI);
    math_e  = tp_number(M_E);

    /*
     * bind math functions to math module
     */
    tp_set(tp, math_mod, tp_string("pi"), math_pi);
    tp_set(tp, math_mod, tp_string("e"), math_e);
    tp_set(tp, math_mod, tp_string("acos"), tp_fnc(tp, math_acos));
    tp_set(tp, math_mod, tp_string("asin"), tp_fnc(tp, math_asin));
    tp_set(tp, math_mod, tp_string("atan"), tp_fnc(tp, math_atan));
    tp_set(tp, math_mod, tp_string("atan2"), tp_fnc(tp, math_atan2));
    tp_set(tp, math_mod, tp_string("ceil"), tp_fnc(tp, math_ceil));
    tp_set(tp, math_mod, tp_string("cos"), tp_fnc(tp, math_cos));
    tp_set(tp, math_mod, tp_string("cosh"), tp_fnc(tp, math_cosh));
    tp_set(tp, math_mod, tp_string("degrees"), tp_fnc(tp, math_degrees));
    tp_set(tp, math_mod, tp_string("exp"), tp_fnc(tp, math_exp));
    tp_set(tp, math_mod, tp_string("fabs"), tp_fnc(tp, math_fabs));
    tp_set(tp, math_mod, tp_string("floor"), tp_fnc(tp, math_floor));
    tp_set(tp, math_mod, tp_string("fmod"), tp_fnc(tp, math_fmod));
    tp_set(tp, math_mod, tp_string("frexp"), tp_fnc(tp, math_frexp));
    tp_set(tp, math_mod, tp_string("hypot"), tp_fnc(tp, math_hypot));
    tp_set(tp, math_mod, tp_string("ldexp"), tp_fnc(tp, math_ldexp));
    tp_set(tp, math_mod, tp_string("log"), tp_fnc(tp, math_log));
    tp_set(tp, math_mod, tp_string("log10"), tp_fnc(tp, math_log10));
    tp_set(tp, math_mod, tp_string("modf"), tp_fnc(tp, math_modf));
    tp_set(tp, math_mod, tp_string("pow"), tp_fnc(tp, math_pow));
    tp_set(tp, math_mod, tp_string("radians"), tp_fnc(tp, math_radians));
    tp_set(tp, math_mod, tp_string("sin"), tp_fnc(tp, math_sin));
    tp_set(tp, math_mod, tp_string("sinh"), tp_fnc(tp, math_sinh));
    tp_set(tp, math_mod, tp_string("sqrt"), tp_fnc(tp, math_sqrt));
    tp_set(tp, math_mod, tp_string("tan"), tp_fnc(tp, math_tan));
    tp_set(tp, math_mod, tp_string("tanh"), tp_fnc(tp, math_tanh));

    /*
     * bind special attributes to math module
     */
    tp_set(tp, math_mod, tp_string("__doc__"), 
            tp_string(
                "This module is always available.  It provides access to the\n"
                "mathematical functions defined by the C standard."));
    tp_set(tp, math_mod, tp_string("__name__"), tp_string("math"));
    tp_set(tp, math_mod, tp_string("__file__"), tp_string(__FILE__));

    /*
     * bind to tiny modules[]
     */
    tp_set(tp, tp->modules, tp_string("math"), math_mod);
}