Пример #1
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;
}
Пример #2
0
Файл: init.c Проект: 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);
}
Пример #3
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);
}
Пример #4
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;
}
Пример #5
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;
}
Пример #6
0
/* Function: tp_class
 * Creates a new base class.
 *
 * Parameters:
 * none
 *
 * Returns:
 * A new, empty class (derived from tinypy's builtin "object" class).
 */
tp_obj tp_class(TP) {
    tp_obj klass = tp_dict(tp);
    klass.dict.val->meta = tp_get(tp,tp->builtins,tp_string("object")); 
    return klass;
}
Пример #7
0
/* Function: tp_object
 * Creates a new object.
 *
 * Returns:
 * The newly created object. The object initially has no parent class, use
 * <tp_setmeta> to set a class. Also see <tp_object_new>.
 */
tp_obj tp_object(TP) {
    tp_obj self = tp_dict(tp);
    self.dict.dtype = 2;
    return self;
}