シェルスクリプト言語xyzshのソースコード。
Révision | 5503b30d3381b9831ffbc9792e9591e23444e5ea (tree) |
---|---|
l'heure | 2012-10-26 18:06:01 |
Auteur | ab25q <ab25cq@gmai...> |
Commiter | ab25q |
v1.1.1 relese
@@ -1,4 +1,12 @@ | ||
1 | 1 | |
2 | +2012 18th Octorber version 1.1.1 | |
3 | + | |
4 | + add "defined" inner command. see help | |
5 | + | |
6 | + add "kanjicode" inner command. see help | |
7 | + | |
8 | + fixed help bug | |
9 | + | |
2 | 10 | 2012 18th Octorber version 1.1.0 |
3 | 11 | |
4 | 12 | fixed break in while loop bug |
@@ -1,4 +1,4 @@ | ||
1 | -Copyright (c) 2012 Yamanaka Gorou | |
1 | +Copyright (c) 2012 ab25cq | |
2 | 2 | |
3 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy |
4 | 4 | of this software and associated documentation files (the "Software"), to deal |
@@ -1,4 +1,6 @@ | ||
1 | 1 | +++ 入れたい機能 +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | +run_functionなど_stackframeのところがおかしい | |
3 | + | |
2 | 4 | リファレンスの引数 |
3 | 5 | |
4 | 6 | オブジェクトの絶対パス |
@@ -16,6 +18,8 @@ glob 内部コマンド | ||
16 | 18 | |
17 | 19 | $$() $でオプションの内容が入っていたら、オプションとして使う |
18 | 20 | |
21 | +エラーメッセージが分かりにくい | |
22 | + | |
19 | 23 | +++ 機能のバグ +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | 24 | エラー出力のリダイレクト |
21 | 25 |
@@ -44,6 +44,10 @@ completion sweep ( | ||
44 | 44 | hash COMPLETION_OPTIONS -key sweep |
45 | 45 | ) |
46 | 46 | |
47 | +completion defined ( | |
48 | + self | egrep -v external\ program\$ | egrep -v native\ function\$ | egrep -v '^root:|^self:|^parent:|^run:'| root::scan '(^.+?):' | |
49 | +) | |
50 | + | |
47 | 51 | completion var ( |
48 | 52 | self | egrep ': var$' | root::scan '(^.+?):' |
49 | 53 | hash COMPLETION_OPTIONS -key var |
@@ -3042,7 +3042,7 @@ fi | ||
3042 | 3042 | ##################################################################### |
3043 | 3043 | # check operating systems |
3044 | 3044 | ##################################################################### |
3045 | -SO_VERSION=1.4.5 | |
3045 | +SO_VERSION=1.5.0 | |
3046 | 3046 | |
3047 | 3047 | { $as_echo "$as_me:${as_lineno-$LINENO}: checking Operating System" >&5 |
3048 | 3048 | $as_echo_n "checking Operating System... " >&6; } |
@@ -3205,7 +3205,7 @@ CFLAGS="-DSYSCONFDIR=\"\\\"$sysconfdir/xyzsh/\\\"\" -DDATAROOTDIR=\"\\\"$dataroo | ||
3205 | 3205 | |
3206 | 3206 | |
3207 | 3207 | |
3208 | -OBJ="src/gc.o src/stack.o src/string.o src/list.o src/kanji.o src/debug.o src/hash.o src/vector.o src/block.o src/fun.o src/class.o src/completion.o src/xyzsh.o src/parser.o src/run.o src/readline.o src/curses.o src/cmd_base.o src/cmd_obj.o src/cmd_file.o src/cmd_str.o src/cmd_ary.o src/cmd_condition.o src/interface.o src/memchecker.o src/object.o src/cmd_num.o src/cmd_curses.o" | |
3208 | +OBJ="src/gc.o src/stack.o src/string.o src/list.o src/kanji.o src/debug.o src/hash.o src/vector.o src/block.o src/fun.o src/class.o src/completion.o src/xyzsh.o src/parser.o src/run.o src/readline.o src/curses.o src/cmd_base.o src/cmd_obj.o src/cmd_file.o src/cmd_str.o src/cmd_ary.o src/cmd_condition.o src/interface.o src/memchecker.o src/object.o src/uobject.o src/cmd_num.o src/cmd_curses.o" | |
3209 | 3209 | |
3210 | 3210 | ##################################################################### |
3211 | 3211 | # ncurses settings |
@@ -189,7 +189,7 @@ CFLAGS="-DSYSCONFDIR=\"\\\"$sysconfdir/xyzsh/\\\"\" -DDATAROOTDIR=\"\\\"$dataroo | ||
189 | 189 | |
190 | 190 | AC_SUBST(CFLAGS) |
191 | 191 | |
192 | -OBJ="src/gc.o src/stack.o src/string.o src/list.o src/kanji.o src/debug.o src/hash.o src/vector.o src/block.o src/fun.o src/class.o src/completion.o src/xyzsh.o src/parser.o src/run.o src/readline.o src/curses.o src/cmd_base.o src/cmd_obj.o src/cmd_file.o src/cmd_str.o src/cmd_ary.o src/cmd_condition.o src/interface.o src/memchecker.o src/object.o src/cmd_num.o src/cmd_curses.o" | |
192 | +OBJ="src/gc.o src/stack.o src/string.o src/list.o src/kanji.o src/debug.o src/hash.o src/vector.o src/block.o src/fun.o src/class.o src/completion.o src/xyzsh.o src/parser.o src/run.o src/readline.o src/curses.o src/cmd_base.o src/cmd_obj.o src/cmd_file.o src/cmd_str.o src/cmd_ary.o src/cmd_condition.o src/interface.o src/memchecker.o src/object.o src/uobject.o src/cmd_num.o src/cmd_curses.o" | |
193 | 193 | |
194 | 194 | ##################################################################### |
195 | 195 | # ncurses settings |
@@ -2,16 +2,16 @@ class Help ( | ||
2 | 2 | def set_helps_ja ( |
3 | 3 | | chomp | split -multi-line -La \n-\n | each -La -number 2 ( |
4 | 4 | | lines -La 0 ( |
5 | - | chomp | split | lines 0 (|print) | var -local cmd_name | |
6 | - | chomp | var -local cmdline | |
5 | + | chomp | split | lines 0 (|print) | var -local CMD_NAME | |
6 | + | chomp | var -local CMDLINE | |
7 | 7 | ) 1 ( |
8 | - | chomp | ary -local explain | |
8 | + | chomp | ary -local EXPLAIN | |
9 | 9 | ) |
10 | 10 | |
11 | - var cmd_name | chomp | |
11 | + var CMD_NAME | chomp | |
12 | 12 | print \a |
13 | - var cmdline | add \n | |
14 | - ary explain | chomp | |
13 | + var CMDLINE | add \n | |
14 | + ary EXPLAIN | chomp | |
15 | 15 | print \a |
16 | 16 | ) | hash -La HELPS.ja |
17 | 17 | ) |
@@ -19,16 +19,16 @@ class Help ( | ||
19 | 19 | def set_helps ( |
20 | 20 | | chomp | split -multi-line -La \n-\n | each -La -number 2 ( |
21 | 21 | | lines -La 0 ( |
22 | - | chomp | split | lines 0 (|print) | var -local cmd_name | |
23 | - | chomp | var -local cmdline | |
22 | + | chomp | split | lines 0 (|print) | var -local CMD_NAME | |
23 | + | chomp | var -local CMDLINE | |
24 | 24 | ) 1 ( |
25 | - | chomp | ary -local explain | |
25 | + | chomp | ary -local EXPLAIN | |
26 | 26 | ) |
27 | 27 | |
28 | - var cmd_name | chomp | |
28 | + var CMD_NAME | chomp | |
29 | 29 | print \a |
30 | - var cmdline | add \n | |
31 | - ary explain | chomp | |
30 | + var CMDLINE | add \n | |
31 | + ary EXPLAIN | chomp | |
32 | 32 | print \a |
33 | 33 | ) | hash -La HELPS |
34 | 34 | ) |
@@ -71,6 +71,19 @@ class Help ( | ||
71 | 71 | object help ( Help ) |
72 | 72 | |
73 | 73 | print <<<'EOS' |
74 | +defined オブジェクト | |
75 | +- | |
76 | +オブジェクトが定義されていたら真を返す | |
77 | +- | |
78 | +kanjicode | |
79 | +- | |
80 | +現在の漢字コードを表示する。 | |
81 | + | |
82 | +-byte バイトに設定する | |
83 | +-sjis sjisに設定する | |
84 | +-eucjp eucjpに設定する | |
85 | +-utf8 utf8に設定する | |
86 | +- | |
74 | 87 | funinfo |
75 | 88 | - |
76 | 89 | 実行中の関数もしくはクラスの情報を得る |
@@ -913,6 +926,19 @@ EOS | help::set_helps_ja | ||
913 | 926 | ### English Help ################################################## |
914 | 927 | |
915 | 928 | print <<<'EOS' |
929 | +defined (object name) | |
930 | +- | |
931 | +if object is defined, return true | |
932 | +- | |
933 | +kanjicode | |
934 | +- | |
935 | +show language setting | |
936 | + | |
937 | +-byte change language setting to byte | |
938 | +-sjis change language setting to SJIS(for Japanese) | |
939 | +-eucjp change language setting to EUCJP(for Japanese) | |
940 | +-utf8 change language setting to UTF8 | |
941 | +- | |
916 | 942 | funinfo |
917 | 943 | - |
918 | 944 | output running function or class information. |
@@ -270,8 +270,8 @@ static void sCommand_copy_deeply(sCommand* dest, sCommand* src) | ||
270 | 270 | } |
271 | 271 | dest->mArgsRuntime[i] = NULL; |
272 | 272 | */ |
273 | - dest->mArgsRuntime = MALLOC(sizeof(char*)*8); | |
274 | - dest->mArgsSizeRuntime = 8; | |
273 | + dest->mArgsRuntime = MALLOC(sizeof(char*)*3); | |
274 | + dest->mArgsSizeRuntime = 3; | |
275 | 275 | dest->mArgsNumRuntime = 0; |
276 | 276 | |
277 | 277 | dest->mBlocks = MALLOC(sizeof(sObject*)*src->mBlocksSize); |
@@ -308,6 +308,8 @@ static void sCommand_copy_deeply(sCommand* dest, sCommand* src) | ||
308 | 308 | } |
309 | 309 | dest->mMessagesNum = src->mMessagesNum; |
310 | 310 | } |
311 | + | |
312 | + dest->mRedirectsFileNamesRuntime = NULL; | |
311 | 313 | } |
312 | 314 | |
313 | 315 | static void sCommand_copy_deeply_stack(sCommand* dest, sCommand* src) |
@@ -355,8 +357,8 @@ static void sCommand_copy_deeply_stack(sCommand* dest, sCommand* src) | ||
355 | 357 | } |
356 | 358 | dest->mArgsRuntime[i] = NULL; |
357 | 359 | */ |
358 | - dest->mArgsRuntime = MALLOC(sizeof(char*)*8); | |
359 | - dest->mArgsSizeRuntime = 8; | |
360 | + dest->mArgsRuntime = MALLOC(sizeof(char*)*3); | |
361 | + dest->mArgsSizeRuntime = 3; | |
360 | 362 | dest->mArgsNumRuntime = 0; |
361 | 363 | |
362 | 364 | dest->mBlocks = MALLOC(sizeof(sObject*)*src->mBlocksSize); |
@@ -394,6 +396,8 @@ static void sCommand_copy_deeply_stack(sCommand* dest, sCommand* src) | ||
394 | 396 | } |
395 | 397 | dest->mMessagesNum = src->mMessagesNum; |
396 | 398 | } |
399 | + | |
400 | + dest->mRedirectsFileNamesRuntime = NULL; | |
397 | 401 | } |
398 | 402 | |
399 | 403 | static void sCommand_copy_deeply_malloc(sCommand* dest, sCommand* src) |
@@ -441,8 +445,8 @@ static void sCommand_copy_deeply_malloc(sCommand* dest, sCommand* src) | ||
441 | 445 | } |
442 | 446 | dest->mArgsRuntime[i] = NULL; |
443 | 447 | */ |
444 | - dest->mArgsRuntime = MALLOC(sizeof(char*)*8); | |
445 | - dest->mArgsSizeRuntime = 8; | |
448 | + dest->mArgsRuntime = MALLOC(sizeof(char*)*3); | |
449 | + dest->mArgsSizeRuntime = 3; | |
446 | 450 | dest->mArgsNumRuntime = 0; |
447 | 451 | |
448 | 452 | dest->mBlocks = MALLOC(sizeof(sObject*)*src->mBlocksSize); |
@@ -480,6 +484,8 @@ static void sCommand_copy_deeply_malloc(sCommand* dest, sCommand* src) | ||
480 | 484 | } |
481 | 485 | dest->mMessagesNum = src->mMessagesNum; |
482 | 486 | } |
487 | + | |
488 | + dest->mRedirectsFileNamesRuntime = NULL; | |
483 | 489 | } |
484 | 490 | |
485 | 491 | void sCommand_delete(sCommand* self) |
@@ -513,10 +519,13 @@ void sCommand_delete(sCommand* self) | ||
513 | 519 | |
514 | 520 | if(self->mBlocks) FREE(self->mBlocks); |
515 | 521 | |
516 | - for(i=0; i<self->mRedirectsNum; i++) { | |
517 | - FREE(self->mRedirectsFileNames[i]); | |
522 | + if(self->mRedirectsFileNames) { | |
523 | + for(i=0; i<self->mRedirectsNum; i++) { | |
524 | + FREE(self->mRedirectsFileNames[i]); | |
525 | + } | |
526 | + FREE(self->mRedirectsFileNames); | |
518 | 527 | } |
519 | - if(self->mRedirectsFileNames) FREE(self->mRedirectsFileNames); | |
528 | + | |
520 | 529 | if(self->mRedirects) FREE(self->mRedirects); |
521 | 530 | |
522 | 531 | if(self->mRedirectsFileNamesRuntime) { |
@@ -564,10 +573,12 @@ void sCommand_delete_malloc(sCommand* self) | ||
564 | 573 | } |
565 | 574 | if(self->mBlocks) FREE(self->mBlocks); |
566 | 575 | |
567 | - for(i=0; i<self->mRedirectsNum; i++) { | |
568 | - FREE(self->mRedirectsFileNames[i]); | |
576 | + if(self->mRedirectsFileNames) { | |
577 | + for(i=0; i<self->mRedirectsNum; i++) { | |
578 | + FREE(self->mRedirectsFileNames[i]); | |
579 | + } | |
580 | + FREE(self->mRedirectsFileNames); | |
569 | 581 | } |
570 | - if(self->mRedirectsFileNames) FREE(self->mRedirectsFileNames); | |
571 | 582 | if(self->mRedirects) FREE(self->mRedirects); |
572 | 583 | |
573 | 584 | if(self->mRedirectsFileNamesRuntime) { |
@@ -672,7 +683,12 @@ static void sStatment_copy_deeply(sStatment* dest, sStatment* source) | ||
672 | 683 | sCommand_copy_deeply(dest->mCommands + i, source->mCommands + i); |
673 | 684 | } |
674 | 685 | |
675 | - dest->mFName = STRDUP(source->mFName); | |
686 | + if(source->mFName) { | |
687 | + dest->mFName = STRDUP(source->mFName); | |
688 | + } | |
689 | + else { | |
690 | + dest->mFName = NULL; | |
691 | + } | |
676 | 692 | dest->mLine = source->mLine; |
677 | 693 | |
678 | 694 | dest->mFlags = source->mFlags; |
@@ -687,7 +703,12 @@ static void sStatment_copy_deeply_stack(sStatment* dest, sStatment* source) | ||
687 | 703 | sCommand_copy_deeply_stack(dest->mCommands + i, source->mCommands + i); |
688 | 704 | } |
689 | 705 | |
690 | - dest->mFName = STRDUP(source->mFName); | |
706 | + if(source->mFName) { | |
707 | + dest->mFName = STRDUP(source->mFName); | |
708 | + } | |
709 | + else { | |
710 | + dest->mFName = NULL; | |
711 | + } | |
691 | 712 | dest->mLine = source->mLine; |
692 | 713 | |
693 | 714 | dest->mFlags = source->mFlags; |
@@ -702,7 +723,12 @@ static void sStatment_copy_deeply_malloc(sStatment* dest, sStatment* source) | ||
702 | 723 | sCommand_copy_deeply_malloc(dest->mCommands + i, source->mCommands + i); |
703 | 724 | } |
704 | 725 | |
705 | - dest->mFName = STRDUP(source->mFName); | |
726 | + if(source->mFName) { | |
727 | + dest->mFName = STRDUP(source->mFName); | |
728 | + } | |
729 | + else { | |
730 | + dest->mFName = NULL; | |
731 | + } | |
706 | 732 | dest->mLine = source->mLine; |
707 | 733 | |
708 | 734 | dest->mFlags = source->mFlags; |
@@ -255,10 +255,10 @@ BOOL cmd_stackframe(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
255 | 255 | sCommand* command = runinfo->mCommand; |
256 | 256 | char buf[BUFSIZ]; |
257 | 257 | |
258 | - hash_it* it = hash_loop_begin(SFUN(runinfo->mRunningObject).mLocalObjects); | |
258 | + uobject_it* it = uobject_loop_begin(SFUN(runinfo->mRunningObject).mLocalObjects); | |
259 | 259 | while(it) { |
260 | - sObject* object2 = hash_loop_item(it); | |
261 | - char* key = hash_loop_key(it); | |
260 | + sObject* object2 = uobject_loop_item(it); | |
261 | + char* key = uobject_loop_key(it); | |
262 | 262 | |
263 | 263 | char*obj_kind[16] = { |
264 | 264 | NULL, "var", "array", "hash", "list", "native function", "block", "file dicriptor", "job", "object", "memchecker", "function", "class", "external program", "completion", "external object" |
@@ -271,10 +271,10 @@ BOOL cmd_stackframe(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
271 | 271 | return FALSE; |
272 | 272 | } |
273 | 273 | |
274 | - it = hash_loop_next(it); | |
274 | + it = uobject_loop_next(it); | |
275 | 275 | } |
276 | 276 | |
277 | - if(hash_count(SFUN(runinfo->mRunningObject).mLocalObjects) == 0) { | |
277 | + if(uobject_count(SFUN(runinfo->mRunningObject).mLocalObjects) == 0) { | |
278 | 278 | runinfo->mRCode = 1; |
279 | 279 | } |
280 | 280 | else { |
@@ -395,7 +395,7 @@ BOOL cmd_sweep(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
395 | 395 | char* var_name = command->mArgsRuntime[i]; |
396 | 396 | sObject* current_object = runinfo->mCurrentObject; |
397 | 397 | |
398 | - sObject* item = hash_item(current_object, var_name); | |
398 | + sObject* item = uobject_item(current_object, var_name); | |
399 | 399 | |
400 | 400 | if(item && item->mUserObject) { |
401 | 401 | if(item != gCurrentObject || strcmp(var_name, SUOBJECT(item).mName) != 0) { |
@@ -673,9 +673,9 @@ static BOOL xyzsh_seek_external_programs(char* path, sObject* sys, char* sname, | ||
673 | 673 | && strcmp(entry->d_name, "..") != 0 |
674 | 674 | && |
675 | 675 | (stat_.st_mode & S_IXUSR ||stat_.st_mode & S_IXGRP||stat_.st_mode & S_IXOTH) |
676 | - && hash_item(sys, entry->d_name) == NULL) | |
676 | + && uobject_item(sys, entry->d_name) == NULL) | |
677 | 677 | { |
678 | - hash_put(sys, entry->d_name, EXTPROG_NEW_GC(path2, TRUE)); | |
678 | + uobject_put(sys, entry->d_name, EXTPROG_NEW_GC(path2, TRUE)); | |
679 | 679 | } |
680 | 680 | } |
681 | 681 |
@@ -700,7 +700,7 @@ BOOL xyzsh_rehash(char* sname, int sline) | ||
700 | 700 | } |
701 | 701 | |
702 | 702 | sObject* sys = UOBJECT_NEW_GC(8, gRootObject, "sys", FALSE); |
703 | - hash_put(gRootObject, "sys", sys); | |
703 | + uobject_put(gRootObject, "sys", sys); | |
704 | 704 | uobject_init(sys); |
705 | 705 | |
706 | 706 | char buf[PATH_MAX+1]; |
@@ -798,7 +798,7 @@ BOOL cmd_prompt(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
798 | 798 | sCommand* command = runinfo->mCommand; |
799 | 799 | if(command->mBlocksNum == 1) { |
800 | 800 | gPrompt = block_clone_gc(command->mBlocks[0], T_BLOCK, FALSE); |
801 | - hash_put(gxyzshObject, "_prompt", gPrompt); | |
801 | + uobject_put(gxyzshObject, "_prompt", gPrompt); | |
802 | 802 | runinfo->mRCode = 0; |
803 | 803 | } |
804 | 804 |
@@ -870,3 +870,85 @@ BOOL cmd_block(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
870 | 870 | |
871 | 871 | return TRUE; |
872 | 872 | } |
873 | + | |
874 | +BOOL cmd_kanjicode(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | |
875 | +{ | |
876 | + sCommand* command = runinfo->mCommand; | |
877 | + | |
878 | + if(sCommand_option_item(command, "-byte")) { | |
879 | + gKanjiCode = kByte; | |
880 | + runinfo->mRCode = 0; | |
881 | + } | |
882 | + else if(sCommand_option_item(command, "-utf8")) { | |
883 | + gKanjiCode = kUtf8; | |
884 | + runinfo->mRCode = 0; | |
885 | + } | |
886 | + else if(sCommand_option_item(command, "-sjis")) { | |
887 | + gKanjiCode = kSjis; | |
888 | + runinfo->mRCode = 0; | |
889 | + } | |
890 | + else if(sCommand_option_item(command, "-eucjp")) { | |
891 | + gKanjiCode = kEucjp; | |
892 | + runinfo->mRCode = 0; | |
893 | + } | |
894 | + else { | |
895 | + if(gKanjiCode == kUtf8) { | |
896 | + if(!fd_write(nextout, "utf8", 4)) { | |
897 | + err_msg("interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
898 | + runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; | |
899 | + return FALSE; | |
900 | + } | |
901 | + if(!fd_write(nextout, "\n", 1)) { | |
902 | + err_msg("interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
903 | + runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; | |
904 | + return FALSE; | |
905 | + } | |
906 | + | |
907 | + runinfo->mRCode = 0; | |
908 | + } | |
909 | + else if(gKanjiCode == kByte) { | |
910 | + if(!fd_write(nextout, "byte", 4)) { | |
911 | + err_msg("interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
912 | + runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; | |
913 | + return FALSE; | |
914 | + } | |
915 | + if(!fd_write(nextout, "\n", 1)) { | |
916 | + err_msg("interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
917 | + runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; | |
918 | + return FALSE; | |
919 | + } | |
920 | + | |
921 | + runinfo->mRCode = 0; | |
922 | + } | |
923 | + else if(gKanjiCode == kSjis) { | |
924 | + if(!fd_write(nextout, "sjis", 4)) { | |
925 | + err_msg("interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
926 | + runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; | |
927 | + return FALSE; | |
928 | + } | |
929 | + if(!fd_write(nextout, "\n", 1)) { | |
930 | + err_msg("interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
931 | + runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; | |
932 | + return FALSE; | |
933 | + } | |
934 | + | |
935 | + runinfo->mRCode = 0; | |
936 | + } | |
937 | + else if(gKanjiCode == kEucjp) { | |
938 | + if(!fd_write(nextout, "eucjp", 5)) { | |
939 | + err_msg("interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
940 | + runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; | |
941 | + return FALSE; | |
942 | + } | |
943 | + if(!fd_write(nextout, "\n", 1)) { | |
944 | + err_msg("interrupt", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); | |
945 | + runinfo->mRCode = RCODE_SIGNAL_INTERRUPT; | |
946 | + return FALSE; | |
947 | + } | |
948 | + | |
949 | + runinfo->mRCode = 0; | |
950 | + } | |
951 | + } | |
952 | + | |
953 | + return TRUE; | |
954 | +} |
@@ -624,25 +624,25 @@ void clear_matching_info_variable() | ||
624 | 624 | { |
625 | 625 | char buf[128]; |
626 | 626 | snprintf(buf, 128, ""); |
627 | - hash_put(gRootObject, "MATCH", STRING_NEW_GC(buf, FALSE)); | |
627 | + uobject_put(gRootObject, "MATCH", STRING_NEW_GC(buf, FALSE)); | |
628 | 628 | |
629 | 629 | snprintf(buf, 128, ""); |
630 | - hash_put(gRootObject, "PREMATCH", STRING_NEW_GC(buf, FALSE)); | |
630 | + uobject_put(gRootObject, "PREMATCH", STRING_NEW_GC(buf, FALSE)); | |
631 | 631 | |
632 | 632 | snprintf(buf, 128, ""); |
633 | - hash_put(gRootObject, "POSTMATCH", STRING_NEW_GC(buf, FALSE)); | |
633 | + uobject_put(gRootObject, "POSTMATCH", STRING_NEW_GC(buf, FALSE)); | |
634 | 634 | |
635 | 635 | snprintf(buf, 128, ""); |
636 | - hash_put(gRootObject, "MATCH_NUMBER", STRING_NEW_GC(buf, FALSE)); | |
636 | + uobject_put(gRootObject, "MATCH_NUMBER", STRING_NEW_GC(buf, FALSE)); | |
637 | 637 | |
638 | 638 | snprintf(buf, 128, ""); |
639 | - hash_put(gRootObject, "LAST_MATCH", STRING_NEW_GC(buf, FALSE)); | |
639 | + uobject_put(gRootObject, "LAST_MATCH", STRING_NEW_GC(buf, FALSE)); | |
640 | 640 | |
641 | 641 | int i; |
642 | 642 | for(i=0; i<10; i++) { |
643 | 643 | char name[128]; |
644 | 644 | snprintf(name, 128, "%d", i); |
645 | - hash_put(gRootObject, name, STRING_NEW_GC(buf, FALSE)); | |
645 | + uobject_put(gRootObject, name, STRING_NEW_GC(buf, FALSE)); | |
646 | 646 | } |
647 | 647 | } |
648 | 648 |
@@ -690,17 +690,17 @@ BOOL cmd_condition_re(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
690 | 690 | |
691 | 691 | if(r2 >= 0) { |
692 | 692 | if(region->beg[0] > 0) { |
693 | - hash_put(gRootObject, "PREMATCH", STRING_NEW_GC3(target, region->beg[0], FALSE)); | |
693 | + uobject_put(gRootObject, "PREMATCH", STRING_NEW_GC3(target, region->beg[0], FALSE)); | |
694 | 694 | } |
695 | 695 | |
696 | 696 | const int size = region->end[0] - region->beg[0]; |
697 | 697 | |
698 | - hash_put(gRootObject, "MATCH", STRING_NEW_GC3(target + region->beg[0], size, FALSE)); | |
699 | - hash_put(gRootObject, "0", STRING_NEW_GC3(target + region->beg[0], size, FALSE)); | |
698 | + uobject_put(gRootObject, "MATCH", STRING_NEW_GC3(target + region->beg[0], size, FALSE)); | |
699 | + uobject_put(gRootObject, "0", STRING_NEW_GC3(target + region->beg[0], size, FALSE)); | |
700 | 700 | |
701 | 701 | const int n = strlen(target)-region->end[0]; |
702 | 702 | if(n > 0) { |
703 | - hash_put(gRootObject, "POSTMATCH", STRING_NEW_GC3(target + region->end[0], n, FALSE)); | |
703 | + uobject_put(gRootObject, "POSTMATCH", STRING_NEW_GC3(target + region->end[0], n, FALSE)); | |
704 | 704 | } |
705 | 705 | |
706 | 706 | int i; |
@@ -710,7 +710,7 @@ BOOL cmd_condition_re(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
710 | 710 | char name[16]; |
711 | 711 | snprintf(name, 16, "%d", i); |
712 | 712 | |
713 | - hash_put(gRootObject, name, STRING_NEW_GC3(target + region->beg[i], size, FALSE)); | |
713 | + uobject_put(gRootObject, name, STRING_NEW_GC3(target + region->beg[i], size, FALSE)); | |
714 | 714 | } |
715 | 715 | |
716 | 716 | if(region->num_regs > 0) { |
@@ -718,12 +718,12 @@ BOOL cmd_condition_re(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
718 | 718 | |
719 | 719 | const int size = region->end[n] - region->beg[n]; |
720 | 720 | |
721 | - hash_put(gRootObject, "LAST_MATCH", STRING_NEW_GC3(target + region->beg[n], size, FALSE)); | |
721 | + uobject_put(gRootObject, "LAST_MATCH", STRING_NEW_GC3(target + region->beg[n], size, FALSE)); | |
722 | 722 | } |
723 | 723 | |
724 | 724 | char buf[128]; |
725 | 725 | snprintf(buf, 128, "%d", region->num_regs); |
726 | - hash_put(gRootObject, "MATCH_NUMBER", STRING_NEW_GC(buf, FALSE)); | |
726 | + uobject_put(gRootObject, "MATCH_NUMBER", STRING_NEW_GC(buf, FALSE)); | |
727 | 727 | |
728 | 728 | if(verbose) { |
729 | 729 | int point = str_pointer2kanjipos(code, target, target + r2); |
@@ -29,10 +29,10 @@ BOOL cmd_mshow(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
29 | 29 | sCommand* command = runinfo->mCommand; |
30 | 30 | |
31 | 31 | sObject* object = runinfo->mRecieverObject; |
32 | - hash_it* it = hash_loop_begin(object); | |
32 | + uobject_it* it = uobject_loop_begin(object); | |
33 | 33 | while(it) { |
34 | - sObject* object2 = hash_loop_item(it); | |
35 | - char* key = hash_loop_key(it); | |
34 | + sObject* object2 = uobject_loop_item(it); | |
35 | + char* key = uobject_loop_key(it); | |
36 | 36 | |
37 | 37 | char buf[BUFSIZ]; |
38 | 38 | char*obj_kind[16] = { |
@@ -46,7 +46,7 @@ BOOL cmd_mshow(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
46 | 46 | return FALSE; |
47 | 47 | } |
48 | 48 | |
49 | - it = hash_loop_next(it); | |
49 | + it = uobject_loop_next(it); | |
50 | 50 | } |
51 | 51 | |
52 | 52 | runinfo->mRCode = 0; |
@@ -64,7 +64,7 @@ static BOOL entry_fun(sObject* nextin, sObject* nextout, sRunInfo* runinfo, sObj | ||
64 | 64 | block = fun_clone_from_stack_block_gc(block, TRUE, NULL); // block is a stack object, so change the memory manager from stack to gc |
65 | 65 | |
66 | 66 | if(sCommand_option_item(command, "-inherit")) { |
67 | - sObject* parent = hash_item(object, command->mArgsRuntime[1]); | |
67 | + sObject* parent = uobject_item(object, command->mArgsRuntime[1]); | |
68 | 68 | if(parent) { |
69 | 69 | if(type == T_FUN && (TYPE(parent) == T_FUN || TYPE(parent) == T_NFUN) |
70 | 70 | || type == T_CLASS && TYPE(parent) == T_CLASS) |
@@ -127,7 +127,7 @@ static BOOL entry_fun(sObject* nextin, sObject* nextout, sRunInfo* runinfo, sObj | ||
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
130 | - hash_put(object, command->mArgsRuntime[1], block); | |
130 | + uobject_put(object, command->mArgsRuntime[1], block); | |
131 | 131 | |
132 | 132 | return TRUE; |
133 | 133 | } |
@@ -268,6 +268,30 @@ BOOL cmd_class(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
268 | 268 | return TRUE; |
269 | 269 | } |
270 | 270 | |
271 | +BOOL cmd_defined(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | |
272 | +{ | |
273 | + sCommand* command = runinfo->mCommand; | |
274 | + | |
275 | + if(command->mArgsNumRuntime > 1) { | |
276 | + sObject* object = runinfo->mCurrentObject; | |
277 | + int i; | |
278 | + for(i=1; i<command->mArgsNumRuntime; i++) { | |
279 | + sObject* reciever = runinfo->mCurrentObject; | |
280 | + sObject* obj = access_object(command->mArgsRuntime[i], &reciever, runinfo->mRunningObject); | |
281 | + | |
282 | + if(obj) { | |
283 | + runinfo->mRCode = 0; | |
284 | + } | |
285 | + else { | |
286 | + runinfo->mRCode = RCODE_NFUN_FALSE; | |
287 | + break; | |
288 | + } | |
289 | + } | |
290 | + } | |
291 | + | |
292 | + return TRUE; | |
293 | +} | |
294 | + | |
271 | 295 | BOOL cmd_inherit(sObject* nextin, sObject* nextout, sRunInfo* runinfo) |
272 | 296 | { |
273 | 297 | sCommand* command = runinfo->mCommand; |
@@ -474,10 +498,10 @@ BOOL cmd_var(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
474 | 498 | if(i-1 < max) { |
475 | 499 | sObject* new_var = STRING_NEW_GC(vector_item(SFD(nextin).fdbuf.mLines, i-1), TRUE); |
476 | 500 | string_chomp(new_var); |
477 | - hash_put(object, command->mArgsRuntime[i], new_var); | |
501 | + uobject_put(object, command->mArgsRuntime[i], new_var); | |
478 | 502 | } |
479 | 503 | else { |
480 | - hash_put(object, command->mArgsRuntime[i], STRING_NEW_GC("", TRUE)); | |
504 | + uobject_put(object, command->mArgsRuntime[i], STRING_NEW_GC("", TRUE)); | |
481 | 505 | } |
482 | 506 | } |
483 | 507 |
@@ -514,7 +538,7 @@ BOOL cmd_object(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
514 | 538 | int i; |
515 | 539 | for(i=1; i<command->mArgsNumRuntime; i++) { |
516 | 540 | sObject* new_object = UOBJECT_NEW_GC(8, object, command->mArgsRuntime[i], TRUE); |
517 | - hash_put(object, command->mArgsRuntime[i], new_object); | |
541 | + uobject_put(object, command->mArgsRuntime[i], new_object); | |
518 | 542 | uobject_init(new_object); |
519 | 543 | |
520 | 544 | int rcode = 0; |
@@ -531,7 +555,7 @@ BOOL cmd_object(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
531 | 555 | int i; |
532 | 556 | for(i=1; i<command->mArgsNumRuntime; i++) { |
533 | 557 | sObject* new_object = UOBJECT_NEW_GC(8, object, command->mArgsRuntime[i], TRUE); |
534 | - hash_put(object, command->mArgsRuntime[i], new_object); | |
558 | + uobject_put(object, command->mArgsRuntime[i], new_object); | |
535 | 559 | uobject_init(new_object); |
536 | 560 | runinfo->mRCode = 0; |
537 | 561 | } |
@@ -618,7 +642,7 @@ BOOL cmd_co(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
618 | 642 | sCommand* command = runinfo->mCommand; |
619 | 643 | |
620 | 644 | if(command->mArgsNumRuntime == 2) { |
621 | - sObject* new_current = hash_item(gCurrentObject, command->mArgsRuntime[1]); | |
645 | + sObject* new_current = uobject_item(gCurrentObject, command->mArgsRuntime[1]); | |
622 | 646 | if(new_current && TYPE(new_current) == T_UOBJECT) { |
623 | 647 | gCurrentObject = new_current; |
624 | 648 | runinfo->mRCode = 0; |
@@ -741,7 +765,7 @@ BOOL cmd_ref(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
741 | 765 | int type = memchecker_item(gMemChecker, mem); |
742 | 766 | |
743 | 767 | if(type >= 0) { |
744 | - hash_put(object, command->mArgsRuntime[i+1], mem); | |
768 | + uobject_put(object, command->mArgsRuntime[i+1], mem); | |
745 | 769 | } |
746 | 770 | else { |
747 | 771 | err_msg("invalid adress. it's not memory managed by a xyzsh gabage collecter", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); |
@@ -964,7 +988,7 @@ BOOL cmd_ary(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
964 | 988 | return FALSE; |
965 | 989 | } |
966 | 990 | |
967 | - hash_put(object, command->mArgsRuntime[1], new_ary); | |
991 | + uobject_put(object, command->mArgsRuntime[1], new_ary); | |
968 | 992 | for(i=0; i<max; i++) { |
969 | 993 | sObject* new_var = STRING_NEW_GC(vector_item(SFD(nextin).fdbuf.mLines, i), FALSE); |
970 | 994 | string_chomp(new_var); |
@@ -1172,7 +1196,7 @@ BOOL cmd_hash(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1172 | 1196 | return FALSE; |
1173 | 1197 | } |
1174 | 1198 | |
1175 | - hash_put(object, command->mArgsRuntime[1], new_hash); | |
1199 | + uobject_put(object, command->mArgsRuntime[1], new_hash); | |
1176 | 1200 | sObject* key = STRING_NEW_STACK(""); |
1177 | 1201 | for(i=0; i<max; i++) { |
1178 | 1202 | if((i % 2) == 0) { |
@@ -1177,17 +1177,17 @@ BOOL cmd_sub(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1177 | 1177 | |
1178 | 1178 | const int size = region->beg[0] - (p - target); |
1179 | 1179 | if(size > 0) { |
1180 | - hash_put(gRootObject, "PREMATCH", STRING_NEW_GC3(p, size, FALSE)); | |
1180 | + uobject_put(gRootObject, "PREMATCH", STRING_NEW_GC3(p, size, FALSE)); | |
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 | const int size2 = region->end[0] - region->beg[0]; |
1184 | 1184 | |
1185 | - hash_put(gRootObject, "MATCH", STRING_NEW_GC3(target + region->beg[0], size2, FALSE)); | |
1186 | - hash_put(gRootObject, "0", STRING_NEW_GC3(target + region->beg[0], size2, FALSE)); | |
1185 | + uobject_put(gRootObject, "MATCH", STRING_NEW_GC3(target + region->beg[0], size2, FALSE)); | |
1186 | + uobject_put(gRootObject, "0", STRING_NEW_GC3(target + region->beg[0], size2, FALSE)); | |
1187 | 1187 | |
1188 | 1188 | const int n = strlen(target)-region->end[0]; |
1189 | 1189 | if(n > 0) { |
1190 | - hash_put(gRootObject, "POSTMATCH", STRING_NEW_GC3(target + region->end[0], n, FALSE)); | |
1190 | + uobject_put(gRootObject, "POSTMATCH", STRING_NEW_GC3(target + region->end[0], n, FALSE)); | |
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | int i; |
@@ -1197,7 +1197,7 @@ BOOL cmd_sub(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1197 | 1197 | char name[16]; |
1198 | 1198 | snprintf(name, 16, "%d", i); |
1199 | 1199 | |
1200 | - hash_put(gRootObject, name, STRING_NEW_GC3(target + region->beg[i], size, FALSE)); | |
1200 | + uobject_put(gRootObject, name, STRING_NEW_GC3(target + region->beg[i], size, FALSE)); | |
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | if(region->num_regs > 0) { |
@@ -1205,12 +1205,12 @@ BOOL cmd_sub(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1205 | 1205 | |
1206 | 1206 | const int size = region->end[n] - region->beg[n]; |
1207 | 1207 | |
1208 | - hash_put(gRootObject, "LAST_MATCH", STRING_NEW_GC3(target + region->beg[n], size, FALSE)); | |
1208 | + uobject_put(gRootObject, "LAST_MATCH", STRING_NEW_GC3(target + region->beg[n], size, FALSE)); | |
1209 | 1209 | } |
1210 | 1210 | |
1211 | 1211 | char buf[128]; |
1212 | 1212 | snprintf(buf, 128, "%d", region->num_regs); |
1213 | - hash_put(gRootObject, "MATCH_NUMBER", STRING_NEW_GC(buf, FALSE)); | |
1213 | + uobject_put(gRootObject, "MATCH_NUMBER", STRING_NEW_GC(buf, FALSE)); | |
1214 | 1214 | |
1215 | 1215 | fd_clear(nextin2); |
1216 | 1216 | fd_clear(nextout2); |
@@ -1358,7 +1358,7 @@ BOOL cmd_sub(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1358 | 1358 | |
1359 | 1359 | char buf[128]; |
1360 | 1360 | snprintf(buf, 128, "%d", sub_count); |
1361 | - hash_put(gRootObject, "SUB_COUNT", STRING_NEW_GC(buf, FALSE)); | |
1361 | + uobject_put(gRootObject, "SUB_COUNT", STRING_NEW_GC(buf, FALSE)); | |
1362 | 1362 | |
1363 | 1363 | if(sub_count > 0) { |
1364 | 1364 | if(SFD(nextin).fdbuf.mBufLen == 0) { |
@@ -1488,17 +1488,17 @@ BOOL cmd_scan(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1488 | 1488 | |
1489 | 1489 | const int size = region->beg[0] - (p - target); |
1490 | 1490 | if(size > 0) { |
1491 | - hash_put(gRootObject, "PREMATCH", STRING_NEW_GC3(p, size, FALSE)); | |
1491 | + uobject_put(gRootObject, "PREMATCH", STRING_NEW_GC3(p, size, FALSE)); | |
1492 | 1492 | } |
1493 | 1493 | |
1494 | 1494 | const int size2 = region->end[0] - region->beg[0]; |
1495 | 1495 | |
1496 | - hash_put(gRootObject, "MATCH", STRING_NEW_GC3(target + region->beg[0], size2, FALSE)); | |
1497 | - hash_put(gRootObject, "0", STRING_NEW_GC3(target + region->beg[0], size2, FALSE)); | |
1496 | + uobject_put(gRootObject, "MATCH", STRING_NEW_GC3(target + region->beg[0], size2, FALSE)); | |
1497 | + uobject_put(gRootObject, "0", STRING_NEW_GC3(target + region->beg[0], size2, FALSE)); | |
1498 | 1498 | |
1499 | 1499 | const int n = strlen(target)-region->end[0]; |
1500 | 1500 | if(n > 0) { |
1501 | - hash_put(gRootObject, "POSTMATCH", STRING_NEW_GC3(target + region->end[0], n, FALSE)); | |
1501 | + uobject_put(gRootObject, "POSTMATCH", STRING_NEW_GC3(target + region->end[0], n, FALSE)); | |
1502 | 1502 | } |
1503 | 1503 | |
1504 | 1504 | int i; |
@@ -1508,7 +1508,7 @@ BOOL cmd_scan(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1508 | 1508 | char name[16]; |
1509 | 1509 | snprintf(name, 16, "%d", i); |
1510 | 1510 | |
1511 | - hash_put(gRootObject, name, STRING_NEW_GC3(target + region->beg[i], size, FALSE)); | |
1511 | + uobject_put(gRootObject, name, STRING_NEW_GC3(target + region->beg[i], size, FALSE)); | |
1512 | 1512 | } |
1513 | 1513 | |
1514 | 1514 | if(region->num_regs > 0) { |
@@ -1516,12 +1516,12 @@ BOOL cmd_scan(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1516 | 1516 | |
1517 | 1517 | const int size = region->end[n] - region->beg[n]; |
1518 | 1518 | |
1519 | - hash_put(gRootObject, "LAST_MATCH", STRING_NEW_GC3(target + region->beg[n], size, FALSE)); | |
1519 | + uobject_put(gRootObject, "LAST_MATCH", STRING_NEW_GC3(target + region->beg[n], size, FALSE)); | |
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | char buf[128]; |
1523 | 1523 | snprintf(buf, 128, "%d", region->num_regs); |
1524 | - hash_put(gRootObject, "MATCH_NUMBER", STRING_NEW_GC(buf, FALSE)); | |
1524 | + uobject_put(gRootObject, "MATCH_NUMBER", STRING_NEW_GC(buf, FALSE)); | |
1525 | 1525 | |
1526 | 1526 | int rcode = 0; |
1527 | 1527 | if(!run(block, nextin2, nextout, &rcode, runinfo->mCurrentObject, runinfo->mRunningObject)) { |
@@ -1600,7 +1600,7 @@ BOOL cmd_scan(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
1600 | 1600 | |
1601 | 1601 | char buf[128]; |
1602 | 1602 | snprintf(buf, 128, "%d", match_count); |
1603 | - hash_put(gRootObject, "MATCH_COUNT", STRING_NEW_GC(buf, FALSE)); | |
1603 | + uobject_put(gRootObject, "MATCH_COUNT", STRING_NEW_GC(buf, FALSE)); | |
1604 | 1604 | |
1605 | 1605 | if(match_count > 0) { |
1606 | 1606 | if(SFD(nextin).fdbuf.mBufLen == 0) { |
@@ -200,17 +200,18 @@ void gc_init(int pool_size) | ||
200 | 200 | gCompletionObject = UOBJECT_NEW_GC(8, gRootObject, "compl", FALSE); |
201 | 201 | uobject_init(gCompletionObject); |
202 | 202 | |
203 | - hash_put(gRootObject, "compl", gCompletionObject); | |
203 | + uobject_put(gRootObject, "compl", gCompletionObject); | |
204 | 204 | |
205 | 205 | gxyzshObject = UOBJECT_NEW_GC(8, NULL, "xyzsh", FALSE); |
206 | 206 | gStackFrames = VECTOR_NEW_GC(8, FALSE); |
207 | - hash_put(gxyzshObject, "_stackframes", gStackFrames); | |
207 | + uobject_put(gxyzshObject, "_stackframes", gStackFrames); | |
208 | 208 | } |
209 | 209 | |
210 | 210 | void gc_final() |
211 | 211 | { |
212 | 212 | /// sweep all user objects /// |
213 | - hash_clear(gRootObject); | |
213 | + uobject_clear(gRootObject); | |
214 | + uobject_clear(gxyzshObject); | |
214 | 215 | if(gAppType == kATConsoleApp) { |
215 | 216 | printf("sweeped %d objects...\n", gc_sweep()); |
216 | 217 | } |
@@ -1,6 +1,7 @@ | ||
1 | 1 | #include "config.h" |
2 | 2 | #include <stdio.h> |
3 | 3 | #include <string.h> |
4 | +#include <assert.h> | |
4 | 5 | #include "xyzsh/xyzsh.h" |
5 | 6 | |
6 | 7 | hash_it* hash_it_new(char* key, void* item, hash_it* coll_it, hash_it* next_it, sObject* hash) |
@@ -92,6 +93,7 @@ sObject* hash_new_from_stack(int size) | ||
92 | 93 | |
93 | 94 | void hash_delete_gc(sObject* self) |
94 | 95 | { |
96 | + assert(TYPE(self) == T_HASH); | |
95 | 97 | hash_it* it = SHASH(self).mEntryIt; |
96 | 98 | |
97 | 99 | while(it) { |
@@ -105,6 +107,7 @@ void hash_delete_gc(sObject* self) | ||
105 | 107 | |
106 | 108 | void hash_delete_stack(sObject* self) |
107 | 109 | { |
110 | + assert(TYPE(self) == T_HASH); | |
108 | 111 | hash_it* it = SHASH(self).mEntryIt; |
109 | 112 | |
110 | 113 | while(it) { |
@@ -118,6 +121,7 @@ void hash_delete_stack(sObject* self) | ||
118 | 121 | |
119 | 122 | void hash_delete_malloc(sObject* self) |
120 | 123 | { |
124 | + assert(TYPE(self) == T_HASH); | |
121 | 125 | hash_it* it = SHASH(self).mEntryIt; |
122 | 126 | |
123 | 127 | while(it) { |
@@ -133,6 +137,8 @@ void hash_delete_malloc(sObject* self) | ||
133 | 137 | |
134 | 138 | static unsigned int get_hash_value(sObject* self, char* key) |
135 | 139 | { |
140 | + assert(TYPE(self) == T_HASH); | |
141 | + | |
136 | 142 | unsigned int i = 0; |
137 | 143 | while(*key) { |
138 | 144 | i += *key; |
@@ -144,6 +150,7 @@ static unsigned int get_hash_value(sObject* self, char* key) | ||
144 | 150 | |
145 | 151 | static void resize(sObject* self) |
146 | 152 | { |
153 | + assert(TYPE(self) == T_HASH); | |
147 | 154 | const int table_size = SHASH(self).mTableSize; |
148 | 155 | |
149 | 156 | SHASH(self).mTableSize *= 5; |
@@ -165,6 +172,8 @@ static void resize(sObject* self) | ||
165 | 172 | |
166 | 173 | void hash_put(sObject* self, char* key, void* item) |
167 | 174 | { |
175 | + assert(TYPE(self) == T_HASH); | |
176 | + | |
168 | 177 | if(SHASH(self).mCounter >= SHASH(self).mTableSize) { |
169 | 178 | resize(self); |
170 | 179 | } |
@@ -190,6 +199,7 @@ void hash_put(sObject* self, char* key, void* item) | ||
190 | 199 | |
191 | 200 | static void erase_from_list(sObject* self, hash_it* rit) |
192 | 201 | { |
202 | + assert(TYPE(self) == T_HASH); | |
193 | 203 | if(rit == SHASH(self).mEntryIt) { |
194 | 204 | SHASH(self).mEntryIt = rit->mNextIt; |
195 | 205 | } |
@@ -209,6 +219,7 @@ static void erase_from_list(sObject* self, hash_it* rit) | ||
209 | 219 | |
210 | 220 | BOOL hash_erase(sObject* self, char* key) |
211 | 221 | { |
222 | + assert(TYPE(self) == T_HASH); | |
212 | 223 | const unsigned int hash_value = get_hash_value(self, key); |
213 | 224 | hash_it* it = SHASH(self).mTable[hash_value]; |
214 | 225 |
@@ -249,6 +260,7 @@ BOOL hash_erase(sObject* self, char* key) | ||
249 | 260 | |
250 | 261 | void hash_clear(sObject* self) |
251 | 262 | { |
263 | + assert(TYPE(self) == T_HASH); | |
252 | 264 | int i; |
253 | 265 | int max; |
254 | 266 | hash_it* it = SHASH(self).mEntryIt; |
@@ -267,6 +279,7 @@ void hash_clear(sObject* self) | ||
267 | 279 | |
268 | 280 | void hash_replace(sObject* self, char* key, void* item) |
269 | 281 | { |
282 | + assert(TYPE(self) == T_HASH); | |
270 | 283 | hash_it* it = SHASH(self).mTable[get_hash_value(self, key)]; |
271 | 284 | |
272 | 285 | if(it) { |
@@ -283,6 +296,8 @@ void hash_replace(sObject* self, char* key, void* item) | ||
283 | 296 | |
284 | 297 | void hash_show(sObject* self, char* fname) |
285 | 298 | { |
299 | + assert(TYPE(self) == T_HASH); | |
300 | + | |
286 | 301 | char tmp[8096]; |
287 | 302 | int i; |
288 | 303 | int max; |
@@ -318,6 +333,8 @@ void hash_show(sObject* self, char* fname) | ||
318 | 333 | |
319 | 334 | void* hash_item(sObject* self, char* key) |
320 | 335 | { |
336 | + assert(TYPE(self) == T_HASH); | |
337 | + | |
321 | 338 | hash_it* it = SHASH(self).mTable[ get_hash_value(self, key) ]; |
322 | 339 | |
323 | 340 | while(it) { |
@@ -330,6 +347,8 @@ void* hash_item(sObject* self, char* key) | ||
330 | 347 | |
331 | 348 | void* hash_item_addr(sObject* self, char* key) |
332 | 349 | { |
350 | + assert(TYPE(self) == T_HASH); | |
351 | + | |
333 | 352 | hash_it* it = SHASH(self).mTable[ get_hash_value(self, key) ]; |
334 | 353 | while(it) { |
335 | 354 | if(strcmp(key, it->mKey) == 0) return &it->mItem; |
@@ -341,6 +360,8 @@ void* hash_item_addr(sObject* self, char* key) | ||
341 | 360 | |
342 | 361 | char* hash_key(sObject* self, void* item) |
343 | 362 | { |
363 | + assert(TYPE(self) == T_HASH); | |
364 | + | |
344 | 365 | hash_it* it = SHASH(self).mEntryIt; |
345 | 366 | |
346 | 367 | while(it) { |
@@ -353,16 +374,37 @@ char* hash_key(sObject* self, void* item) | ||
353 | 374 | |
354 | 375 | int hash_count(sObject* self) |
355 | 376 | { |
377 | + assert(TYPE(self) == T_HASH); | |
378 | + | |
356 | 379 | return SHASH(self).mCounter; |
357 | 380 | } |
358 | 381 | |
359 | -hash_it* hash_loop_begin(sObject* self) { return SHASH(self).mEntryIt; } | |
360 | -void* hash_loop_item(hash_it* it) { return it->mItem; } | |
361 | -char* hash_loop_key(hash_it* it) { return it->mKey; } | |
362 | -hash_it* hash_loop_next(hash_it* it) { return it->mNextIt; } | |
382 | +hash_it* hash_loop_begin(sObject* self) | |
383 | +{ | |
384 | + assert(TYPE(self) == T_HASH); | |
385 | + | |
386 | + return SHASH(self).mEntryIt; | |
387 | +} | |
388 | + | |
389 | +void* hash_loop_item(hash_it* it) | |
390 | +{ | |
391 | + return it->mItem; | |
392 | +} | |
393 | + | |
394 | +char* hash_loop_key(hash_it* it) | |
395 | +{ | |
396 | + return it->mKey; | |
397 | +} | |
398 | + | |
399 | +hash_it* hash_loop_next(hash_it* it) | |
400 | +{ | |
401 | + return it->mNextIt; | |
402 | +} | |
363 | 403 | |
364 | 404 | int hash_gc_children_mark(sObject* self) |
365 | 405 | { |
406 | + assert(TYPE(self) == T_HASH); | |
407 | + | |
366 | 408 | int count = 0; |
367 | 409 | |
368 | 410 | hash_it* it = SHASH(self).mEntryIt; |
@@ -93,6 +93,7 @@ static char* prompt() | ||
93 | 93 | char* buf = readline(SFD(nextout).fdbuf.mBuf); |
94 | 94 | |
95 | 95 | (void)vector_pop_back(gStackFrames); |
96 | + | |
96 | 97 | stack_end_stack(); |
97 | 98 | |
98 | 99 | return buf; |
@@ -118,13 +119,12 @@ BOOL xyzsh_run(int* rcode, sObject* block, char* source_name, fXyzshJobDone xyzs | ||
118 | 119 | for(i=0; i<argc; i++) { |
119 | 120 | vector_add(argv2, STRING_NEW_GC(argv[i], FALSE)); |
120 | 121 | } |
121 | - hash_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
122 | + uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
122 | 123 | |
123 | 124 | SFUN(fun).mRunInfo = NULL; |
124 | 125 | |
125 | 126 | if(!run(block, nextin, nextout, rcode, current_object, fun)) { |
126 | 127 | xyzsh_restore_signal_default(); |
127 | - | |
128 | 128 | (void)vector_pop_back(gStackFrames); |
129 | 129 | |
130 | 130 | stack_end_stack(); |
@@ -137,7 +137,6 @@ BOOL xyzsh_run(int* rcode, sObject* block, char* source_name, fXyzshJobDone xyzs | ||
137 | 137 | xyzsh_restore_signal_default(); |
138 | 138 | |
139 | 139 | (void)vector_pop_back(gStackFrames); |
140 | - | |
141 | 140 | stack_end_stack(); |
142 | 141 | |
143 | 142 | /// wait background job |
@@ -286,15 +285,13 @@ BOOL xyzsh_readline_interface_onetime(int* rcode, char* cmdline, int cursor_poin | ||
286 | 285 | for(i=0; i<argc; i++) { |
287 | 286 | vector_add(argv2, STRING_NEW_GC(argv[i], FALSE)); |
288 | 287 | } |
289 | - hash_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
288 | + uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
290 | 289 | |
291 | 290 | SFUN(fun).mRunInfo = NULL; |
292 | 291 | |
293 | 292 | if(!run(block, gStdin, gStdout, rcode, gCurrentObject, fun)) { |
294 | 293 | xyzsh_restore_signal_default(); |
295 | 294 | |
296 | - (void)vector_pop_back(gStackFrames); | |
297 | - | |
298 | 295 | if(*rcode == RCODE_BREAK) { |
299 | 296 | fprintf(stderr, "invalid break. Not in a loop\n"); |
300 | 297 | } |
@@ -319,6 +316,7 @@ BOOL xyzsh_readline_interface_onetime(int* rcode, char* cmdline, int cursor_poin | ||
319 | 316 | if(*rcode != 0) { |
320 | 317 | fprintf(stderr, "return code is %d\n", *rcode); |
321 | 318 | } |
319 | + (void)vector_pop_back(gStackFrames); | |
322 | 320 | stack_end_stack(); |
323 | 321 | |
324 | 322 | /// wait background job |
@@ -328,9 +326,8 @@ BOOL xyzsh_readline_interface_onetime(int* rcode, char* cmdline, int cursor_poin | ||
328 | 326 | |
329 | 327 | return FALSE; |
330 | 328 | } |
331 | - readline_signal(); | |
332 | - | |
333 | 329 | (void)vector_pop_back(gStackFrames); |
330 | + readline_signal(); | |
334 | 331 | } |
335 | 332 | else { |
336 | 333 | xyzsh_restore_signal_default(); |
@@ -448,7 +445,7 @@ void xyzsh_readline_interface(char* cmdline, int cursor_point, char** argv, int | ||
448 | 445 | for(i=0; i<argc; i++) { |
449 | 446 | vector_add(argv2, STRING_NEW_GC(argv[i], FALSE)); |
450 | 447 | } |
451 | - hash_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
448 | + uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
452 | 449 | |
453 | 450 | SFUN(fun).mRunInfo = NULL; |
454 | 451 |
@@ -462,7 +459,6 @@ void xyzsh_readline_interface(char* cmdline, int cursor_point, char** argv, int | ||
462 | 459 | } |
463 | 460 | else if(rcode == RCODE_EXIT) { |
464 | 461 | stack_end_stack(); |
465 | - (void)vector_pop_back(gStackFrames); | |
466 | 462 | break; |
467 | 463 | } |
468 | 464 | else { |
@@ -470,9 +466,8 @@ void xyzsh_readline_interface(char* cmdline, int cursor_point, char** argv, int | ||
470 | 466 | fprintf(stderr, "%s", string_c_str(gErrMsg)); |
471 | 467 | } |
472 | 468 | } |
473 | - readline_signal(); | |
474 | - | |
475 | 469 | (void)vector_pop_back(gStackFrames); |
470 | + readline_signal(); | |
476 | 471 | } |
477 | 472 | else { |
478 | 473 | fprintf(stderr, "parser error\n"); |
@@ -560,7 +555,7 @@ void xyzsh_opt_c(char* cmd, char** argv, int argc) | ||
560 | 555 | for(i=0; i<argc; i++) { |
561 | 556 | vector_add(argv2, STRING_NEW_GC(argv[i], FALSE)); |
562 | 557 | } |
563 | - hash_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
558 | + uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
564 | 559 | |
565 | 560 | if(!run(block, gStdin, gStdout, &rcode, gRootObject, fun)) { |
566 | 561 | if(rcode == RCODE_BREAK) { |
@@ -576,8 +571,8 @@ void xyzsh_opt_c(char* cmd, char** argv, int argc) | ||
576 | 571 | fprintf(stderr, "%s", string_c_str(gErrMsg)); |
577 | 572 | } |
578 | 573 | } |
579 | - xyzsh_restore_signal_default(); | |
580 | 574 | (void)vector_pop_back(gStackFrames); |
575 | + xyzsh_restore_signal_default(); | |
581 | 576 | } |
582 | 577 | else { |
583 | 578 | fprintf(stderr, "parser error\n"); |
@@ -620,6 +615,6 @@ void xyzsh_add_inner_command(sObject* object, char* name, fXyzshNativeFun comman | ||
620 | 615 | } |
621 | 616 | va_end(args); |
622 | 617 | |
623 | - hash_put(object, name, nfun); | |
618 | + uobject_put(object, name, nfun); | |
624 | 619 | } |
625 | 620 |
@@ -3,272 +3,6 @@ | ||
3 | 3 | #include <string.h> |
4 | 4 | #include <stdio.h> |
5 | 5 | |
6 | -sObject* uobject_new_from_gc(int size, sObject* parent, char* name, BOOL user_object) | |
7 | -{ | |
8 | - sObject* self = gc_get_free_object(T_UOBJECT, user_object); | |
9 | - | |
10 | - SHASH(self).mTableSize = size; | |
11 | - SHASH(self).mTable = (hash_it**)MALLOC(sizeof(hash_it*) * size); | |
12 | - memset(SHASH(self).mTable, 0, sizeof(hash_it*)*size); | |
13 | - | |
14 | - SHASH(self).mEntryIt = NULL; | |
15 | - | |
16 | - SHASH(self).mCounter = 0; | |
17 | - | |
18 | - if(parent) SUOBJECT(self).mParent = parent; else SUOBJECT(self).mParent = self; | |
19 | - | |
20 | - SUOBJECT(self).mName = STRDUP(name); | |
21 | - | |
22 | - return self; | |
23 | -} | |
24 | - | |
25 | -sObject* uobject_new_from_stack(int size, sObject* parent, char* name) | |
26 | -{ | |
27 | - sObject* self = stack_get_free_object(T_UOBJECT); | |
28 | - | |
29 | - SHASH(self).mTableSize = size; | |
30 | - SHASH(self).mTable = (hash_it**)MALLOC(sizeof(hash_it*) * size); | |
31 | - memset(SHASH(self).mTable, 0, sizeof(hash_it*)*size); | |
32 | - | |
33 | - SHASH(self).mEntryIt = NULL; | |
34 | - | |
35 | - SHASH(self).mCounter = 0; | |
36 | - | |
37 | - if(parent) SUOBJECT(self).mParent = parent; else SUOBJECT(self).mParent = self; | |
38 | - | |
39 | - SUOBJECT(self).mName = STRDUP(name); | |
40 | - | |
41 | - return self; | |
42 | -} | |
43 | - | |
44 | -sObject* gInherit; | |
45 | - | |
46 | -void uobject_root_init(sObject* self) | |
47 | -{ | |
48 | - hash_put(self, "unset", NFUN_NEW_GC(cmd_unset, NULL, TRUE)); | |
49 | - sObject* readline = UOBJECT_NEW_GC(8, self, "rl", TRUE); | |
50 | - uobject_init(readline); | |
51 | - hash_put(self, "rl", readline); | |
52 | - | |
53 | - hash_put(readline, "insert_text", NFUN_NEW_GC(cmd_readline_insert_text, NULL, TRUE)); | |
54 | - hash_put(readline, "delete_text", NFUN_NEW_GC(cmd_readline_delete_text, NULL, TRUE)); | |
55 | - hash_put(readline, "clear_screen", NFUN_NEW_GC(cmd_readline_clear_screen, NULL, TRUE)); | |
56 | - hash_put(readline, "point_move", NFUN_NEW_GC(cmd_readline_point_move, NULL, TRUE)); | |
57 | - hash_put(readline, "read_history", NFUN_NEW_GC(cmd_readline_read_history, NULL, TRUE)); | |
58 | - hash_put(readline, "write_history", NFUN_NEW_GC(cmd_readline_write_history, NULL, TRUE)); | |
59 | - hash_put(self, "completion", NFUN_NEW_GC(cmd_completion, NULL, TRUE)); | |
60 | - hash_put(self, "p", NFUN_NEW_GC(cmd_p, NULL, TRUE)); | |
61 | - hash_put(self, "jobs", NFUN_NEW_GC(cmd_jobs, NULL, TRUE)); | |
62 | - hash_put(self, "gcinfo", NFUN_NEW_GC(cmd_gcinfo, NULL, TRUE)); | |
63 | - hash_put(self, "stackinfo", NFUN_NEW_GC(cmd_stackinfo, NULL, TRUE)); | |
64 | - hash_put(self, "fg", NFUN_NEW_GC(cmd_fg, NULL, TRUE)); | |
65 | - hash_put(self, "exit", NFUN_NEW_GC(cmd_exit, NULL, TRUE)); | |
66 | - hash_put(self, "fselector", NFUN_NEW_GC(cmd_fselector, NULL, TRUE)); | |
67 | - hash_put(self, "sweep", NFUN_NEW_GC(cmd_sweep, NULL, TRUE)); | |
68 | - hash_put(self, "subshell", NFUN_NEW_GC(cmd_subshell, NULL, TRUE)); | |
69 | - hash_put(self, "print", NFUN_NEW_GC(cmd_print, NULL, TRUE)); | |
70 | - hash_put(self, "if", NFUN_NEW_GC(cmd_if, NULL, TRUE)); | |
71 | - hash_put(self, "break", NFUN_NEW_GC(cmd_break, NULL, TRUE)); | |
72 | - hash_put(self, "while", NFUN_NEW_GC(cmd_while, NULL, TRUE)); | |
73 | - hash_put(self, "return", NFUN_NEW_GC(cmd_return, NULL, TRUE)); | |
74 | - hash_put(self, "rehash", NFUN_NEW_GC(cmd_rehash, NULL, TRUE)); | |
75 | - hash_put(self, "true", NFUN_NEW_GC(cmd_true, NULL, TRUE)); | |
76 | - hash_put(self, "false", NFUN_NEW_GC(cmd_false, NULL, TRUE)); | |
77 | - hash_put(self, "write", NFUN_NEW_GC(cmd_write, NULL, TRUE)); | |
78 | - hash_put(self, "quote", NFUN_NEW_GC(cmd_quote, NULL, TRUE)); | |
79 | - hash_put(self, "load", NFUN_NEW_GC(cmd_load, NULL, TRUE)); | |
80 | - gInherit = NFUN_NEW_GC(cmd_inherit, NULL, TRUE); | |
81 | - hash_put(self, "inherit", gInherit); | |
82 | - hash_put(self, "eval", NFUN_NEW_GC(cmd_eval, NULL, TRUE)); | |
83 | - hash_put(self, "object", NFUN_NEW_GC(cmd_object, NULL, TRUE)); | |
84 | - hash_put(self, "pwo", NFUN_NEW_GC(cmd_pwo, NULL, TRUE)); | |
85 | - hash_put(self, "co", NFUN_NEW_GC(cmd_co, NULL, TRUE)); | |
86 | - hash_put(self, "ref", NFUN_NEW_GC(cmd_ref, NULL, TRUE)); | |
87 | - hash_put(self, "length", NFUN_NEW_GC(cmd_length, NULL, TRUE)); | |
88 | - hash_put(self, "export", NFUN_NEW_GC(cmd_export, NULL, TRUE)); | |
89 | - hash_put(self, "x", NFUN_NEW_GC(cmd_x , NULL, TRUE)); | |
90 | - hash_put(self, "stackframe", NFUN_NEW_GC(cmd_stackframe, NULL, TRUE)); | |
91 | - hash_put(self, "msleep", NFUN_NEW_GC(cmd_msleep, NULL, TRUE)); | |
92 | - hash_put(self, "raise", NFUN_NEW_GC(cmd_raise, NULL, TRUE)); | |
93 | - hash_put(self, "cd", NFUN_NEW_GC(cmd_cd, NULL, TRUE)); | |
94 | - hash_put(self, "popd", NFUN_NEW_GC(cmd_popd, NULL, TRUE)); | |
95 | - hash_put(self, "pushd", NFUN_NEW_GC(cmd_pushd, NULL, TRUE)); | |
96 | - hash_put(self, "block", NFUN_NEW_GC(cmd_block, NULL, TRUE)); | |
97 | - hash_put(self, "lc", NFUN_NEW_GC(cmd_lc, NULL, TRUE)); | |
98 | - hash_put(self, "uc", NFUN_NEW_GC(cmd_uc, NULL, TRUE)); | |
99 | - hash_put(self, "chomp", NFUN_NEW_GC(cmd_chomp, NULL, TRUE)); | |
100 | - hash_put(self, "chop", NFUN_NEW_GC(cmd_chop, NULL, TRUE)); | |
101 | - hash_put(self, "pomch", NFUN_NEW_GC(cmd_pomch, NULL, TRUE)); | |
102 | - hash_put(self, "funinfo", NFUN_NEW_GC(cmd_funinfo, NULL, TRUE)); | |
103 | - hash_put(self, "printf", NFUN_NEW_GC(cmd_printf, NULL, TRUE)); | |
104 | - hash_put(self, "join", NFUN_NEW_GC(cmd_join, NULL, TRUE)); | |
105 | - hash_put(self, "lines", NFUN_NEW_GC(cmd_lines, NULL, TRUE)); | |
106 | - hash_put(self, "rows", NFUN_NEW_GC(cmd_rows, NULL, TRUE)); | |
107 | - hash_put(self, "scan", NFUN_NEW_GC(cmd_scan, NULL, TRUE)); | |
108 | - hash_put(self, "split", NFUN_NEW_GC(cmd_split, NULL, TRUE)); | |
109 | - hash_put(self, "try", NFUN_NEW_GC(cmd_try, NULL, TRUE)); | |
110 | - hash_put(self, "errmsg", NFUN_NEW_GC(cmd_errmsg, NULL, TRUE)); | |
111 | - hash_put(self, "prompt", NFUN_NEW_GC(cmd_prompt, NULL, TRUE)); | |
112 | - | |
113 | - hash_put(self, "-n", NFUN_NEW_GC(cmd_condition_n, NULL, TRUE)); | |
114 | - hash_put(self, "-z", NFUN_NEW_GC(cmd_condition_z, NULL, TRUE)); | |
115 | - hash_put(self, "-b", NFUN_NEW_GC(cmd_condition_b, NULL, TRUE)); | |
116 | - hash_put(self, "-c", NFUN_NEW_GC(cmd_condition_c, NULL, TRUE)); | |
117 | - hash_put(self, "-d", NFUN_NEW_GC(cmd_condition_d, NULL, TRUE)); | |
118 | - hash_put(self, "-f", NFUN_NEW_GC(cmd_condition_f, NULL, TRUE)); | |
119 | - hash_put(self, "-h", NFUN_NEW_GC(cmd_condition_h, NULL, TRUE)); | |
120 | - hash_put(self, "-L", NFUN_NEW_GC(cmd_condition_l, NULL, TRUE)); | |
121 | - hash_put(self, "-p", NFUN_NEW_GC(cmd_condition_p, NULL, TRUE)); | |
122 | - hash_put(self, "-t", NFUN_NEW_GC(cmd_condition_t, NULL, TRUE)); | |
123 | - hash_put(self, "-S", NFUN_NEW_GC(cmd_condition_s2, NULL, TRUE)); | |
124 | - hash_put(self, "-g", NFUN_NEW_GC(cmd_condition_g, NULL, TRUE)); | |
125 | - hash_put(self, "-k", NFUN_NEW_GC(cmd_condition_k, NULL, TRUE)); | |
126 | - hash_put(self, "-u", NFUN_NEW_GC(cmd_condition_u, NULL, TRUE)); | |
127 | - hash_put(self, "-r", NFUN_NEW_GC(cmd_condition_r, NULL, TRUE)); | |
128 | - hash_put(self, "-w", NFUN_NEW_GC(cmd_condition_w, NULL, TRUE)); | |
129 | - hash_put(self, "-x", NFUN_NEW_GC(cmd_condition_x, NULL, TRUE)); | |
130 | - hash_put(self, "-O", NFUN_NEW_GC(cmd_condition_o, NULL, TRUE)); | |
131 | - hash_put(self, "-G", NFUN_NEW_GC(cmd_condition_g2, NULL, TRUE)); | |
132 | - hash_put(self, "-e", NFUN_NEW_GC(cmd_condition_e, NULL, TRUE)); | |
133 | - hash_put(self, "-s", NFUN_NEW_GC(cmd_condition_s, NULL, TRUE)); | |
134 | - hash_put(self, "=", NFUN_NEW_GC(cmd_condition_eq, NULL, TRUE)); | |
135 | - hash_put(self, "!=", NFUN_NEW_GC(cmd_condition_neq, NULL, TRUE)); | |
136 | - hash_put(self, "-slt", NFUN_NEW_GC(cmd_condition_slt, NULL, TRUE)); | |
137 | - hash_put(self, "-sgt", NFUN_NEW_GC(cmd_condition_sgt, NULL, TRUE)); | |
138 | - hash_put(self, "-sle", NFUN_NEW_GC(cmd_condition_sle, NULL, TRUE)); | |
139 | - hash_put(self, "-sge", NFUN_NEW_GC(cmd_condition_sge, NULL, TRUE)); | |
140 | - hash_put(self, "-eq", NFUN_NEW_GC(cmd_condition_eq2, NULL, TRUE)); | |
141 | - hash_put(self, "-ne", NFUN_NEW_GC(cmd_condition_ne, NULL, TRUE)); | |
142 | - hash_put(self, "-lt", NFUN_NEW_GC(cmd_condition_lt, NULL, TRUE)); | |
143 | - hash_put(self, "-le", NFUN_NEW_GC(cmd_condition_le, NULL, TRUE)); | |
144 | - hash_put(self, "-gt", NFUN_NEW_GC(cmd_condition_gt, NULL, TRUE)); | |
145 | - hash_put(self, "-ge", NFUN_NEW_GC(cmd_condition_ge, NULL, TRUE)); | |
146 | - hash_put(self, "-nt", NFUN_NEW_GC(cmd_condition_nt, NULL, TRUE)); | |
147 | - hash_put(self, "-ot", NFUN_NEW_GC(cmd_condition_ot, NULL, TRUE)); | |
148 | - hash_put(self, "-ef", NFUN_NEW_GC(cmd_condition_ef, NULL, TRUE)); | |
149 | - hash_put(self, "=~", NFUN_NEW_GC(cmd_condition_re, NULL, TRUE)); | |
150 | - hash_put(self, "++", NFUN_NEW_GC(cmd_plusplus, NULL, TRUE)); | |
151 | - hash_put(self, "--", NFUN_NEW_GC(cmd_minusminus, NULL, TRUE)); | |
152 | - hash_put(self, "+", NFUN_NEW_GC(cmd_plus, NULL, TRUE)); | |
153 | - hash_put(self, "-", NFUN_NEW_GC(cmd_minus, NULL, TRUE)); | |
154 | - hash_put(self, "*", NFUN_NEW_GC(cmd_mult, NULL, TRUE)); | |
155 | - hash_put(self, "/", NFUN_NEW_GC(cmd_div, NULL, TRUE)); | |
156 | - hash_put(self, "mod", NFUN_NEW_GC(cmd_mod, NULL, TRUE)); | |
157 | - hash_put(self, "pow", NFUN_NEW_GC(cmd_pow, NULL, TRUE)); | |
158 | - hash_put(self, "abs", NFUN_NEW_GC(cmd_abs, NULL, TRUE)); | |
159 | - hash_put(self, "selector", NFUN_NEW_GC(cmd_selector, NULL, TRUE)); | |
160 | - hash_put(self, "sort", NFUN_NEW_GC(cmd_sort, NULL, TRUE)); | |
161 | - hash_put(self, "readline", NFUN_NEW_GC(cmd_readline, NULL, TRUE)); | |
162 | -#if defined(HAVE_MIGEMO_H) | |
163 | - hash_put(self, "migemo_match", NFUN_NEW_GC(cmd_migemo_match, NULL, TRUE)); | |
164 | -#endif | |
165 | - | |
166 | - hash_put(self, "sub", NFUN_NEW_GC(cmd_sub, NULL, TRUE)); | |
167 | - hash_put(self, "time", NFUN_NEW_GC(cmd_time, NULL, TRUE)); | |
168 | - | |
169 | - sObject* nfun = NFUN_NEW_GC(cmd_hash, NULL, TRUE); | |
170 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-key")); | |
171 | - hash_put(self, "hash", nfun); | |
172 | - nfun = NFUN_NEW_GC(cmd_ary, NULL, TRUE); | |
173 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-index")); | |
174 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-append")); | |
175 | - hash_put(self, "ary", nfun); | |
176 | - | |
177 | - nfun = NFUN_NEW_GC(cmd_var, NULL, TRUE); | |
178 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-index")); | |
179 | - hash_put(self, "var", nfun); | |
180 | - | |
181 | - nfun = NFUN_NEW_GC(cmd_add, NULL, TRUE); | |
182 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
183 | - hash_put(self, "add", nfun); | |
184 | - | |
185 | - nfun = NFUN_NEW_GC(cmd_del, NULL, TRUE); | |
186 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
187 | - hash_put(self, "del", nfun); | |
188 | - | |
189 | - nfun = NFUN_NEW_GC(cmd_index, NULL, TRUE); | |
190 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
191 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-count")); | |
192 | - hash_put(self, "index", nfun); | |
193 | - | |
194 | - nfun = NFUN_NEW_GC(cmd_rindex, NULL, TRUE); | |
195 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
196 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-count")); | |
197 | - hash_put(self, "rindex", nfun); | |
198 | - | |
199 | - nfun = NFUN_NEW_GC(cmd_each, NULL, TRUE); | |
200 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
201 | - hash_put(self, "each", nfun); | |
202 | - | |
203 | - nfun = NFUN_NEW_GC(cmd_def, NULL, TRUE); | |
204 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-option-with-argument")); | |
205 | - hash_put(self, "def", nfun); | |
206 | - | |
207 | - nfun = NFUN_NEW_GC(cmd_class, NULL, TRUE); | |
208 | - (void)nfun_put_option_with_argument(nfun, STRDUP("-option-with-argument")); | |
209 | - hash_put(self, "class", nfun); | |
210 | - | |
211 | - clear_matching_info_variable(); | |
212 | -} | |
213 | - | |
214 | -void uobject_init(sObject* self) | |
215 | -{ | |
216 | - hash_put(self, "run", NFUN_NEW_GC(cmd_mrun, NULL, FALSE)); | |
217 | - hash_put(self, "self", self); | |
218 | - hash_put(self, "root", gRootObject); | |
219 | - hash_put(self, "parent", SUOBJECT(self).mParent); | |
220 | - hash_put(self, "show", NFUN_NEW_GC(cmd_mshow, NULL, FALSE)); | |
221 | -} | |
222 | - | |
223 | -void uobject_delete_gc(sObject* self) | |
224 | -{ | |
225 | - hash_it* it = SHASH(self).mEntryIt; | |
226 | - | |
227 | - while(it) { | |
228 | - hash_it* next_it = it->mNextIt; | |
229 | - hash_it_release(it, self); | |
230 | - it = next_it; | |
231 | - } | |
232 | - | |
233 | - FREE(SHASH(self).mTable); | |
234 | - FREE(SUOBJECT(self).mName); | |
235 | -} | |
236 | - | |
237 | -void uobject_delete_stack(sObject* self) | |
238 | -{ | |
239 | - hash_it* it = SHASH(self).mEntryIt; | |
240 | - | |
241 | - while(it) { | |
242 | - hash_it* next_it = it->mNextIt; | |
243 | - hash_it_release(it, self); | |
244 | - it = next_it; | |
245 | - } | |
246 | - | |
247 | - FREE(SHASH(self).mTable); | |
248 | - FREE(SUOBJECT(self).mName); | |
249 | -} | |
250 | - | |
251 | -int uobject_gc_children_mark(sObject* self) | |
252 | -{ | |
253 | - int count = 0; | |
254 | - | |
255 | - hash_it* it = SHASH(self).mEntryIt; | |
256 | - while(it) { | |
257 | - sObject* item = it->mItem; | |
258 | - | |
259 | - if((item->mFlg & GC_MARK) == 0) { | |
260 | - item->mFlg |= GC_MARK; | |
261 | - count++; | |
262 | - | |
263 | - count += object_gc_children_mark(item); | |
264 | - } | |
265 | - | |
266 | - it = it->mNextIt; | |
267 | - } | |
268 | - | |
269 | - return count; | |
270 | -} | |
271 | - | |
272 | 6 | sObject* nfun_new_from_gc(fXyzshNativeFun fun, sObject* parent, BOOL user_object) |
273 | 7 | { |
274 | 8 | sObject* self = gc_get_free_object(T_NFUN, user_object); |
@@ -370,12 +104,12 @@ sObject* access_object(char* name, sObject** current, sObject* running_object) | ||
370 | 104 | { |
371 | 105 | sObject* object; |
372 | 106 | if(running_object) { |
373 | - object = hash_item(SFUN(running_object).mLocalObjects, name); | |
107 | + object = uobject_item(SFUN(running_object).mLocalObjects, name); | |
374 | 108 | if(object) { return object; } |
375 | 109 | } |
376 | 110 | |
377 | 111 | while(1) { |
378 | - object = hash_item(*current, name); | |
112 | + object = uobject_item(*current, name); | |
379 | 113 | |
380 | 114 | if(object || *current == gRootObject) { return object; } |
381 | 115 |
@@ -385,10 +119,10 @@ sObject* access_object(char* name, sObject** current, sObject* running_object) | ||
385 | 119 | |
386 | 120 | sObject* access_object2(char* name, sObject* current, sObject* running_object) |
387 | 121 | { |
388 | - sObject* object = hash_item(SFUN(running_object).mLocalObjects, name); | |
122 | + sObject* object = uobject_item(SFUN(running_object).mLocalObjects, name); | |
389 | 123 | if(object) return object; |
390 | 124 | |
391 | - return hash_item(current, name); | |
125 | + return uobject_item(current, name); | |
392 | 126 | } |
393 | 127 | |
394 | 128 | sObject* access_object3(char* name, sObject** current) |
@@ -396,7 +130,7 @@ sObject* access_object3(char* name, sObject** current) | ||
396 | 130 | sObject* object; |
397 | 131 | |
398 | 132 | while(1) { |
399 | - object = hash_item(*current, name); | |
133 | + object = uobject_item(*current, name); | |
400 | 134 | |
401 | 135 | if(object || *current == gRootObject) { return object; } |
402 | 136 |
@@ -865,7 +865,7 @@ static BOOL read_command(char** p, sCommand* command, sStatment* statment, sObje | ||
865 | 865 | if(object && TYPE(object) == T_UOBJECT) { |
866 | 866 | int i; |
867 | 867 | for(i=1; i<command->mMessagesNum; i++) { |
868 | - object = hash_item(object, command->mMessages[i]); | |
868 | + object = uobject_item(object, command->mMessages[i]); | |
869 | 869 | |
870 | 870 | if(object == NULL || TYPE(object) != T_UOBJECT) { |
871 | 871 | break; |
@@ -57,7 +57,7 @@ static char* message_completion(const char* text, int stat) | ||
57 | 57 | sObject* messages = STRING_NEW_STACK(""); |
58 | 58 | |
59 | 59 | while(1) { |
60 | - object = hash_item(current, command->mMessages[0]); | |
60 | + object = uobject_item(current, command->mMessages[0]); | |
61 | 61 | if(object || current == gRootObject) break; |
62 | 62 | current = SUOBJECT((current)).mParent; |
63 | 63 | } |
@@ -68,17 +68,17 @@ static char* message_completion(const char* text, int stat) | ||
68 | 68 | if(object && TYPE(object) == T_UOBJECT) { |
69 | 69 | int i; |
70 | 70 | for(i=1; i<command->mMessagesNum; i++) { |
71 | - object = hash_item(object, command->mMessages[i]); | |
71 | + object = uobject_item(object, command->mMessages[i]); | |
72 | 72 | if(object == NULL || TYPE(object) != T_UOBJECT) break; |
73 | 73 | string_push_back(messages, command->mMessages[i]); |
74 | 74 | string_push_back(messages, "::"); |
75 | 75 | } |
76 | 76 | |
77 | 77 | if(object && TYPE(object) == T_UOBJECT) { |
78 | - hash_it* it = hash_loop_begin(object); | |
78 | + uobject_it* it = uobject_loop_begin(object); | |
79 | 79 | while(it) { |
80 | - char* key = hash_loop_key(it); | |
81 | - sObject* item = hash_loop_item(it); | |
80 | + char* key = uobject_loop_key(it); | |
81 | + sObject* item = uobject_loop_item(it); | |
82 | 82 | |
83 | 83 | sObject* candidate = STRING_NEW_STACK(string_c_str(messages)); |
84 | 84 | string_push_back(candidate, key); |
@@ -96,7 +96,7 @@ static char* message_completion(const char* text, int stat) | ||
96 | 96 | vector_add(gCompletionArray, string_c_str(candidate)); |
97 | 97 | } |
98 | 98 | |
99 | - it = hash_loop_next(it); | |
99 | + it = uobject_loop_next(it); | |
100 | 100 | } |
101 | 101 | |
102 | 102 | vector_sort(gCompletionArray, name_sort); |
@@ -136,21 +136,21 @@ static char* all_program_completion(const char* text, int stat) | ||
136 | 136 | |
137 | 137 | sObject* current = gReadlineCurrentObject; |
138 | 138 | while(1) { |
139 | - hash_it* it = hash_loop_begin(current); | |
139 | + uobject_it* it = uobject_loop_begin(current); | |
140 | 140 | while(it) { |
141 | - char* key = hash_loop_key(it); | |
142 | - sObject* object = hash_loop_item(it); | |
141 | + char* key = uobject_loop_key(it); | |
142 | + sObject* object = uobject_loop_item(it); | |
143 | 143 | |
144 | 144 | if(hash_item(hash, key) == NULL) { |
145 | 145 | hash_put(hash, key, object); |
146 | 146 | |
147 | - sObject* candidate = STRING_NEW_STACK(hash_loop_key(it)); | |
147 | + sObject* candidate = STRING_NEW_STACK(uobject_loop_key(it)); | |
148 | 148 | if(TYPE(object) == T_UOBJECT) { |
149 | - if(hash_item(object, "main")) { | |
149 | + if(uobject_item(object, "main")) { | |
150 | 150 | vector_add(gCompletionArray, string_c_str(candidate)); |
151 | 151 | } |
152 | 152 | else { |
153 | - sObject* candidate2 = STRING_NEW_STACK(hash_loop_key(it)); | |
153 | + sObject* candidate2 = STRING_NEW_STACK(uobject_loop_key(it)); | |
154 | 154 | string_push_back(candidate2, "::"); |
155 | 155 | vector_add(gCompletionArray, string_c_str(candidate2)); |
156 | 156 | } |
@@ -160,7 +160,7 @@ static char* all_program_completion(const char* text, int stat) | ||
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | - it = hash_loop_next(it); | |
163 | + it = uobject_loop_next(it); | |
164 | 164 | } |
165 | 165 | |
166 | 166 | if(current == gRootObject) break; |
@@ -193,21 +193,21 @@ static char* program_completion(const char* text, int stat) | ||
193 | 193 | |
194 | 194 | sObject* current = gReadlineCurrentObject; |
195 | 195 | while(1) { |
196 | - hash_it* it = hash_loop_begin(current); | |
196 | + uobject_it* it = uobject_loop_begin(current); | |
197 | 197 | while(it) { |
198 | - char* key = hash_loop_key(it); | |
199 | - sObject* object = hash_loop_item(it); | |
198 | + char* key = uobject_loop_key(it); | |
199 | + sObject* object = uobject_loop_item(it); | |
200 | 200 | |
201 | 201 | if(hash_item(hash, key) == NULL) { |
202 | 202 | hash_put(hash, key, object); |
203 | 203 | |
204 | - sObject* candidate = STRING_NEW_STACK(hash_loop_key(it)); | |
204 | + sObject* candidate = STRING_NEW_STACK(uobject_loop_key(it)); | |
205 | 205 | if(TYPE(object) == T_UOBJECT) { |
206 | - if(hash_item(object, "main")) { | |
206 | + if(uobject_item(object, "main")) { | |
207 | 207 | vector_add(gCompletionArray, string_c_str(candidate)); |
208 | 208 | } |
209 | 209 | else { |
210 | - sObject* candidate2 = STRING_NEW_STACK(hash_loop_key(it)); | |
210 | + sObject* candidate2 = STRING_NEW_STACK(uobject_loop_key(it)); | |
211 | 211 | string_push_back(candidate2, "::"); |
212 | 212 | vector_add(gCompletionArray, string_c_str(candidate2)); |
213 | 213 | } |
@@ -217,7 +217,7 @@ static char* program_completion(const char* text, int stat) | ||
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - it = hash_loop_next(it); | |
220 | + it = uobject_loop_next(it); | |
221 | 221 | } |
222 | 222 | |
223 | 223 | if(current == gRootObject) break; |
@@ -328,23 +328,23 @@ static char* env_completion(const char* text, int stat_) | ||
328 | 328 | |
329 | 329 | sObject* current = gReadlineCurrentObject; |
330 | 330 | while(1) { |
331 | - hash_it* it = hash_loop_begin(current); | |
331 | + uobject_it* it = uobject_loop_begin(current); | |
332 | 332 | while(it) { |
333 | - char* key = hash_loop_key(it); | |
334 | - sObject* object = hash_loop_item(it); | |
333 | + char* key = uobject_loop_key(it); | |
334 | + sObject* object = uobject_loop_item(it); | |
335 | 335 | |
336 | 336 | if(hash_item(hash, key) == NULL) { |
337 | 337 | if(TYPE(object) == T_STRING || TYPE(object) == T_VECTOR || TYPE(object) == T_HASH) { |
338 | 338 | hash_put(hash, key, object); |
339 | 339 | |
340 | 340 | sObject* candidate = STRING_NEW_STACK(""); |
341 | - string_push_back(candidate, hash_loop_key(it)); | |
341 | + string_push_back(candidate, uobject_loop_key(it)); | |
342 | 342 | |
343 | 343 | vector_add(gCompletionArray, string_c_str(candidate)); |
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | - it = hash_loop_next(it); | |
347 | + it = uobject_loop_next(it); | |
348 | 348 | } |
349 | 349 | |
350 | 350 | if(current == gRootObject) break; |
@@ -407,7 +407,7 @@ static void get_current_completion_object(sObject** completion_object, sObject** | ||
407 | 407 | if(*current_object != gRootObject) { |
408 | 408 | sObject* parent_object = SUOBJECT(*current_object).mParent; |
409 | 409 | get_current_completion_object(completion_object, &parent_object); |
410 | - if(*completion_object) *completion_object = hash_item(*completion_object, SUOBJECT(*current_object).mName); | |
410 | + if(*completion_object) *completion_object = uobject_item(*completion_object, SUOBJECT(*current_object).mName); | |
411 | 411 | } |
412 | 412 | } |
413 | 413 |
@@ -416,7 +416,7 @@ static sObject* access_object_compl(char* name, sObject** current) | ||
416 | 416 | sObject* object; |
417 | 417 | |
418 | 418 | while(1) { |
419 | - object = hash_item(*current, name); | |
419 | + object = uobject_item(*current, name); | |
420 | 420 | |
421 | 421 | if(object || *current == gCompletionObject) { return object; } |
422 | 422 |
@@ -511,7 +511,7 @@ char** readline_on_complete(const char* text, int start, int end) | ||
511 | 511 | int i; |
512 | 512 | for(i=1; i<command->mMessagesNum; i++) { |
513 | 513 | if(object && TYPE(object) == T_UOBJECT) { |
514 | - object = hash_item(object, command->mMessages[i]); | |
514 | + object = uobject_item(object, command->mMessages[i]); | |
515 | 515 | } |
516 | 516 | else { |
517 | 517 | break; |
@@ -519,10 +519,10 @@ char** readline_on_complete(const char* text, int start, int end) | ||
519 | 519 | } |
520 | 520 | |
521 | 521 | if(object && TYPE(object) == T_UOBJECT) { |
522 | - ucompletion = hash_item(object, command->mArgs[0]); | |
522 | + ucompletion = uobject_item(object, command->mArgs[0]); | |
523 | 523 | |
524 | 524 | if(ucompletion == NULL) { |
525 | - ucompletion = hash_item(object, "__all__");; | |
525 | + ucompletion = uobject_item(object, "__all__");; | |
526 | 526 | } |
527 | 527 | } |
528 | 528 | else { |
@@ -599,7 +599,7 @@ char** readline_on_complete(const char* text, int start, int end) | ||
599 | 599 | vector_add(argv, STRING_NEW_GC("", FALSE)); |
600 | 600 | vector_add(argv, STRING_NEW_GC("", FALSE)); |
601 | 601 | } |
602 | - hash_put(SFUN(fun).mLocalObjects, "ARGV", argv); | |
602 | + uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv); | |
603 | 603 | |
604 | 604 | int rcode = 0; |
605 | 605 | xyzsh_set_signal(); |
@@ -607,12 +607,12 @@ char** readline_on_complete(const char* text, int start, int end) | ||
607 | 607 | readline_signal(); |
608 | 608 | fprintf(stderr, "\nrun time error\n"); |
609 | 609 | fprintf(stderr, "%s", string_c_str(gErrMsg)); |
610 | - vector_pop_back(gStackFrames); | |
610 | + (void)vector_pop_back(gStackFrames); | |
611 | 611 | stack_end_stack(); |
612 | 612 | return NULL; |
613 | 613 | } |
614 | + (void)vector_pop_back(gStackFrames); | |
614 | 615 | readline_signal(); |
615 | - vector_pop_back(gStackFrames); | |
616 | 616 | |
617 | 617 | fd_split(nextout, kLF); |
618 | 618 |
@@ -649,10 +649,10 @@ BOOL cmd_completion(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
649 | 649 | } |
650 | 650 | p+=2; |
651 | 651 | |
652 | - sObject* object2 = hash_item(object, string_c_str(str)); | |
652 | + sObject* object2 = uobject_item(object, string_c_str(str)); | |
653 | 653 | if(object2 == NULL || TYPE(object2) !=T_UOBJECT) { |
654 | 654 | sObject* new_object = UOBJECT_NEW_GC(8, object, string_c_str(str), TRUE); |
655 | - hash_put(object, string_c_str(str), new_object); | |
655 | + uobject_put(object, string_c_str(str), new_object); | |
656 | 656 | uobject_init(new_object); |
657 | 657 | |
658 | 658 | object = new_object; |
@@ -668,7 +668,7 @@ BOOL cmd_completion(sObject* nextin, sObject* nextout, sRunInfo* runinfo) | ||
668 | 668 | } |
669 | 669 | } |
670 | 670 | if(object && TYPE(object) == T_UOBJECT && string_c_str(str)[0] != 0) { |
671 | - hash_put(object, string_c_str(str), COMPLETION_NEW_GC(block, FALSE)); | |
671 | + uobject_put(object, string_c_str(str), COMPLETION_NEW_GC(block, FALSE)); | |
672 | 672 | } |
673 | 673 | else { |
674 | 674 | err_msg("There is no object", runinfo->mSName, runinfo->mSLine, command->mArgsRuntime[i]); |
@@ -818,9 +818,9 @@ static int readline_macro(int count, int key) | ||
818 | 818 | fprintf(stderr, "%s", string_c_str(gErrMsg)); |
819 | 819 | } |
820 | 820 | } |
821 | + (void)vector_pop_back(gStackFrames); | |
821 | 822 | readline_signal(); |
822 | 823 | //xyzsh_restore_signal_default(); |
823 | - (void)vector_pop_back(gStackFrames); | |
824 | 824 | } |
825 | 825 | else { |
826 | 826 | fprintf(stderr, "parser error\n"); |
@@ -39,7 +39,7 @@ void run_init(enum eAppType app_type) | ||
39 | 39 | gStdout = FD_NEW_STACK(kFDKindBuf, 0); |
40 | 40 | gStderr = FD_NEW_STACK(kFDKindBuf, 0); |
41 | 41 | gJobs = VECTOR_NEW_GC(16, FALSE); |
42 | - hash_put(gxyzshObject, "_jobs", gJobs); | |
42 | + uobject_put(gxyzshObject, "_jobs", gJobs); | |
43 | 43 | |
44 | 44 | xyzsh_job_done = NULL; |
45 | 45 |
@@ -811,7 +811,7 @@ BOOL run_function(sObject* fun, sObject* nextin, sObject* nextout, sRunInfo* run | ||
811 | 811 | for(i=0; i<argc; i++) { |
812 | 812 | vector_add(argv2, STRING_NEW_GC(argv[i], FALSE)); |
813 | 813 | } |
814 | - hash_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
814 | + uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
815 | 815 | |
816 | 816 | sCommand* command = runinfo->mCommand; |
817 | 817 | sObject* options = HASH_NEW_GC(16, FALSE); |
@@ -825,7 +825,7 @@ BOOL run_function(sObject* fun, sObject* nextin, sObject* nextout, sRunInfo* run | ||
825 | 825 | } |
826 | 826 | } |
827 | 827 | } |
828 | - hash_put(SFUN(fun).mLocalObjects, "OPTIONS", options); | |
828 | + uobject_put(SFUN(fun).mLocalObjects, "OPTIONS", options); | |
829 | 829 | |
830 | 830 | sObject* arg_blocks = SFUN(fun).mArgBlocks; |
831 | 831 | SFUN(fun).mArgBlocks = VECTOR_NEW_GC(16, FALSE); |
@@ -849,10 +849,10 @@ BOOL run_function(sObject* fun, sObject* nextin, sObject* nextout, sRunInfo* run | ||
849 | 849 | } |
850 | 850 | } |
851 | 851 | |
852 | -runinfo->mRCode = rcode; | |
853 | - | |
854 | 852 | (void)vector_pop_back(gStackFrames); |
855 | 853 | |
854 | +runinfo->mRCode = rcode; | |
855 | + | |
856 | 856 | SFUN(fun).mLocalObjects = local_objects; |
857 | 857 | SFUN(fun).mArgBlocks = arg_blocks; |
858 | 858 | SFUN(fun).mRunInfo = runinfo2; |
@@ -955,7 +955,7 @@ static BOOL run_object(sObject* object, sObject* nextin, sObject* nextout, sRunI | ||
955 | 955 | break; |
956 | 956 | |
957 | 957 | case T_UOBJECT: { |
958 | - sObject* main_obj = hash_item(object, "main"); | |
958 | + sObject* main_obj = uobject_item(object, "main"); | |
959 | 959 | runinfo->mRecieverObject = object; |
960 | 960 | |
961 | 961 | if(main_obj) { |
@@ -1254,7 +1254,7 @@ static BOOL statment_tree(sStatment* statment, sObject* pipein, sObject* pipeout | ||
1254 | 1254 | while(i < command->mMessagesNum) { |
1255 | 1255 | if(object && TYPE(object) == T_UOBJECT) { |
1256 | 1256 | reciever = object; |
1257 | - object = hash_item(object, command->mMessages[i++]); | |
1257 | + object = uobject_item(object, command->mMessages[i++]); | |
1258 | 1258 | } |
1259 | 1259 | else { |
1260 | 1260 | err_msg("invalid message passing", runinfo->mSName, runinfo->mSLine, command->mArgs[0]); |
@@ -1264,7 +1264,7 @@ static BOOL statment_tree(sStatment* statment, sObject* pipein, sObject* pipeout | ||
1264 | 1264 | |
1265 | 1265 | if(object && TYPE(object) == T_UOBJECT) { |
1266 | 1266 | reciever = object; |
1267 | - object = hash_item(object, command->mArgs[0]); | |
1267 | + object = uobject_item(object, command->mArgs[0]); | |
1268 | 1268 | |
1269 | 1269 | if(object == gInherit) { |
1270 | 1270 | sObject* running_object = runinfo->mRunningObject; |
@@ -1724,7 +1724,7 @@ BOOL load_file(char* fname, sObject* nextin, sObject* nextout, sRunInfo* runinfo | ||
1724 | 1724 | for(i=0; i<argc; i++) { |
1725 | 1725 | vector_add(argv2, STRING_NEW_GC(argv[i], FALSE)); |
1726 | 1726 | } |
1727 | - hash_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
1727 | + uobject_put(SFUN(fun).mLocalObjects, "ARGV", argv2); | |
1728 | 1728 | |
1729 | 1729 | if(!run(block, nextin, nextout, &rcode, runinfo->mCurrentObject, fun)) |
1730 | 1730 | { |
@@ -1733,22 +1733,21 @@ BOOL load_file(char* fname, sObject* nextin, sObject* nextout, sRunInfo* runinfo | ||
1733 | 1733 | else { |
1734 | 1734 | runinfo->mRCode = rcode; |
1735 | 1735 | |
1736 | - stack_end_stack(); | |
1737 | 1736 | (void)vector_pop_back(gStackFrames); |
1737 | + stack_end_stack(); | |
1738 | 1738 | return FALSE; |
1739 | 1739 | } |
1740 | 1740 | } |
1741 | + (void)vector_pop_back(gStackFrames); | |
1741 | 1742 | } |
1742 | 1743 | else { |
1743 | 1744 | FREE(buf); |
1744 | 1745 | sCommand* command = runinfo->mCommand; |
1745 | 1746 | err_msg_adding("parser error", runinfo->mSName, runinfo->mSLine, "parser"); |
1746 | 1747 | stack_end_stack(); |
1747 | - (void)vector_pop_back(gStackFrames); | |
1748 | 1748 | return FALSE; |
1749 | 1749 | } |
1750 | 1750 | |
1751 | - (void)vector_pop_back(gStackFrames); | |
1752 | 1751 | stack_end_stack(); |
1753 | 1752 | |
1754 | 1753 | return TRUE; |
@@ -0,0 +1,428 @@ | ||
1 | +#include "config.h" | |
2 | +#include "xyzsh/xyzsh.h" | |
3 | +#include <string.h> | |
4 | +#include <stdio.h> | |
5 | +#include <assert.h> | |
6 | + | |
7 | +static unsigned int get_uobject_value(sObject* self, char* key) | |
8 | +{ | |
9 | + unsigned int i = 0; | |
10 | + while(*key) { | |
11 | + i += *key; | |
12 | + key++; | |
13 | + } | |
14 | + | |
15 | + return i % SUOBJECT(self).mTableSize; | |
16 | +} | |
17 | + | |
18 | +static void resize(sObject* self) | |
19 | +{ | |
20 | + const int table_size = SUOBJECT(self).mTableSize; | |
21 | + | |
22 | + SUOBJECT(self).mTableSize *= 5; | |
23 | + FREE(SUOBJECT(self).mTable); | |
24 | + SUOBJECT(self).mTable = (uobject_it**)MALLOC(sizeof(uobject_it*) * SUOBJECT(self).mTableSize); | |
25 | + memset(SUOBJECT(self).mTable, 0, sizeof(uobject_it*)*SUOBJECT(self).mTableSize); | |
26 | + | |
27 | + uobject_it* it = SUOBJECT(self).mEntryIt; | |
28 | + while(it) { | |
29 | + unsigned int uobject_key = get_uobject_value(self, it->mKey); | |
30 | + | |
31 | + it->mCollisionIt = SUOBJECT(self).mTable[uobject_key]; | |
32 | + | |
33 | + SUOBJECT(self).mTable[uobject_key] = it; | |
34 | + | |
35 | + it = it->mNextIt; | |
36 | + } | |
37 | +} | |
38 | + | |
39 | + | |
40 | +uobject_it* uobject_it_new(char* key, void* item, uobject_it* coll_it, uobject_it* next_it, sObject* hash) | |
41 | +{ | |
42 | + uobject_it* it = (uobject_it*)MALLOC(sizeof(uobject_it)); | |
43 | + | |
44 | + it->mKey = STRDUP(key); | |
45 | + | |
46 | + it->mItem = item; | |
47 | + it->mCollisionIt = coll_it; | |
48 | + | |
49 | + it->mNextIt = next_it; | |
50 | + | |
51 | + return it; | |
52 | +} | |
53 | + | |
54 | +void uobject_it_release(uobject_it* it, sObject* hash) | |
55 | +{ | |
56 | + FREE(it->mKey); | |
57 | + | |
58 | + FREE(it); | |
59 | +} | |
60 | + | |
61 | + | |
62 | +sObject* uobject_new_from_gc(int size, sObject* parent, char* name, BOOL user_object) | |
63 | +{ | |
64 | + sObject* self = gc_get_free_object(T_UOBJECT, user_object); | |
65 | + | |
66 | + SUOBJECT(self).mTableSize = size; | |
67 | + SUOBJECT(self).mTable = (uobject_it**)MALLOC(sizeof(uobject_it*) * size); | |
68 | + memset(SUOBJECT(self).mTable, 0, sizeof(uobject_it*)*size); | |
69 | + | |
70 | + SUOBJECT(self).mEntryIt = NULL; | |
71 | + | |
72 | + SUOBJECT(self).mCounter = 0; | |
73 | + | |
74 | + if(parent) SUOBJECT(self).mParent = parent; else SUOBJECT(self).mParent = self; | |
75 | + | |
76 | + SUOBJECT(self).mName = STRDUP(name); | |
77 | + | |
78 | + return self; | |
79 | +} | |
80 | + | |
81 | +sObject* uobject_new_from_stack(int size, sObject* parent, char* name) | |
82 | +{ | |
83 | + sObject* self = stack_get_free_object(T_UOBJECT); | |
84 | + | |
85 | + SUOBJECT(self).mTableSize = size; | |
86 | + SUOBJECT(self).mTable = (uobject_it**)MALLOC(sizeof(uobject_it*) * size); | |
87 | + memset(SUOBJECT(self).mTable, 0, sizeof(uobject_it*)*size); | |
88 | + | |
89 | + SUOBJECT(self).mEntryIt = NULL; | |
90 | + | |
91 | + SUOBJECT(self).mCounter = 0; | |
92 | + | |
93 | + if(parent) SUOBJECT(self).mParent = parent; else SUOBJECT(self).mParent = self; | |
94 | + | |
95 | + SUOBJECT(self).mName = STRDUP(name); | |
96 | + | |
97 | + return self; | |
98 | +} | |
99 | + | |
100 | +sObject* gInherit; | |
101 | + | |
102 | +void uobject_root_init(sObject* self) | |
103 | +{ | |
104 | + assert(TYPE(self) == T_UOBJECT); | |
105 | + | |
106 | + uobject_put(self, "unset", NFUN_NEW_GC(cmd_unset, NULL, TRUE)); | |
107 | + sObject* readline = UOBJECT_NEW_GC(8, self, "rl", TRUE); | |
108 | + uobject_init(readline); | |
109 | + uobject_put(self, "rl", readline); | |
110 | + | |
111 | + uobject_put(readline, "insert_text", NFUN_NEW_GC(cmd_readline_insert_text, NULL, TRUE)); | |
112 | + uobject_put(readline, "delete_text", NFUN_NEW_GC(cmd_readline_delete_text, NULL, TRUE)); | |
113 | + uobject_put(readline, "clear_screen", NFUN_NEW_GC(cmd_readline_clear_screen, NULL, TRUE)); | |
114 | + uobject_put(readline, "point_move", NFUN_NEW_GC(cmd_readline_point_move, NULL, TRUE)); | |
115 | + uobject_put(readline, "read_history", NFUN_NEW_GC(cmd_readline_read_history, NULL, TRUE)); | |
116 | + uobject_put(readline, "write_history", NFUN_NEW_GC(cmd_readline_write_history, NULL, TRUE)); | |
117 | + uobject_put(self, "completion", NFUN_NEW_GC(cmd_completion, NULL, TRUE)); | |
118 | + uobject_put(self, "p", NFUN_NEW_GC(cmd_p, NULL, TRUE)); | |
119 | + uobject_put(self, "jobs", NFUN_NEW_GC(cmd_jobs, NULL, TRUE)); | |
120 | + uobject_put(self, "gcinfo", NFUN_NEW_GC(cmd_gcinfo, NULL, TRUE)); | |
121 | + uobject_put(self, "stackinfo", NFUN_NEW_GC(cmd_stackinfo, NULL, TRUE)); | |
122 | + uobject_put(self, "fg", NFUN_NEW_GC(cmd_fg, NULL, TRUE)); | |
123 | + uobject_put(self, "exit", NFUN_NEW_GC(cmd_exit, NULL, TRUE)); | |
124 | + uobject_put(self, "fselector", NFUN_NEW_GC(cmd_fselector, NULL, TRUE)); | |
125 | + uobject_put(self, "sweep", NFUN_NEW_GC(cmd_sweep, NULL, TRUE)); | |
126 | + uobject_put(self, "subshell", NFUN_NEW_GC(cmd_subshell, NULL, TRUE)); | |
127 | + uobject_put(self, "print", NFUN_NEW_GC(cmd_print, NULL, TRUE)); | |
128 | + uobject_put(self, "if", NFUN_NEW_GC(cmd_if, NULL, TRUE)); | |
129 | + uobject_put(self, "break", NFUN_NEW_GC(cmd_break, NULL, TRUE)); | |
130 | + uobject_put(self, "while", NFUN_NEW_GC(cmd_while, NULL, TRUE)); | |
131 | + uobject_put(self, "return", NFUN_NEW_GC(cmd_return, NULL, TRUE)); | |
132 | + uobject_put(self, "rehash", NFUN_NEW_GC(cmd_rehash, NULL, TRUE)); | |
133 | + uobject_put(self, "true", NFUN_NEW_GC(cmd_true, NULL, TRUE)); | |
134 | + uobject_put(self, "false", NFUN_NEW_GC(cmd_false, NULL, TRUE)); | |
135 | + uobject_put(self, "write", NFUN_NEW_GC(cmd_write, NULL, TRUE)); | |
136 | + uobject_put(self, "quote", NFUN_NEW_GC(cmd_quote, NULL, TRUE)); | |
137 | + uobject_put(self, "load", NFUN_NEW_GC(cmd_load, NULL, TRUE)); | |
138 | + gInherit = NFUN_NEW_GC(cmd_inherit, NULL, TRUE); | |
139 | + uobject_put(self, "inherit", gInherit); | |
140 | + uobject_put(self, "eval", NFUN_NEW_GC(cmd_eval, NULL, TRUE)); | |
141 | + uobject_put(self, "object", NFUN_NEW_GC(cmd_object, NULL, TRUE)); | |
142 | + uobject_put(self, "pwo", NFUN_NEW_GC(cmd_pwo, NULL, TRUE)); | |
143 | + uobject_put(self, "co", NFUN_NEW_GC(cmd_co, NULL, TRUE)); | |
144 | + uobject_put(self, "ref", NFUN_NEW_GC(cmd_ref, NULL, TRUE)); | |
145 | + uobject_put(self, "length", NFUN_NEW_GC(cmd_length, NULL, TRUE)); | |
146 | + uobject_put(self, "export", NFUN_NEW_GC(cmd_export, NULL, TRUE)); | |
147 | + uobject_put(self, "x", NFUN_NEW_GC(cmd_x , NULL, TRUE)); | |
148 | + uobject_put(self, "stackframe", NFUN_NEW_GC(cmd_stackframe, NULL, TRUE)); | |
149 | + uobject_put(self, "msleep", NFUN_NEW_GC(cmd_msleep, NULL, TRUE)); | |
150 | + uobject_put(self, "raise", NFUN_NEW_GC(cmd_raise, NULL, TRUE)); | |
151 | + uobject_put(self, "cd", NFUN_NEW_GC(cmd_cd, NULL, TRUE)); | |
152 | + uobject_put(self, "popd", NFUN_NEW_GC(cmd_popd, NULL, TRUE)); | |
153 | + uobject_put(self, "pushd", NFUN_NEW_GC(cmd_pushd, NULL, TRUE)); | |
154 | + uobject_put(self, "block", NFUN_NEW_GC(cmd_block, NULL, TRUE)); | |
155 | + uobject_put(self, "lc", NFUN_NEW_GC(cmd_lc, NULL, TRUE)); | |
156 | + uobject_put(self, "uc", NFUN_NEW_GC(cmd_uc, NULL, TRUE)); | |
157 | + uobject_put(self, "chomp", NFUN_NEW_GC(cmd_chomp, NULL, TRUE)); | |
158 | + uobject_put(self, "chop", NFUN_NEW_GC(cmd_chop, NULL, TRUE)); | |
159 | + uobject_put(self, "pomch", NFUN_NEW_GC(cmd_pomch, NULL, TRUE)); | |
160 | + uobject_put(self, "funinfo", NFUN_NEW_GC(cmd_funinfo, NULL, TRUE)); | |
161 | + uobject_put(self, "printf", NFUN_NEW_GC(cmd_printf, NULL, TRUE)); | |
162 | + uobject_put(self, "join", NFUN_NEW_GC(cmd_join, NULL, TRUE)); | |
163 | + uobject_put(self, "lines", NFUN_NEW_GC(cmd_lines, NULL, TRUE)); | |
164 | + uobject_put(self, "rows", NFUN_NEW_GC(cmd_rows, NULL, TRUE)); | |
165 | + uobject_put(self, "scan", NFUN_NEW_GC(cmd_scan, NULL, TRUE)); | |
166 | + uobject_put(self, "split", NFUN_NEW_GC(cmd_split, NULL, TRUE)); | |
167 | + uobject_put(self, "try", NFUN_NEW_GC(cmd_try, NULL, TRUE)); | |
168 | + uobject_put(self, "errmsg", NFUN_NEW_GC(cmd_errmsg, NULL, TRUE)); | |
169 | + uobject_put(self, "prompt", NFUN_NEW_GC(cmd_prompt, NULL, TRUE)); | |
170 | + uobject_put(self, "defined", NFUN_NEW_GC(cmd_defined, NULL, TRUE)); | |
171 | + | |
172 | + uobject_put(self, "-n", NFUN_NEW_GC(cmd_condition_n, NULL, TRUE)); | |
173 | + uobject_put(self, "-z", NFUN_NEW_GC(cmd_condition_z, NULL, TRUE)); | |
174 | + uobject_put(self, "-b", NFUN_NEW_GC(cmd_condition_b, NULL, TRUE)); | |
175 | + uobject_put(self, "-c", NFUN_NEW_GC(cmd_condition_c, NULL, TRUE)); | |
176 | + uobject_put(self, "-d", NFUN_NEW_GC(cmd_condition_d, NULL, TRUE)); | |
177 | + uobject_put(self, "-f", NFUN_NEW_GC(cmd_condition_f, NULL, TRUE)); | |
178 | + uobject_put(self, "-h", NFUN_NEW_GC(cmd_condition_h, NULL, TRUE)); | |
179 | + uobject_put(self, "-L", NFUN_NEW_GC(cmd_condition_l, NULL, TRUE)); | |
180 | + uobject_put(self, "-p", NFUN_NEW_GC(cmd_condition_p, NULL, TRUE)); | |
181 | + uobject_put(self, "-t", NFUN_NEW_GC(cmd_condition_t, NULL, TRUE)); | |
182 | + uobject_put(self, "-S", NFUN_NEW_GC(cmd_condition_s2, NULL, TRUE)); | |
183 | + uobject_put(self, "-g", NFUN_NEW_GC(cmd_condition_g, NULL, TRUE)); | |
184 | + uobject_put(self, "-k", NFUN_NEW_GC(cmd_condition_k, NULL, TRUE)); | |
185 | + uobject_put(self, "-u", NFUN_NEW_GC(cmd_condition_u, NULL, TRUE)); | |
186 | + uobject_put(self, "-r", NFUN_NEW_GC(cmd_condition_r, NULL, TRUE)); | |
187 | + uobject_put(self, "-w", NFUN_NEW_GC(cmd_condition_w, NULL, TRUE)); | |
188 | + uobject_put(self, "-x", NFUN_NEW_GC(cmd_condition_x, NULL, TRUE)); | |
189 | + uobject_put(self, "-O", NFUN_NEW_GC(cmd_condition_o, NULL, TRUE)); | |
190 | + uobject_put(self, "-G", NFUN_NEW_GC(cmd_condition_g2, NULL, TRUE)); | |
191 | + uobject_put(self, "-e", NFUN_NEW_GC(cmd_condition_e, NULL, TRUE)); | |
192 | + uobject_put(self, "-s", NFUN_NEW_GC(cmd_condition_s, NULL, TRUE)); | |
193 | + uobject_put(self, "=", NFUN_NEW_GC(cmd_condition_eq, NULL, TRUE)); | |
194 | + uobject_put(self, "!=", NFUN_NEW_GC(cmd_condition_neq, NULL, TRUE)); | |
195 | + uobject_put(self, "-slt", NFUN_NEW_GC(cmd_condition_slt, NULL, TRUE)); | |
196 | + uobject_put(self, "-sgt", NFUN_NEW_GC(cmd_condition_sgt, NULL, TRUE)); | |
197 | + uobject_put(self, "-sle", NFUN_NEW_GC(cmd_condition_sle, NULL, TRUE)); | |
198 | + uobject_put(self, "-sge", NFUN_NEW_GC(cmd_condition_sge, NULL, TRUE)); | |
199 | + uobject_put(self, "-eq", NFUN_NEW_GC(cmd_condition_eq2, NULL, TRUE)); | |
200 | + uobject_put(self, "-ne", NFUN_NEW_GC(cmd_condition_ne, NULL, TRUE)); | |
201 | + uobject_put(self, "-lt", NFUN_NEW_GC(cmd_condition_lt, NULL, TRUE)); | |
202 | + uobject_put(self, "-le", NFUN_NEW_GC(cmd_condition_le, NULL, TRUE)); | |
203 | + uobject_put(self, "-gt", NFUN_NEW_GC(cmd_condition_gt, NULL, TRUE)); | |
204 | + uobject_put(self, "-ge", NFUN_NEW_GC(cmd_condition_ge, NULL, TRUE)); | |
205 | + uobject_put(self, "-nt", NFUN_NEW_GC(cmd_condition_nt, NULL, TRUE)); | |
206 | + uobject_put(self, "-ot", NFUN_NEW_GC(cmd_condition_ot, NULL, TRUE)); | |
207 | + uobject_put(self, "-ef", NFUN_NEW_GC(cmd_condition_ef, NULL, TRUE)); | |
208 | + uobject_put(self, "=~", NFUN_NEW_GC(cmd_condition_re, NULL, TRUE)); | |
209 | + uobject_put(self, "++", NFUN_NEW_GC(cmd_plusplus, NULL, TRUE)); | |
210 | + uobject_put(self, "--", NFUN_NEW_GC(cmd_minusminus, NULL, TRUE)); | |
211 | + uobject_put(self, "+", NFUN_NEW_GC(cmd_plus, NULL, TRUE)); | |
212 | + uobject_put(self, "-", NFUN_NEW_GC(cmd_minus, NULL, TRUE)); | |
213 | + uobject_put(self, "*", NFUN_NEW_GC(cmd_mult, NULL, TRUE)); | |
214 | + uobject_put(self, "/", NFUN_NEW_GC(cmd_div, NULL, TRUE)); | |
215 | + uobject_put(self, "mod", NFUN_NEW_GC(cmd_mod, NULL, TRUE)); | |
216 | + uobject_put(self, "pow", NFUN_NEW_GC(cmd_pow, NULL, TRUE)); | |
217 | + uobject_put(self, "abs", NFUN_NEW_GC(cmd_abs, NULL, TRUE)); | |
218 | + uobject_put(self, "selector", NFUN_NEW_GC(cmd_selector, NULL, TRUE)); | |
219 | + uobject_put(self, "sort", NFUN_NEW_GC(cmd_sort, NULL, TRUE)); | |
220 | + uobject_put(self, "readline", NFUN_NEW_GC(cmd_readline, NULL, TRUE)); | |
221 | + uobject_put(self, "kanjicode", NFUN_NEW_GC(cmd_kanjicode, NULL, TRUE)); | |
222 | +#if defined(HAVE_MIGEMO_H) | |
223 | + uobject_put(self, "migemo_match", NFUN_NEW_GC(cmd_migemo_match, NULL, TRUE)); | |
224 | +#endif | |
225 | + | |
226 | + uobject_put(self, "sub", NFUN_NEW_GC(cmd_sub, NULL, TRUE)); | |
227 | + uobject_put(self, "time", NFUN_NEW_GC(cmd_time, NULL, TRUE)); | |
228 | + | |
229 | + sObject* nfun = NFUN_NEW_GC(cmd_hash, NULL, TRUE); | |
230 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-key")); | |
231 | + uobject_put(self, "hash", nfun); | |
232 | + nfun = NFUN_NEW_GC(cmd_ary, NULL, TRUE); | |
233 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-index")); | |
234 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-append")); | |
235 | + uobject_put(self, "ary", nfun); | |
236 | + | |
237 | + nfun = NFUN_NEW_GC(cmd_var, NULL, TRUE); | |
238 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-index")); | |
239 | + uobject_put(self, "var", nfun); | |
240 | + | |
241 | + nfun = NFUN_NEW_GC(cmd_add, NULL, TRUE); | |
242 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
243 | + uobject_put(self, "add", nfun); | |
244 | + | |
245 | + nfun = NFUN_NEW_GC(cmd_del, NULL, TRUE); | |
246 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
247 | + uobject_put(self, "del", nfun); | |
248 | + | |
249 | + nfun = NFUN_NEW_GC(cmd_index, NULL, TRUE); | |
250 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
251 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-count")); | |
252 | + uobject_put(self, "index", nfun); | |
253 | + | |
254 | + nfun = NFUN_NEW_GC(cmd_rindex, NULL, TRUE); | |
255 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
256 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-count")); | |
257 | + uobject_put(self, "rindex", nfun); | |
258 | + | |
259 | + nfun = NFUN_NEW_GC(cmd_each, NULL, TRUE); | |
260 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-number")); | |
261 | + uobject_put(self, "each", nfun); | |
262 | + | |
263 | + nfun = NFUN_NEW_GC(cmd_def, NULL, TRUE); | |
264 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-option-with-argument")); | |
265 | + uobject_put(self, "def", nfun); | |
266 | + | |
267 | + nfun = NFUN_NEW_GC(cmd_class, NULL, TRUE); | |
268 | + (void)nfun_put_option_with_argument(nfun, STRDUP("-option-with-argument")); | |
269 | + uobject_put(self, "class", nfun); | |
270 | + | |
271 | + clear_matching_info_variable(); | |
272 | +} | |
273 | + | |
274 | +void uobject_init(sObject* self) | |
275 | +{ | |
276 | + assert(TYPE(self) == T_UOBJECT); | |
277 | + | |
278 | + uobject_put(self, "run", NFUN_NEW_GC(cmd_mrun, NULL, FALSE)); | |
279 | + uobject_put(self, "self", self); | |
280 | + uobject_put(self, "root", gRootObject); | |
281 | + uobject_put(self, "parent", SUOBJECT(self).mParent); | |
282 | + uobject_put(self, "show", NFUN_NEW_GC(cmd_mshow, NULL, FALSE)); | |
283 | +} | |
284 | + | |
285 | +void uobject_delete_gc(sObject* self) | |
286 | +{ | |
287 | + assert(TYPE(self) == T_UOBJECT); | |
288 | + | |
289 | + uobject_it* it = SUOBJECT(self).mEntryIt; | |
290 | + | |
291 | + while(it) { | |
292 | + uobject_it* next_it = it->mNextIt; | |
293 | + uobject_it_release(it, self); | |
294 | + it = next_it; | |
295 | + } | |
296 | + | |
297 | + FREE(SUOBJECT(self).mTable); | |
298 | + FREE(SUOBJECT(self).mName); | |
299 | +} | |
300 | + | |
301 | +void uobject_delete_stack(sObject* self) | |
302 | +{ | |
303 | + assert(TYPE(self) == T_UOBJECT); | |
304 | + | |
305 | + uobject_it* it = SUOBJECT(self).mEntryIt; | |
306 | + | |
307 | + while(it) { | |
308 | + uobject_it* next_it = it->mNextIt; | |
309 | + uobject_it_release(it, self); | |
310 | + it = next_it; | |
311 | + } | |
312 | + | |
313 | + FREE(SUOBJECT(self).mTable); | |
314 | + FREE(SUOBJECT(self).mName); | |
315 | +} | |
316 | + | |
317 | +int uobject_gc_children_mark(sObject* self) | |
318 | +{ | |
319 | + assert(TYPE(self) == T_UOBJECT); | |
320 | + | |
321 | + int count = 0; | |
322 | + | |
323 | + uobject_it* it = SUOBJECT(self).mEntryIt; | |
324 | + while(it) { | |
325 | + sObject* item = it->mItem; | |
326 | + | |
327 | + if((item->mFlg & GC_MARK) == 0) { | |
328 | + item->mFlg |= GC_MARK; | |
329 | + count++; | |
330 | + | |
331 | + count += object_gc_children_mark(item); | |
332 | + } | |
333 | + | |
334 | + it = it->mNextIt; | |
335 | + } | |
336 | + | |
337 | + return count; | |
338 | +} | |
339 | + | |
340 | +void uobject_put(sObject* self, char* key, void* item) | |
341 | +{ | |
342 | + assert(TYPE(self) == T_UOBJECT); | |
343 | + | |
344 | + if(SUOBJECT(self).mCounter >= SUOBJECT(self).mTableSize) { | |
345 | + resize(self); | |
346 | + } | |
347 | + | |
348 | + unsigned int uobject_key = get_uobject_value(self, key); | |
349 | + | |
350 | + uobject_it* it = SUOBJECT(self).mTable[ uobject_key ]; | |
351 | + while(it) { | |
352 | + if(strcmp(key, it->mKey) == 0) { | |
353 | + it->mItem = item; | |
354 | + return; | |
355 | + } | |
356 | + it = it->mCollisionIt; | |
357 | + } | |
358 | + | |
359 | + uobject_it* new_it | |
360 | + = uobject_it_new(key, item, SUOBJECT(self).mTable[uobject_key], SUOBJECT(self).mEntryIt, self); | |
361 | + | |
362 | + SUOBJECT(self).mTable[uobject_key] = new_it; | |
363 | + SUOBJECT(self).mEntryIt = new_it; | |
364 | + SUOBJECT(self).mCounter++; | |
365 | +} | |
366 | + | |
367 | +void* uobject_item(sObject* self, char* key) | |
368 | +{ | |
369 | + assert(TYPE(self) == T_UOBJECT); | |
370 | + | |
371 | + uobject_it* it = SUOBJECT(self).mTable[ get_uobject_value(self, key) ]; | |
372 | + | |
373 | + while(it) { | |
374 | + if(strcmp(key, it->mKey) == 0) return it->mItem; | |
375 | + it = it->mCollisionIt; | |
376 | + } | |
377 | + | |
378 | + return NULL; | |
379 | +} | |
380 | + | |
381 | +void uobject_clear(sObject* self) | |
382 | +{ | |
383 | + assert(TYPE(self) == T_UOBJECT); | |
384 | + | |
385 | + int i; | |
386 | + int max; | |
387 | + uobject_it* it = SUOBJECT(self).mEntryIt; | |
388 | + | |
389 | + while(it) { | |
390 | + uobject_it* next_it = it->mNextIt; | |
391 | + uobject_it_release(it, self); | |
392 | + it = next_it; | |
393 | + } | |
394 | + | |
395 | + memset(SUOBJECT(self).mTable, 0, sizeof(uobject_it*)*SUOBJECT(self).mTableSize); | |
396 | + | |
397 | + SUOBJECT(self).mEntryIt = NULL; | |
398 | + SUOBJECT(self).mCounter = 0; | |
399 | +} | |
400 | + | |
401 | +uobject_it* uobject_loop_begin(sObject* self) | |
402 | +{ | |
403 | + assert(TYPE(self) == T_UOBJECT); | |
404 | + | |
405 | + return SUOBJECT(self).mEntryIt; | |
406 | +} | |
407 | + | |
408 | +void* uobject_loop_item(uobject_it* it) | |
409 | +{ | |
410 | + return it->mItem; | |
411 | +} | |
412 | + | |
413 | +char* uobject_loop_key(uobject_it* it) | |
414 | +{ | |
415 | + return it->mKey; | |
416 | +} | |
417 | + | |
418 | +uobject_it* uobject_loop_next(uobject_it* it) | |
419 | +{ | |
420 | + return it->mNextIt; | |
421 | +} | |
422 | + | |
423 | +int uobject_count(sObject* self) | |
424 | +{ | |
425 | + assert(TYPE(self) == T_UOBJECT); | |
426 | + | |
427 | + return SUOBJECT(self).mCounter; | |
428 | +} |
@@ -107,12 +107,12 @@ static void xyzsh_read_rc() | ||
107 | 107 | xyzsh_read_rc_core(user_rc_path); |
108 | 108 | |
109 | 109 | |
110 | -// hash_put(gRootObject, "test", sTestObj_new("AAA", 1)); | |
110 | +// uobject_put(gRootObject, "test", sTestObj_new("AAA", 1)); | |
111 | 111 | } |
112 | 112 | |
113 | 113 | void xyzsh_init(enum eAppType app_type, BOOL no_runtime_script) |
114 | 114 | { |
115 | - setenv("XYZSH_VERSION", "1.1.0", 1); | |
115 | + setenv("XYZSH_VERSION", "1.1.1", 1); | |
116 | 116 | setenv("XYZSH_DATAROOTDIR", DATAROOTDIR, 1); |
117 | 117 | |
118 | 118 | stack_init(1);; |
@@ -132,7 +132,7 @@ void xyzsh_init(enum eAppType app_type, BOOL no_runtime_script) | ||
132 | 132 | xyzsh_readline_init(FALSE); |
133 | 133 | |
134 | 134 | gDirStack = VECTOR_NEW_GC(10, FALSE); |
135 | - hash_put(gxyzshObject, "_dir_stack", gDirStack); | |
135 | + uobject_put(gxyzshObject, "_dir_stack", gDirStack); | |
136 | 136 | |
137 | 137 | char* term_env = getenv("TERM"); |
138 | 138 | if(term_env != NULL && strcmp(term_env, "") != 0) { |
@@ -307,11 +307,20 @@ typedef struct { | ||
307 | 307 | BOOL mSuspended; |
308 | 308 | } job_obj; |
309 | 309 | |
310 | +typedef struct _uobject_it { | |
311 | + char* mKey; | |
312 | + | |
313 | + void* mItem; | |
314 | + struct _uobject_it* mCollisionIt; | |
315 | + | |
316 | + struct _uobject_it* mNextIt; | |
317 | +} uobject_it; | |
318 | + | |
310 | 319 | typedef struct { // a user object can be treated like a hash_obj |
311 | - hash_it** mTable; | |
320 | + uobject_it** mTable; | |
312 | 321 | int mTableSize; |
313 | 322 | |
314 | - hash_it* mEntryIt; | |
323 | + uobject_it* mEntryIt; | |
315 | 324 | |
316 | 325 | int mCounter; |
317 | 326 |
@@ -438,8 +447,18 @@ sObject* extobj_new_from_gc(void* object, fExtObjMarkFun mark_fun, fExtObjFreeFu | ||
438 | 447 | |
439 | 448 | sObject* uobject_new_from_gc(int size, sObject* parent, char* name, BOOL user_object); |
440 | 449 | sObject* uobject_new_from_stack(int size, sObject* object, char* name); |
450 | +void uobject_put(sObject* self, char* key, void* item); | |
441 | 451 | void uobject_init(sObject* self); |
442 | 452 | void uobject_root_init(sObject* self); |
453 | +void uobject_put(sObject* self, char* key, void* item); | |
454 | +void* uobject_item(sObject* self, char* key); | |
455 | +void uobject_clear(sObject* self); | |
456 | + | |
457 | +uobject_it* uobject_loop_begin(sObject* self); | |
458 | +void* uobject_loop_item(uobject_it* it); | |
459 | +char* uobject_loop_key(uobject_it* it); | |
460 | +uobject_it* uobject_loop_next(uobject_it* it); | |
461 | +int uobject_count(sObject* self); | |
443 | 462 | |
444 | 463 | #define UOBJECT_NEW_GC(o, o2, o3, o4) uobject_new_from_gc(o, o2, o3, o4) |
445 | 464 | #define UOBJECT_NEW_STACK(o, o2, o3) uobject_new_from_stack(o, o2, o3) |
@@ -478,6 +497,8 @@ BOOL xyzsh_rehash(char* sname, int sline); | ||
478 | 497 | #if defined(HAVE_MIGEMO_H) |
479 | 498 | BOOL cmd_migemo_match(sObject* nextin, sObject* nextout, sRunInfo* runinfo); |
480 | 499 | #endif |
500 | +BOOL cmd_kanjicode(sObject* nextin, sObject* nextout, sRunInfo* runinfo); | |
501 | +BOOL cmd_defined(sObject* nextin, sObject* nextout, sRunInfo* runinfo); | |
481 | 502 | BOOL cmd_funinfo(sObject* nextin, sObject* nextout, sRunInfo* runinfo); |
482 | 503 | BOOL cmd_readline_read_history(sObject* nextin, sObject* nextout, sRunInfo* runinfo); |
483 | 504 | BOOL cmd_readline_write_history(sObject* nextin, sObject* nextout, sRunInfo* runinfo); |
@@ -795,5 +816,7 @@ void readline_write_history(); | ||
795 | 816 | void readline_read_history(); |
796 | 817 | void xyzsh_read_rc_core(char* path); |
797 | 818 | |
819 | +extern sObject* gStackFrames; | |
820 | + | |
798 | 821 | #endif |
799 | 822 |
@@ -1,3 +1,5 @@ | ||
1 | +kanjicode -byte | |
2 | + | |
1 | 3 | ### make xyzsh setting directory ### |
2 | 4 | print ~/.xyzsh | if(| -e) ( |
3 | 5 | | if(! | -d) ( |