Ejemplo n.º 1
0
void define_test_driver(RefNode *m)
{
    RefNode *n;

    n = define_identifier(m, m, "testfunc", NODE_FUNC_N, 0);
    define_native_func_a(n, lang_testfunc, 0, 0, NULL);
}
Ejemplo n.º 2
0
static void define_io_text_func(RefNode *m)
{
    RefNode *n;

    // 標準出力系
    n = define_identifier(m, m, "gets", NODE_FUNC_N, 0);
    define_native_func_a(n, stdout_gets, 0, 0, (void*)FALSE, NULL);

    n = define_identifier(m, m, "getln", NODE_FUNC_N, 0);
    define_native_func_a(n, stdout_gets, 0, 0, (void*)TRUE, NULL);

    n = define_identifier(m, m, "print", NODE_FUNC_N, 0);
    define_native_func_a(n, stdout_print, 0, -1, (void*)FALSE, NULL);

    n = define_identifier(m, m, "puts", NODE_FUNC_N, 0);
    define_native_func_a(n, stdout_print, 0, -1, (void*)TRUE, NULL);

    n = define_identifier(m, m, "printf", NODE_FUNC_N, 0);
    define_native_func_a(n, stdout_printf, 1, -1, (void*)FALSE, NULL);

    n = define_identifier(m, m, "sprintf", NODE_FUNC_N, 0);
    define_native_func_a(n, textio_printf, 1, -1, (void*)TRUE, NULL);
}
Ejemplo n.º 3
0
void define_lang_map_class(RefNode *m)
{
    RefNode *cls;
    RefNode *n;

    RefStr *empty = intern("empty", -1);
    RefStr *size = intern("size", -1);

    cls_mapiter = define_identifier(m, m, "MapIter", NODE_CLASS, 0);
    fv->cls_entry = define_identifier(m, m, "Entry", NODE_CLASS, 0);


    // Map
    cls = fs->cls_map;
    n = define_identifier_p(m, cls, fs->str_new, NODE_NEW_N, 0);
    define_native_func_a(n, map_new_elems, 0, -1, NULL);
    fv->func_map_new = n;
    n = define_identifier_p(m, cls, fs->str_marshal_read, NODE_NEW_N, 0);
    define_native_func_a(n, map_marshal_read, 1, 1, (void*) TRUE, fs->cls_marshaldumper);

    n = define_identifier_p(m, cls, fs->str_dtor, NODE_FUNC_N, 0);
    define_native_func_a(n, map_dispose, 0, 0, NULL);

    n = define_identifier_p(m, cls, fs->str_marshal_write, NODE_FUNC_N, 0);
    define_native_func_a(n, map_marshal_write, 1, 1, (void*) TRUE, fs->cls_marshaldumper);
    n = define_identifier_p(m, cls, fs->str_tostr, NODE_FUNC_N, 0);
    define_native_func_a(n, col_tostr, 0, 2, NULL, fs->cls_str, fs->cls_locale);
    n = define_identifier_p(m, cls, fs->str_hash, NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, col_hash, 0, 0, NULL);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_EQ], NODE_FUNC_N, 0);
    define_native_func_a(n, col_eq, 1, 1, NULL, fs->cls_map);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_LB], NODE_FUNC_N, 0);
    define_native_func_a(n, map_index, 1, 1, NULL, NULL);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_LET_B], NODE_FUNC_N, 0);
    define_native_func_a(n, map_index_set, 2, 2, NULL, NULL, NULL);
    n = define_identifier_p(m, cls, fs->str_missing, NODE_FUNC_N, 0);
    define_native_func_a(n, map_index, 1, 1, NULL, NULL);
    n = define_identifier_p(m, cls, fs->str_missing_set, NODE_FUNC_N, 0);
    define_native_func_a(n, map_index_set, 2, 2, NULL, NULL, NULL);
    n = define_identifier(m, cls, "get", NODE_FUNC_N, 0);
    define_native_func_a(n, map_get, 1, 2, NULL, NULL, NULL);
    n = define_identifier_p(m, cls, empty, NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, map_empty, 0, 0, NULL);
    n = define_identifier_p(m, cls, size, NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, map_size, 0, 0, NULL);
    n = define_identifier_p(m, cls, fs->str_iterator, NODE_FUNC_N, 0);
    define_native_func_a(n, map_iterator, 0, 0, (void*)ITERATOR_BOTH);
    n = define_identifier(m, cls, "dup", NODE_FUNC_N, 0);
    define_native_func_a(n, map_dup, 0, 0, fs->cls_map);
    n = define_identifier(m, cls, "entries", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, map_iterator, 0, 0, (void*) ITERATOR_BOTH);
    n = define_identifier(m, cls, "keys", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, map_iterator, 0, 0, (void*) ITERATOR_KEY);
    n = define_identifier(m, cls, "values", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, map_iterator, 0, 0, (void*) ITERATOR_VAL);
    n = define_identifier(m, cls, "has_key", NODE_FUNC_N, 0);
    define_native_func_a(n, map_has_key, 1, 1, NULL, NULL);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_IN], NODE_FUNC_N, 0);
    define_native_func_a(n, map_has_key, 1, 1, NULL, NULL);
    n = define_identifier(m, cls, "index_of", NODE_FUNC_N, 0);
    define_native_func_a(n, map_index_of, 1, 1, (void*) TRUE, NULL);
    n = define_identifier(m, cls, "has_value", NODE_FUNC_N, 0);
    define_native_func_a(n, map_index_of, 1, 1, (void*) FALSE, NULL);
    n = define_identifier(m, cls, "add", NODE_FUNC_N, 0);
    define_native_func_a(n, map_add_entry, 1, 1, NULL, fv->cls_entry);
    n = define_identifier(m, cls, "delete", NODE_FUNC_N, 0);
    define_native_func_a(n, map_delete, 1, 1, NULL, NULL);
    n = define_identifier(m, cls, "clear", NODE_FUNC_N, 0);
    define_native_func_a(n, map_clear, 0, 0, NULL, NULL);
    extends_method(cls, fs->cls_iterable);

    // MapIter
    cls = cls_mapiter;
    cls->u.c.n_memb = INDEX_MAPITER_NUM;
    n = define_identifier_p(m, cls, fs->str_dtor, NODE_FUNC_N, 0);
    define_native_func_a(n, mapiter_dispose, 0, 0, NULL);
    n = define_identifier_p(m, cls, fs->str_next, NODE_FUNC_N, 0);
    define_native_func_a(n, mapiter_next, 0, 0, NULL);
    extends_method(cls, fs->cls_iterator);


    // Entry
    cls = fv->cls_entry;
    n = define_identifier_p(m, cls, fs->str_new, NODE_NEW_N, 0);
    define_native_func_a(n, mapentry_new, 2, 2, NULL, NULL, NULL);

    n = define_identifier_p(m, cls, fs->str_tostr, NODE_FUNC_N, 0);
    define_native_func_a(n, mapentry_tostr, 0, 2, NULL, fs->cls_str, fs->cls_locale);
    n = define_identifier_p(m, cls, fs->str_hash, NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, pairvalue_hash, 0, 0, NULL);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_EQ], NODE_FUNC_N, 0);
    define_native_func_a(n, pairvalue_eq, 1, 1, NULL, fv->cls_entry);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_CMP], NODE_FUNC_N, 0);
    define_native_func_a(n, mapentry_cmp, 1, 1, NULL, fv->cls_entry);
    n = define_identifier(m, cls, "key", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, native_get_member, 0, 0, (void*) INDEX_ENTRY_KEY);
    n = define_identifier(m, cls, "value", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, native_get_member, 0, 0, (void*) INDEX_ENTRY_VAL);

    cls->u.c.n_memb = INDEX_ENTRY_NUM;
    extends_method(cls, fs->cls_obj);

    // Set
    // Mapのkeyのみ使う
    cls = fs->cls_set;
    n = define_identifier_p(m, cls, fs->str_new, NODE_NEW_N, 0);
    define_native_func_a(n, set_new_elems, 0, -1, NULL);
    n = define_identifier_p(m, cls, fs->str_marshal_read, NODE_NEW_N, 0);
    define_native_func_a(n, map_marshal_read, 1, 1, (void*) FALSE, fs->cls_marshaldumper);

    n = define_identifier_p(m, cls, fs->str_dtor, NODE_FUNC_N, 0);
    define_native_func_a(n, map_dispose, 0, 0, NULL);

    n = define_identifier_p(m, cls, fs->str_tostr, NODE_FUNC_N, 0);
    define_native_func_a(n, col_tostr, 0, 2, NULL, fs->cls_str, fs->cls_locale);
    n = define_identifier_p(m, cls, fs->str_marshal_write, NODE_FUNC_N, 0);
    define_native_func_a(n, map_marshal_write, 1, 1, (void*) FALSE, fs->cls_marshaldumper);
    n = define_identifier_p(m, cls, fs->str_hash, NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, col_hash, 0, 0, NULL);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_EQ], NODE_FUNC_N, 0);
    define_native_func_a(n, col_eq, 1, 1, NULL, fs->cls_set);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_AND], NODE_FUNC_N, 0);
    define_native_func_a(n, set_and, 1, 1, NULL, fs->cls_set);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_OR], NODE_FUNC_N, 0);
    define_native_func_a(n, set_or, 1, 1, NULL, fs->cls_set);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_XOR], NODE_FUNC_N, 0);
    define_native_func_a(n, set_xor, 1, 1, NULL, fs->cls_set);
    n = define_identifier_p(m, cls, empty, NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, map_empty, 0, 0, NULL);
    n = define_identifier_p(m, cls, size, NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, map_size, 0, 0, NULL);
    n = define_identifier_p(m, cls, fs->str_iterator, NODE_FUNC_N, 0);
    define_native_func_a(n, map_iterator, 0, 0, (void*) ITERATOR_KEY);
    n = define_identifier(m, cls, "dup", NODE_FUNC_N, 0);
    define_native_func_a(n, map_dup, 0, 0, cls);
    n = define_identifier(m, cls, "has", NODE_FUNC_N, 0);
    define_native_func_a(n, map_has_key, 1, 1, NULL, NULL);
    n = define_identifier_p(m, cls, fs->symbol_stock[T_IN], NODE_FUNC_N, 0);
    define_native_func_a(n, map_has_key, 1, 1, NULL, NULL);
    n = define_identifier(m, cls, "add", NODE_FUNC_N, 0);
    define_native_func_a(n, set_add_value, 1, -1, NULL, NULL);
    n = define_identifier(m, cls, "delete", NODE_FUNC_N, 0);
    define_native_func_a(n, map_delete, 1, 1, NULL, NULL);
    n = define_identifier(m, cls, "clear", NODE_FUNC_N, 0);
    define_native_func_a(n, map_clear, 0, 0, NULL, NULL);
    extends_method(cls, fs->cls_iterable);
}
Ejemplo n.º 4
0
static void define_io_text_class(RefNode *m)
{
    RefNode *cls;
    RefNode *n;


    // TextIO
    // 文字入出力、文字コード変換
    cls = fs->cls_textio;
    cls->u.c.n_memb = INDEX_TEXTIO_NUM;
    n = define_identifier_p(m, cls, fs->str_new, NODE_NEW_N, 0);
    define_native_func_a(n, textio_new, 2, 4, NULL, fs->cls_streamio, fs->cls_charset, fs->cls_bool, fs->cls_str);

    n = define_identifier_p(m, cls, fs->str_dispose, NODE_FUNC_N, 0);
    define_native_func_a(n, textio_close, 0, 0, NULL);

    n = define_identifier(m, cls, "gets", NODE_FUNC_N, 0);
    define_native_func_a(n, textio_gets, 0, 0, (void*)FALSE);
    n = define_identifier(m, cls, "getln", NODE_FUNC_N, 0);
    define_native_func_a(n, textio_gets, 0, 0, (void*)TRUE);
    n = define_identifier(m, cls, "next", NODE_FUNC_N, 0);
    define_native_func_a(n, textio_next, 0, 0, NULL);
    n = define_identifier(m, cls, "print", NODE_FUNC_N, 0);
    define_native_func_a(n, textio_print, 0, -1, (void*) FALSE);
    n = define_identifier(m, cls, "puts", NODE_FUNC_N, 0);
    define_native_func_a(n, textio_print, 0, -1, (void*) TRUE);
    n = define_identifier(m, cls, "printf", NODE_FUNC_N, 0);
    define_native_func_a(n, textio_printf, 1, -1, (void*)FALSE, NULL);
    n = define_identifier(m, cls, "flush", NODE_FUNC_N, 0);
    define_native_func_a(n, textio_flush, 0, 0, NULL);
    n = define_identifier(m, cls, "charset", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, textio_charset, 0, 0, NULL);
    n = define_identifier(m, cls, "translit", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, textio_translit, 0, 0, NULL);
    extends_method(cls, fs->cls_iterator);


    // StrIO
    cls = fv->cls_strio;
    cls->u.c.n_memb = INDEX_TEXTIO_NUM;
    n = define_identifier_p(m, cls, fs->str_new, NODE_NEW_N, 0);
    define_native_func_a(n, strio_new, 0, 1, NULL, fs->cls_str);

    n = define_identifier_p(m, cls, fs->str_tostr, NODE_FUNC_N, 0);
    define_native_func_a(n, strio_tostr, 0, 2, NULL, fs->cls_str, fs->cls_locale);
    n = define_identifier(m, cls, "empty", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, strio_empty, 0, 0, NULL);

    n = define_identifier_p(m, cls, fs->symbol_stock[T_LB], NODE_FUNC_N, 0);
    define_native_func_a(n, strio_index, 1, 1, NULL, fs->cls_int);
    n = define_identifier(m, cls, "size", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, strio_size, 0, 0, NULL);
    n = define_identifier(m, cls, "dup", NODE_FUNC_N, 0);
    define_native_func_a(n, strio_dup, 0, 0, NULL);
    n = define_identifier(m, cls, "data", NODE_FUNC_N, NODEOPT_PROPERTY);
    define_native_func_a(n, strio_data, 0, 0, NULL);
    n = define_identifier(m, cls, "sub", NODE_FUNC_N, 0);
    define_native_func_a(n, strio_data, 1, 2, NULL, fs->cls_int, fs->cls_int);
    n = define_identifier(m, cls, "flush", NODE_FUNC_N, 0);
    define_native_func_a(n, native_return_null, 0, 0, NULL); // 何もしない
    extends_method(cls, fs->cls_textio);
}