Changeset 5972 for lang/c/misc
- Timestamp:
- 02/01/08 00:46:41 (5 years ago)
- Location:
- lang/c/misc/mlisp
- Files:
-
- 5 modified
-
readme.txt (modified) (2 diffs)
-
src/main.c (modified) (2 diffs)
-
src/ml_builtin.c (modified) (2 diffs)
-
src/mlisp.cpp (modified) (20 diffs)
-
src/mlisp.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/misc/mlisp/readme.txt
r5924 r5972 51 51 * todo 52 52 53 - ��� ��Ƃ��������� ���L�V�J���X�R�[�v�A�N���[�W��53 - ���L�V�J���X�R�[�v�A�N���[�W�� 54 54 - �K�x�R�� 55 55 - assert �Ŏ��ȂȂ��悤�� … … 62 62 - &optional, &rest 63 63 64 -[v] � }�N�����Łu`�v�u,�v�u,@�v���������64 -[v] �����Ƃ���������[v] �}�N�����Łu`�v�u,�v�u,@�v��������� 65 65 -- �u`�v�u,�v����ς� 66 66 -- �u,@�v����ς� -
lang/c/misc/mlisp/src/main.c
r5814 r5972 41 41 } 42 42 if (b_print_read) { 43 ml_print(ml, ofp, r , FALSE);43 ml_print(ml, ofp, r); 44 44 } 45 45 … … 47 47 } 48 48 if (e != cNL) { 49 ml_print(ml, ofp, e , FALSE);49 ml_print(ml, ofp, e); 50 50 } 51 51 } -
lang/c/misc/mlisp/src/ml_builtin.c
r5924 r5972 52 52 SExp b; 53 53 if (SEXP_CONSP(ca)) { 54 SExp unq = ml_make_symbol(ml, "unquote", NULL);55 SExp unqa = ml_make_symbol(ml, "unquote-splicing", NULL);56 54 SExp caa = ml_car(ml, ca); 57 if (caa == unq) {55 if (caa == ml_find_symbol(ml, "unquote", NULL, TRUE)) { 58 56 b = ml_eval(ml, ml_car(ml, ml_cdr(ml, ca))); 59 } else if (caa == unqa) {57 } else if (caa == ml_find_symbol(ml, "unquote-splicing", NULL, TRUE)) { 60 58 b = ml_eval(ml, ml_car(ml, ml_cdr(ml, ca))); 61 59 ml_rplacd(ml, tail, b); … … 291 289 { 292 290 FILE* fp = stdout; 293 ml_print(ml, fp, a, TRUE); 294 return cNil; 291 SExp ca = ml_car(ml, a); 292 ml_print(ml, fp, ca); 293 return ca; 295 294 } 296 295 -
lang/c/misc/mlisp/src/mlisp.cpp
r5924 r5972 122 122 SExp read(FILE* fp); 123 123 SExp eval(SExp a); 124 void print(FILE* fp, SExp a , bool b_cell);124 void print(FILE* fp, SExp a); 125 125 SExp apply(SExp ca, SExp cd, bool b_eval); 126 126 … … 142 142 void runtime_error(SExp a, const char* msg); 143 143 144 SExp make_symbol(const char* str, const char* end);144 SExp find_symbol(const char* str, const char* end, bool b_make); 145 145 146 146 private: … … 158 158 SExp alloc_symbol(); 159 159 Symbol* get_symbol_ptr(SExp a); 160 SExp find_symbol(const char* str, const char* end);161 160 162 161 SExp eval_cell(SExp a); ///< �Z���������car �̊��Ɏc�������ČĂяo���j … … 296 295 if (a != cNil) { 297 296 fprintf(fp, " :"); 298 print(fp, a , false);297 print(fp, a); 299 298 } else { 300 299 fprintf(fp, "\n"); … … 434 433 Symbol* MLContext::get_symbol_ptr(SExp a) 435 434 { 436 assert(SEXP_TYPE(a) == tSymb );435 assert(SEXP_TYPE(a) == tSymb || SEXP_TYPE(a) == tStr); 437 436 return &g_symbol_buf[SEXP_UVAL(a)]; 438 437 } 439 438 440 SExp MLContext::find_symbol(const char* str, const char* end )439 SExp MLContext::find_symbol(const char* str, const char* end, bool b_make) 441 440 { 442 441 int len; … … 454 453 } 455 454 } 456 return cFail; 457 } 458 459 SExp MLContext::make_symbol(const char* str, const char* end) 460 { 461 SExp a; 462 a = find_symbol(str, end); 463 if (a == cFail) { 464 a = alloc_symbol(); 455 456 457 if (b_make) { 458 SExp a = alloc_symbol(); 465 459 Symbol* p = get_symbol_ptr(a); 466 460 p->sexp = cUndef; … … 474 468 p->str[len] = '\0'; 475 469 } 476 } 477 return a; 470 return a; 471 } 472 473 return cFail; 478 474 } 479 475 … … 492 488 SExp fn = MAKE_SEXP(tFunc, SEXP_UVAL(cell)); 493 489 494 SExp symb = make_symbol(word, NULL);490 SExp symb = find_symbol(word, NULL, true); 495 491 setq(symb, fn); 496 492 return symb; … … 535 531 *q = '\0'; 536 532 537 SExp a = make_symbol(str, q);538 return cons(find_symbol("quote", NULL), cons(a, cNil));533 SExp a = find_symbol(str, q, true); 534 return MAKE_SEXP(tStr, SEXP_UVAL(a)); 539 535 } 540 536 … … 621 617 { 622 618 SExp a = read_rec(fp); 623 return cons( make_symbol("quote", NULL), cons(a, cNil));619 return cons(find_symbol("quote", NULL, true), cons(a, cNil)); 624 620 } 625 621 case '`': 626 622 { 627 623 SExp a = read_rec(fp); 628 return cons( make_symbol("quasiquote", NULL), cons(a, cNil));624 return cons(find_symbol("quasiquote", NULL, true), cons(a, cNil)); 629 625 } 630 626 case ',': … … 634 630 if (c != '@') { 635 631 ungetc(c, fp); 636 fn = make_symbol("unquote", NULL);632 fn = find_symbol("unquote", NULL, true); 637 633 } else { 638 fn = make_symbol("unquote-splicing", NULL);634 fn = find_symbol("unquote-splicing", NULL, true); 639 635 } 640 636 SExp a = read_rec(fp); … … 665 661 SExp a = reserved(symb, q-symb); 666 662 if (a == cFail) { 667 a = make_symbol(symb, q);663 a = find_symbol(symb, q, true); 668 664 } 669 665 return a; … … 699 695 case tOther: 700 696 case tFunc: 697 case tStr: 701 698 return a; 702 699 case tSymb: … … 752 749 753 750 if (flags[MLF_PRINT_FUNC_ARG]) { 754 print(stdout, param , false);751 print(stdout, param); 755 752 } 756 753 bind_arg(arg, param); … … 759 756 SExp replace = eval(body); 760 757 if (flags[MLF_PRINT_MACRO_REPLACE]) { 761 print(stdout, replace , false);758 print(stdout, replace); 762 759 } 763 760 body = replace; … … 817 814 print_rec(stdout, symb); 818 815 printf(":"); 819 print(stdout, val , false);816 print(stdout, val); 820 817 } 821 818 } … … 879 876 Symbol* p = get_symbol_ptr(a); 880 877 fprintf(fp, "%s", p->str); 878 } 879 break; 880 case tStr: 881 { 882 Symbol* p = get_symbol_ptr(a); 883 fprintf(fp, "\"%s\"", p->str); 881 884 } 882 885 break; … … 911 914 } 912 915 913 void MLContext::print(FILE* fp, SExp a, bool b_cell) 914 { 915 if (!b_cell) { 916 print_rec(fp, a); 917 } else { 918 print_cell(fp, a); 919 } 916 void MLContext::print(FILE* fp, SExp a) 917 { 918 print_rec(fp, a); 920 919 printf("\n"); 921 920 } … … 934 933 SExp ml_read(MLContext* ml, FILE* fp) { return ml->read(fp); } 935 934 SExp ml_eval(MLContext* ml, SExp a) { return ml->eval(a); } 936 void ml_print(MLContext* ml, FILE* fp, SExp a , int b_cell) { ml->print(fp, a, b_cell != FALSE); }935 void ml_print(MLContext* ml, FILE* fp, SExp a) { ml->print(fp, a); } 937 936 SExp ml_apply(MLContext* ml, SExp ca, SExp cd) { return ml->apply(ca, cd, false); } 938 937 … … 950 949 951 950 void ml_setq(MLContext* ml, SExp symb, SExp arg_body) { ml->setq(symb, arg_body); } 952 SExp ml_ make_symbol(MLContext* ml, const char* str, const char* end) { return ml->make_symbol(str, end); }951 SExp ml_find_symbol(MLContext* ml, const char* str, const char* end, int b_make) { return ml->find_symbol(str, end, b_make != FALSE); } 953 952 954 953 const char* ml_get_symbol_string(MLContext* ml, SExp symb) { return ml->get_symbol_string(symb); } -
lang/c/misc/mlisp/src/mlisp.h
r5814 r5972 45 45 SExp ml_read(MLContext* ml, FILE* fp); 46 46 SExp ml_eval(MLContext* ml, SExp a); 47 void ml_print(MLContext* ml, FILE* fp, SExp a , int b_cell);47 void ml_print(MLContext* ml, FILE* fp, SExp a); 48 48 SExp ml_apply(MLContext* ml, SExp ca, SExp cd); 49 49 … … 65 65 66 66 void ml_setq(MLContext* ml, SExp symb, SExp arg_body); ///< setq 67 SExp ml_ make_symbol(MLContext* ml, const char* str, const char* end); ///< �V���{���쐬67 SExp ml_find_symbol(MLContext* ml, const char* str, const char* end, int b_make); ///< �V���{���쐬 68 68 69 69 const char* ml_get_symbol_string(MLContext* ml, SExp symb); ///< symbol string … … 83 83 #define tOther (10) ///< other (nil, t, eof) 84 84 #define tFunc (14) ///< function (lambda or macro) 85 #define tStr (18) ///< string 85 86 86 87 /// macros
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)