Browse Source

Sol Part 33: Garbage In, Garbage Out!

Graham Northup 5 years ago
parent
commit
3c1da53911
20 changed files with 7747 additions and 7770 deletions
  1. 4
    0
      .gitignore
  2. 1
    1
      ast.h
  3. 4
    0
      astprint.c
  4. 1
    1
      build.sh
  5. 78
    64
      builtins.c
  6. 42
    0
      dump.sol
  7. 94
    10
      gc.c
  8. 71
    0
      gcstat.py
  9. 956
    928
      lex.yy.c
  10. 2
    2
      object.c
  11. 4279
    4060
      parser.output
  12. 2097
    2610
      parser.tab.c
  13. 76
    86
      parser.tab.h
  14. 2
    1
      parser.y
  15. 4
    0
      runtime.c
  16. 12
    7
      sol.h
  17. 5
    0
      solrun.c
  18. 16
    0
      state.c
  19. 1
    0
      test_monty.sol
  20. 2
    0
      tokenizer.lex

+ 4
- 0
.gitignore View File

@@ -3,3 +3,7 @@ sol
3 3
 stdout
4 4
 .submodule_stamp
5 5
 *.orig
6
+*.swp
7
+*.swo
8
+gclog.txt
9
+gcstat.txt

+ 1
- 1
ast.h View File

@@ -26,7 +26,7 @@ typedef struct {
26 26
 	};
27 27
 } lit_node;
28 28
 
29
-typedef enum {OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW, OP_BAND, OP_BOR, OP_BXOR, OP_LAND, OP_LOR, OP_EQUAL, OP_LESS, OP_GREATER, OP_LESSEQ, OP_GREATEREQ, OP_LSHIFT, OP_RSHIFT} binop_t;
29
+typedef enum {OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW, OP_BAND, OP_BOR, OP_BXOR, OP_LAND, OP_LOR, OP_EQUAL, OP_NEQUAL, OP_LESS, OP_GREATER, OP_LESSEQ, OP_GREATEREQ, OP_LSHIFT, OP_RSHIFT} binop_t;
30 30
 typedef struct {
31 31
 	binop_t type;
32 32
 	expr_node *left;

+ 4
- 0
astprint.c View File

@@ -189,6 +189,10 @@ void prex(sol_state_t *state, expr_node *node, int lev) {
189 189
 				case OP_EQUAL:
190 190
 					prlev(state, lev, "Op: ==");
191 191
 					break;
192
+					
193
+				case OP_NEQUAL:
194
+					prlev(state, lev, "Op: !=");
195
+					break;
192 196
 
193 197
 				case OP_LESS:
194 198
 					prlev(state, lev, "Op: <");

+ 1
- 1
build.sh View File

@@ -4,7 +4,7 @@ if [ ! -f .submodule_stamp ]; then
4 4
 fi
5 5
 
6 6
 if [ -z "$CFLAGS" ]; then
7
-    CFLAGS=-g
7
+    CFLAGS="-g"
8 8
 fi
9 9
 
10 10
 gcc -c $CFLAGS dsl/seq.c

+ 78
- 64
builtins.c View File

@@ -538,8 +538,8 @@ sol_object_t *sol_f_singlet_tostring(sol_state_t *state, sol_object_t *args) {
538 538
 }
539 539
 
540 540
 sol_object_t *sol_f_int_add(sol_state_t *state, sol_object_t *args) {
541
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
542
-	sol_object_t *res = sol_new_int(state, a->ival + b->ival);
541
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
542
+	sol_object_t *res = sol_new_int(state, a->ival + bint->ival);
543 543
 	sol_obj_free(a);
544 544
 	sol_obj_free(b);
545 545
 	if(sol_has_error(state)) {
@@ -550,8 +550,8 @@ sol_object_t *sol_f_int_add(sol_state_t *state, sol_object_t *args) {
550 550
 }
551 551
 
552 552
 sol_object_t *sol_f_int_sub(sol_state_t *state, sol_object_t *args) {
553
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
554
-	sol_object_t *res = sol_new_int(state, a->ival - b->ival);
553
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
554
+	sol_object_t *res = sol_new_int(state, a->ival - bint->ival);
555 555
 	sol_obj_free(a);
556 556
 	sol_obj_free(b);
557 557
 	if(sol_has_error(state)) {
@@ -562,8 +562,8 @@ sol_object_t *sol_f_int_sub(sol_state_t *state, sol_object_t *args) {
562 562
 }
563 563
 
564 564
 sol_object_t *sol_f_int_mul(sol_state_t *state, sol_object_t *args) {
565
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
566
-	sol_object_t *res = sol_new_int(state, a->ival * b->ival);
565
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
566
+	sol_object_t *res = sol_new_int(state, a->ival * bint->ival);
567 567
 	sol_obj_free(a);
568 568
 	sol_obj_free(b);
569 569
 	if(sol_has_error(state)) {
@@ -574,8 +574,8 @@ sol_object_t *sol_f_int_mul(sol_state_t *state, sol_object_t *args) {
574 574
 }
575 575
 
576 576
 sol_object_t *sol_f_int_div(sol_state_t *state, sol_object_t *args) {
577
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
578
-	sol_object_t *res = sol_new_int(state, a->ival / b->ival);
577
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
578
+	sol_object_t *res = sol_new_int(state, a->ival / bint->ival);
579 579
 	sol_obj_free(a);
580 580
 	sol_obj_free(b);
581 581
 	if(sol_has_error(state)) {
@@ -586,8 +586,8 @@ sol_object_t *sol_f_int_div(sol_state_t *state, sol_object_t *args) {
586 586
 }
587 587
 
588 588
 sol_object_t *sol_f_int_mod(sol_state_t *state, sol_object_t *args) {
589
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
590
-	sol_object_t *res = sol_new_int(state, a->ival % b->ival);
589
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
590
+	sol_object_t *res = sol_new_int(state, a->ival % bint->ival);
591 591
 	sol_obj_free(a);
592 592
 	sol_obj_free(b);
593 593
 	if(sol_has_error(state)) {
@@ -598,8 +598,8 @@ sol_object_t *sol_f_int_mod(sol_state_t *state, sol_object_t *args) {
598 598
 }
599 599
 
600 600
 sol_object_t *sol_f_int_pow(sol_state_t *state, sol_object_t *args) {
601
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
602
-	sol_object_t *res = sol_new_int(state, (long) pow((double) a->ival, b->ival));
601
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
602
+	sol_object_t *res = sol_new_int(state, (long) pow((double) a->ival, bint->ival));
603 603
 	sol_obj_free(a);
604 604
 	sol_obj_free(b);
605 605
 	if(sol_has_error(state)) {
@@ -610,8 +610,8 @@ sol_object_t *sol_f_int_pow(sol_state_t *state, sol_object_t *args) {
610 610
 }
611 611
 
612 612
 sol_object_t *sol_f_int_band(sol_state_t *state, sol_object_t *args) {
613
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
614
-	sol_object_t *res = sol_new_int(state, a->ival & b->ival);
613
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
614
+	sol_object_t *res = sol_new_int(state, a->ival & bint->ival);
615 615
 	sol_obj_free(a);
616 616
 	sol_obj_free(b);
617 617
 	if(sol_has_error(state)) {
@@ -622,8 +622,8 @@ sol_object_t *sol_f_int_band(sol_state_t *state, sol_object_t *args) {
622 622
 }
623 623
 
624 624
 sol_object_t *sol_f_int_bor(sol_state_t *state, sol_object_t *args) {
625
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
626
-	sol_object_t *res = sol_new_int(state, a->ival | b->ival);
625
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
626
+	sol_object_t *res = sol_new_int(state, a->ival | bint->ival);
627 627
 	sol_obj_free(a);
628 628
 	sol_obj_free(b);
629 629
 	if(sol_has_error(state)) {
@@ -634,8 +634,8 @@ sol_object_t *sol_f_int_bor(sol_state_t *state, sol_object_t *args) {
634 634
 }
635 635
 
636 636
 sol_object_t *sol_f_int_bxor(sol_state_t *state, sol_object_t *args) {
637
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
638
-	sol_object_t *res = sol_new_int(state, a->ival ^ b->ival);
637
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
638
+	sol_object_t *res = sol_new_int(state, a->ival ^ bint->ival);
639 639
 	sol_obj_free(a);
640 640
 	sol_obj_free(b);
641 641
 	if(sol_has_error(state)) {
@@ -646,8 +646,8 @@ sol_object_t *sol_f_int_bxor(sol_state_t *state, sol_object_t *args) {
646 646
 }
647 647
 
648 648
 sol_object_t *sol_f_int_blsh(sol_state_t *state, sol_object_t *args) {
649
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
650
-	sol_object_t *res = sol_new_int(state, a->ival << b->ival);
649
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
650
+	sol_object_t *res = sol_new_int(state, a->ival << bint->ival);
651 651
 	sol_obj_free(a);
652 652
 	sol_obj_free(b);
653 653
 	if(sol_has_error(state)) {
@@ -658,8 +658,8 @@ sol_object_t *sol_f_int_blsh(sol_state_t *state, sol_object_t *args) {
658 658
 }
659 659
 
660 660
 sol_object_t *sol_f_int_brsh(sol_state_t *state, sol_object_t *args) {
661
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
662
-	sol_object_t *res = sol_new_int(state, a->ival >> b->ival);
661
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
662
+	sol_object_t *res = sol_new_int(state, a->ival >> bint->ival);
663 663
 	sol_obj_free(a);
664 664
 	sol_obj_free(b);
665 665
 	if(sol_has_error(state)) {
@@ -677,10 +677,11 @@ sol_object_t *sol_f_int_bnot(sol_state_t *state, sol_object_t *args) {
677 677
 }
678 678
 
679 679
 sol_object_t *sol_f_int_cmp(sol_state_t *state, sol_object_t *args) {
680
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
681
-	sol_object_t *res = sol_new_int(state, a->ival == b->ival ? 0 : (a->ival < b->ival ? -1 : 1));
680
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
681
+	sol_object_t *res = sol_new_int(state, a->ival == bint->ival ? 0 : (a->ival < bint->ival ? -1 : 1));
682 682
 	sol_obj_free(a);
683 683
 	sol_obj_free(b);
684
+	sol_obj_free(bint);
684 685
 	return res;
685 686
 }
686 687
 
@@ -705,8 +706,8 @@ sol_object_t *sol_f_int_tostring(sol_state_t *state, sol_object_t *args) {
705 706
 }
706 707
 
707 708
 sol_object_t *sol_f_float_add(sol_state_t *state, sol_object_t *args) {
708
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
709
-	sol_object_t *res = sol_new_float(state, a->fval + b->fval);
709
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bflt = sol_cast_float(state, b);
710
+	sol_object_t *res = sol_new_float(state, a->fval + bflt->fval);
710 711
 	sol_obj_free(a);
711 712
 	sol_obj_free(b);
712 713
 	if(sol_has_error(state)) {
@@ -717,8 +718,8 @@ sol_object_t *sol_f_float_add(sol_state_t *state, sol_object_t *args) {
717 718
 }
718 719
 
719 720
 sol_object_t *sol_f_float_sub(sol_state_t *state, sol_object_t *args) {
720
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
721
-	sol_object_t *res = sol_new_float(state, a->fval - b->fval);
721
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bflt = sol_cast_float(state, b);
722
+	sol_object_t *res = sol_new_float(state, a->fval - bflt->fval);
722 723
 	sol_obj_free(a);
723 724
 	sol_obj_free(b);
724 725
 	if(sol_has_error(state)) {
@@ -729,8 +730,8 @@ sol_object_t *sol_f_float_sub(sol_state_t *state, sol_object_t *args) {
729 730
 }
730 731
 
731 732
 sol_object_t *sol_f_float_mul(sol_state_t *state, sol_object_t *args) {
732
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
733
-	sol_object_t *res = sol_new_float(state, a->fval * b->fval);
733
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bflt = sol_cast_float(state, b);
734
+	sol_object_t *res = sol_new_float(state, a->fval * bflt->fval);
734 735
 	sol_obj_free(a);
735 736
 	sol_obj_free(b);
736 737
 	if(sol_has_error(state)) {
@@ -741,8 +742,8 @@ sol_object_t *sol_f_float_mul(sol_state_t *state, sol_object_t *args) {
741 742
 }
742 743
 
743 744
 sol_object_t *sol_f_float_div(sol_state_t *state, sol_object_t *args) {
744
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
745
-	sol_object_t *res = sol_new_float(state, a->fval / b->fval);
745
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bflt = sol_cast_float(state, b);
746
+	sol_object_t *res = sol_new_float(state, a->fval / bflt->fval);
746 747
 	sol_obj_free(a);
747 748
 	sol_obj_free(b);
748 749
 	if(sol_has_error(state)) {
@@ -753,8 +754,8 @@ sol_object_t *sol_f_float_div(sol_state_t *state, sol_object_t *args) {
753 754
 }
754 755
 
755 756
 sol_object_t *sol_f_float_pow(sol_state_t *state, sol_object_t *args) {
756
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
757
-	sol_object_t *res = sol_new_float(state, pow(a->fval, b->fval));
757
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bflt = sol_cast_float(state, b);
758
+	sol_object_t *res = sol_new_float(state, pow(a->fval, bflt->fval));
758 759
 	sol_obj_free(a);
759 760
 	sol_obj_free(b);
760 761
 	if(sol_has_error(state)) {
@@ -765,11 +766,12 @@ sol_object_t *sol_f_float_pow(sol_state_t *state, sol_object_t *args) {
765 766
 }
766 767
 
767 768
 sol_object_t *sol_f_float_cmp(sol_state_t *state, sol_object_t *args) {
768
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
769
-	sol_object_t *res = sol_new_int(state, a->fval == b->fval ? 0 : (a->fval < b->fval ? -1 : 1));
770
-	sol_obj_free(a);
771
-	sol_obj_free(b);
772
-	return res;
769
+    sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bflt = sol_cast_float(state, b);
770
+    sol_object_t *res = sol_new_int(state, a->fval==bflt->fval? 0 : (a->fval<bflt->fval? -1 : 1));
771
+    sol_obj_free(a);
772
+    sol_obj_free(b);
773
+	sol_obj_free(bflt);
774
+    return res;
773 775
 }
774 776
 
775 777
 sol_object_t *sol_f_float_toint(sol_state_t *state, sol_object_t *args) {
@@ -793,8 +795,8 @@ sol_object_t *sol_f_float_tostring(sol_state_t *state, sol_object_t *args) {
793 795
 }
794 796
 
795 797
 sol_object_t *sol_f_str_add(sol_state_t *state, sol_object_t *args) {
796
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_string(state, sol_list_get_index(state, args, 1));
797
-	sol_object_t *res = sol_string_concat(state, a, b);
798
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bstr = sol_cast_string(state, b);
799
+	sol_object_t *res = sol_string_concat(state, a, bstr);
798 800
 	sol_obj_free(a);
799 801
 	sol_obj_free(b);
800 802
 	if(sol_has_error(state)) {
@@ -805,8 +807,8 @@ sol_object_t *sol_f_str_add(sol_state_t *state, sol_object_t *args) {
805 807
 }
806 808
 
807 809
 sol_object_t *sol_f_str_mul(sol_state_t *state, sol_object_t *args) {
808
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
809
-	int n = strlen(a->str) * b->ival + 1;
810
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b);
811
+	int n = strlen(a->str) * bint->ival + 1;
810 812
 	char *s = malloc(n);
811 813
 	int i;
812 814
 	s[0] = '\0';
@@ -816,6 +818,7 @@ sol_object_t *sol_f_str_mul(sol_state_t *state, sol_object_t *args) {
816 818
 	sol_object_t *res = sol_new_string(state, s);
817 819
 	sol_obj_free(a);
818 820
 	sol_obj_free(b);
821
+	sol_obj_free(bint);
819 822
 	free(s);
820 823
 	if(sol_has_error(state)) {
821 824
 		sol_obj_free(res);
@@ -825,11 +828,12 @@ sol_object_t *sol_f_str_mul(sol_state_t *state, sol_object_t *args) {
825 828
 }
826 829
 
827 830
 sol_object_t *sol_f_str_cmp(sol_state_t *state, sol_object_t *args) {
828
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_string(state, sol_list_get_index(state, args, 1));
829
-	sol_object_t *res = sol_new_int(state, strcmp(a->str, b->str));
830
-	sol_obj_free(a);
831
-	sol_obj_free(b);
832
-	return res;
831
+    sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bstr = sol_cast_string(state, b);
832
+    sol_object_t *res = sol_new_int(state, strcmp(a->str, bstr->str));
833
+    sol_obj_free(a);
834
+    sol_obj_free(b);
835
+	sol_obj_free(bstr);
836
+    return res;
833 837
 }
834 838
 
835 839
 sol_object_t *sol_f_str_len(sol_state_t *state, sol_object_t *args) {
@@ -990,11 +994,12 @@ sol_object_t *sol_f_list_add(sol_state_t *state, sol_object_t *args) {
990 994
 }
991 995
 
992 996
 sol_object_t *sol_f_list_mul(sol_state_t *state, sol_object_t *args) {
993
-	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1)), *ls;
997
+	sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1), *bint = sol_cast_int(state, b), *ls;
994 998
 	int i;
995 999
 	if(sol_has_error(state)) {
996 1000
 		sol_obj_free(a);
997 1001
 		sol_obj_free(b);
1002
+		sol_obj_free(bint);
998 1003
 		return sol_incref(state->None);
999 1004
 	}
1000 1005
 	ls = sol_new_list(state);
@@ -1003,6 +1008,7 @@ sol_object_t *sol_f_list_mul(sol_state_t *state, sol_object_t *args) {
1003 1008
 		if(sol_has_error(state)) {
1004 1009
 			sol_obj_free(a);
1005 1010
 			sol_obj_free(b);
1011
+			sol_obj_free(bint);
1006 1012
 			return sol_incref(state->None);
1007 1013
 		}
1008 1014
 	}
@@ -1027,11 +1033,12 @@ sol_object_t *sol_f_list_index(sol_state_t *state, sol_object_t *args) {
1027 1033
 }
1028 1034
 
1029 1035
 sol_object_t *sol_f_list_setindex(sol_state_t *state, sol_object_t *args) {
1030
-	sol_object_t *ls = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args , 1));
1036
+	sol_object_t *ls = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args ,1), *bint = sol_cast_int(state, b);
1031 1037
 	sol_object_t *val = sol_list_get_index(state, args, 2);
1032
-	sol_list_set_index(state, ls, b->ival, val);
1038
+	sol_list_set_index(state, ls, bint->ival, val);
1033 1039
 	sol_obj_free(ls);
1034 1040
 	sol_obj_free(b);
1041
+	sol_obj_free(bint);
1035 1042
 	sol_obj_free(val);
1036 1043
 	return sol_incref(state->None);
1037 1044
 }
@@ -1084,24 +1091,31 @@ sol_object_t *sol_f_list_copy(sol_state_t *state, sol_object_t *args) {
1084 1091
 }
1085 1092
 
1086 1093
 sol_object_t *sol_f_list_insert(sol_state_t *state, sol_object_t *args) {
1087
-	sol_object_t *list = sol_list_get_index(state, args, 0), *idx = sol_cast_int(state, sol_list_get_index(state, args, 1)), *obj = sol_list_get_index(state, args, 2);
1088
-	sol_list_insert(state, list, idx->ival, obj);
1089
-	sol_obj_free(list);
1090
-	return sol_incref(state->None);
1094
+    sol_object_t *list = sol_list_get_index(state, args, 0), *idx =  sol_list_get_index(state, args, 1), *iidx = sol_cast_int(state, idx), *obj = sol_list_get_index(state, args, 2);
1095
+    sol_list_insert(state, list, iidx->ival, obj);
1096
+    sol_obj_free(list);
1097
+	sol_obj_free(idx);
1098
+	sol_obj_free(iidx);
1099
+	sol_obj_free(obj);
1100
+    return sol_incref(state->None);
1091 1101
 }
1092 1102
 
1093 1103
 sol_object_t *sol_f_list_remove(sol_state_t *state, sol_object_t *args) {
1094
-	sol_object_t *list = sol_list_get_index(state, args, 0), *idx = sol_cast_int(state, sol_list_get_index(state, args, 1));
1095
-	sol_list_remove(state, list, idx->ival);
1096
-	sol_obj_free(list);
1097
-	return sol_incref(state->None);
1104
+    sol_object_t *list = sol_list_get_index(state, args, 0), *idx = sol_list_get_index(state, args, 1), *iidx = sol_cast_int(state, idx);
1105
+    sol_object_t *res = sol_list_remove(state, list, iidx->ival);
1106
+    sol_obj_free(list);
1107
+	sol_obj_free(idx);
1108
+	sol_obj_free(iidx);
1109
+    return res;
1098 1110
 }
1099 1111
 
1100 1112
 sol_object_t *sol_f_list_truncate(sol_state_t *state, sol_object_t *args) {
1101
-	sol_object_t *list = sol_list_get_index(state, args, 0), *idx = sol_list_get_index(state, args, 1);
1102
-	sol_object_t *res = sol_list_truncate(state, list, idx->ival);
1103
-	sol_obj_free(list);
1104
-	return res;
1113
+    sol_object_t *list = sol_list_get_index(state, args, 0), *idx = sol_list_get_index(state, args, 1), *iidx = sol_cast_int(state, idx);
1114
+    sol_object_t *res = sol_list_truncate(state, list, iidx->ival);
1115
+    sol_obj_free(list);
1116
+	sol_obj_free(idx);
1117
+	sol_obj_free(iidx);
1118
+    return res;
1105 1119
 }
1106 1120
 
1107 1121
 sol_object_t *sol_f_list_map(sol_state_t *state, sol_object_t *args) {
@@ -2304,7 +2318,7 @@ sol_object_t *sol_f_buffer_fromstring(sol_state_t *state, sol_object_t *args) {
2304 2318
 
2305 2319
 sol_object_t *sol_f_buffer_fromobject(sol_state_t *state, sol_object_t *args) {
2306 2320
 	sol_object_t *obj = sol_list_get_index(state, args, 0);
2307
-	sol_object_t *buf = sol_new_buffer(state, obj, sizeof(sol_object_t), OWN_CALLF, (sol_freefunc_t) sol_obj_free, (sol_movefunc_t) sol_obj_acquire);
2321
+	sol_object_t *buf = sol_new_buffer(state, obj, sizeof(sol_object_t), OWN_CALLF, (sol_freefunc_t) state->obfuncs.destr, (sol_movefunc_t) state->obfuncs.copy);
2308 2322
 	//Keep ref to obj so buf remains alive
2309 2323
 	return buf;
2310 2324
 }

+ 42
- 0
dump.sol View File

@@ -0,0 +1,42 @@
1
+func dump(obj, indent)
2
+	if None == indent then
3
+		indent = 0
4
+		seen = {}
5
+	end
6
+	io.stdout:write(" "*indent)
7
+	if type(obj) == "list" then
8
+		buf = buffer.fromobject(obj)
9
+		addr = buf:address()
10
+		if None != seen[obj] then
11
+			print("...("+addr+")")
12
+			return
13
+		end
14
+		seen[obj] = 1
15
+		print("[")
16
+		for elem in obj do
17
+			dump(elem, indent+2)
18
+		end
19
+		print(" "*indent+"] =("+addr+")")
20
+		return
21
+	end
22
+	if type(obj) == "map" then
23
+		buf = buffer.fromobject(obj)
24
+		addr = buf:address()
25
+		if None != seen[obj] then
26
+			print("...("+addr+")")
27
+			return
28
+		end
29
+		seen[obj] = 1
30
+		print("{")
31
+		for key in obj do
32
+			io.stdout:write(" "*(indent+2))
33
+			prepr(key, ":")
34
+			dump(obj[key], indent+4)
35
+		end
36
+		print(" "*indent+"} =("+addr+")")
37
+		return
38
+	end
39
+	prepr(obj)
40
+end
41
+
42
+dump.closure.seen = {}

+ 94
- 10
gc.c View File

@@ -1,11 +1,9 @@
1 1
 #include <stdlib.h>
2
+#include <stdio.h>
3
+#include <time.h>
2 4
 #include "sol.h"
3 5
 
4
-#ifdef DEBUG_GC
5
-
6
-#else
7
-
8
-sol_object_t *sol_alloc_object(sol_state_t *state) {
6
+sol_object_t *_sol_gc_alloc_object(sol_state_t *state) {
9 7
 	sol_object_t *res = malloc(sizeof(sol_object_t));
10 8
 	if(!res) {
11 9
 		sol_set_error(state, state->OutOfMemory);
@@ -16,11 +14,7 @@ sol_object_t *sol_alloc_object(sol_state_t *state) {
16 14
 	return sol_incref(res);
17 15
 }
18 16
 
19
-sol_object_t *sol_obj_acquire(sol_object_t *obj) {
20
-	return sol_incref(obj);
21
-}
22
-
23
-void sol_obj_free(sol_object_t *obj) {
17
+void _sol_gc_obj_free(sol_object_t *obj) {
24 18
 	if(!obj) {
25 19
 		printf("WARNING: Attempt to free NULL\n");
26 20
 		return;
@@ -34,6 +28,93 @@ void sol_obj_free(sol_object_t *obj) {
34 28
 	}
35 29
 }
36 30
 
31
+sol_object_t *sol_obj_acquire(sol_object_t *obj) {
32
+	return sol_incref(obj);
33
+}
34
+
35
+#ifdef DEBUG_GC
36
+
37
+static FILE *gclog = NULL;
38
+static int gcrefcnt = 0;
39
+
40
+static char gctime[64];
41
+
42
+/*
43
+char *prtime() {
44
+	time_t t;
45
+	struct tm t2;
46
+	time(&t);
47
+	localtime_r(&t, &t2);
48
+	strftime(gctime, 64, "%Y/%m/%d %T", &t2);
49
+	return gctime;
50
+}
51
+*/
52
+
53
+char *prtime() {return "";}
54
+
55
+void sol_mm_initialize(sol_state_t *state) {
56
+	if(gclog) {
57
+		fprintf(gclog, " === Reopened at %s ===\n", prtime());
58
+	} else {
59
+		gclog = fopen("gclog.txt", "a");
60
+		fprintf(gclog, "=== Opened at %s ===\n", prtime());
61
+	}
62
+	gcrefcnt++;
63
+}
64
+
65
+void sol_mm_finalize(sol_state_t *state) {
66
+	gcrefcnt--;
67
+	fprintf(gclog, "=== Closed at %s ===\n", prtime());
68
+	if(gcrefcnt <= 0) {
69
+		fflush(gclog);
70
+		fclose(gclog);
71
+		gclog = NULL;
72
+	}
73
+}
74
+
75
+sol_object_t *_int_sol_alloc_object(const char *func, sol_state_t *state) {
76
+	fprintf(gclog, "%s\t%s\tALLOC\n", prtime(), func);
77
+	return _sol_gc_alloc_object(state);
78
+}
79
+
80
+sol_object_t *_int_sol_incref(const char *func, sol_object_t *obj) {
81
+	int oldref = obj->refcnt++;
82
+	fprintf(gclog, "%s\t%s\tINCREF\t%s\t%p\t%d\t->\t%d\n", prtime(), func, obj->ops->tname, obj, oldref, obj->refcnt);
83
+	return obj;
84
+}
85
+
86
+void _int_sol_obj_free(const char *func, sol_object_t *obj) {
87
+	fprintf(gclog, "%s\t%s\tDECREF\t%s\t%p\t%d\t->\t%d\n", prtime(), func, obj->ops->tname, obj, obj->refcnt, obj->refcnt - 1);
88
+	_sol_gc_obj_free(obj);
89
+}
90
+
91
+
92
+void sol_obj_release(sol_object_t *obj) {
93
+	fprintf(gclog, "%s\t\tFREE\t%s\t%p\n", prtime(), obj->ops->tname, obj);
94
+    if(obj->ops->free) obj->ops->free(NULL, obj);
95
+    free(obj);
96
+}
97
+
98
+sol_object_t *_sol_gc_dsl_copier(sol_object_t *obj) {
99
+	fprintf(gclog, "%s\t<dsl>\tINCREF\t%s\t%p\t%d\t->\t%d\n", prtime(), obj->ops->tname, obj, obj->refcnt, ++obj->refcnt);
100
+	return obj;
101
+}
102
+
103
+void _sol_gc_dsl_destructor(sol_object_t *obj) {
104
+	fprintf(gclog, "%s\t<dsl>\tDECREF\t%s\t%p\t%d\t->\t%d\n", prtime(), obj->ops->tname, obj, obj->refcnt, obj->refcnt - 1);
105
+	_sol_gc_obj_free(obj);
106
+}
107
+
108
+#else
109
+
110
+sol_object_t *sol_alloc_object(sol_state_t *state) {
111
+	return _sol_gc_alloc_object(state);
112
+}
113
+
114
+void sol_obj_free(sol_object_t *obj) {
115
+	_sol_gc_obj_free(obj);
116
+}
117
+
37 118
 void sol_obj_release(sol_object_t *obj) {
38 119
 	if(obj->ops->free) {
39 120
 		obj->ops->free(NULL, obj);
@@ -41,4 +122,7 @@ void sol_obj_release(sol_object_t *obj) {
41 122
 	free(obj);
42 123
 }
43 124
 
125
+void sol_mm_initialize(sol_state_t *state) {}
126
+void sol_mm_finalize(sol_state_t *state) {}
127
+
44 128
 #endif

+ 71
- 0
gcstat.py View File

@@ -0,0 +1,71 @@
1
+import sys
2
+from collections import defaultdict
3
+
4
+f = open('gclog.txt', 'r')
5
+
6
+incs = defaultdict(lambda: 0)
7
+decs = defaultdict(lambda: 0)
8
+refs = defaultdict(lambda: 0)
9
+seenrefs = {}
10
+types = {}
11
+
12
+lineno = 0
13
+
14
+for line in f:
15
+	lineno += 1
16
+	if lineno % 10000 == 0:
17
+		print 'Processing line', lineno
18
+	if line[0] == '=':
19
+		continue
20
+	parts = line.split('\t')
21
+	if parts[2] == 'INCREF':
22
+		incs[parts[1]] += 1
23
+		refs[parts[4]] += 1
24
+		types[parts[4]] = parts[3]
25
+		seenrefs[parts[4]] = parts[7]
26
+	elif parts[2] == 'DECREF':
27
+		decs[parts[1]] += 1
28
+		refs[parts[4]] -= 1
29
+		types[parts[4]] = parts[3]
30
+		seenrefs[parts[4]] = parts[7]
31
+
32
+incpairs = incs.items()
33
+decpairs = decs.items()
34
+refpairs = refs.items()
35
+
36
+incpairs.sort(key=lambda it: it[1], reverse=True)
37
+decpairs.sort(key=lambda it: it[1], reverse=True)
38
+refpairs.sort(key=lambda it: it[1], reverse=True)
39
+
40
+for k in seenrefs:
41
+	seenrefs[k] = int(seenrefs[k])
42
+
43
+totincs = sum((i[1] for i in incpairs))
44
+totdecs = sum((i[1] for i in decpairs))
45
+totliving = sum((i[1] for i in refpairs))
46
+totsol = sum(seenrefs.itervalues())
47
+
48
+out = open('gcstat.txt', 'w')
49
+sys.stdout = out
50
+
51
+print '=== Totals ==='
52
+print '= Increfs:', totincs
53
+print '= Decrefs:', totdecs
54
+print '= Diff:', totincs - totdecs
55
+print '= Living (our estimate):', totliving
56
+print '= Living (according to Sol):', totsol
57
+
58
+print '=== Functions, sorted by increments ==='
59
+print '= %-30s%-8s%-8s'%('name', 'incs', 'decs')
60
+for func, inccnt in incpairs:
61
+	print '%-32s%-8d%-8d'%(func, inccnt, decs[func])
62
+
63
+print '=== Functions, sorted by decrements ==='
64
+print '= %-30s%-8s%-8s'%('name', 'decs', 'incs')
65
+for func, deccnt in decpairs:
66
+	print '%-32s%-8d%-8d'%(func, deccnt, incs[func])
67
+
68
+print '=== Objects alive at cleanup ==='
69
+print '= %-14s%-16s%-8s%-8s'%('addr', 'type', 'refs', 'solrefs')
70
+for addr, refcnt in refpairs:
71
+	print '%-16s%-16s%-8d%-8d'%(addr, types[addr], refcnt, seenrefs[addr])

+ 956
- 928
lex.yy.c
File diff suppressed because it is too large
View File


+ 2
- 2
object.c View File

@@ -330,7 +330,7 @@ sol_object_t *sol_map_mcell(sol_state_t *state, sol_object_t *map, sol_object_t
330 330
 int sol_map_has(sol_state_t *state, sol_object_t *map, sol_object_t *key) {
331 331
 	sol_object_t *mcell = sol_map_mcell(state, map, key);
332 332
 	int res = sol_is_none(state, mcell);
333
-	sol_obj_free(mcell);
333
+	if(sol_is_none(state, mcell)) sol_decref(mcell);
334 334
 	return res;
335 335
 }
336 336
 
@@ -637,4 +637,4 @@ sol_object_t *sol_f_stream_free(sol_state_t *state, sol_object_t *stream) {
637 637
 	//printf("IO: Closing open file\n");
638 638
 	fclose(stream->stream);
639 639
 	return stream;
640
-}
640
+}

+ 4279
- 4060
parser.output
File diff suppressed because it is too large
View File


+ 2097
- 2610
parser.tab.c
File diff suppressed because it is too large
View File


+ 76
- 86
parser.tab.h View File

@@ -1,8 +1,8 @@
1
-/* A Bison parser, made by GNU Bison 2.7.12-4996.  */
1
+/* A Bison parser, made by GNU Bison 3.0.2.  */
2 2
 
3 3
 /* Bison interface for Yacc-like parsers in C
4 4
 
5
-      Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
5
+   Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
6 6
 
7 7
    This program is free software: you can redistribute it and/or modify
8 8
    it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@
32 32
 
33 33
 #ifndef YY_YY_PARSER_TAB_H_INCLUDED
34 34
 # define YY_YY_PARSER_TAB_H_INCLUDED
35
-/* Enabling traces.  */
35
+/* Debug traces.  */
36 36
 #ifndef YYDEBUG
37 37
 # define YYDEBUG 1
38 38
 #endif
@@ -40,105 +40,95 @@
40 40
 extern int yydebug;
41 41
 #endif
42 42
 
43
-/* Tokens.  */
43
+/* Token type.  */
44 44
 #ifndef YYTOKENTYPE
45 45
 # define YYTOKENTYPE
46
-/* Put the tokens into the symbol table, so that GDB and other debuggers
47
-   know about them.  */
48
-enum yytokentype {
49
-	IF = 258,
50
-	THEN = 259,
51
-	ELSE = 260,
52
-	WHILE = 261,
53
-	FOR = 262,
54
-	IN = 263,
55
-	DO = 264,
56
-	FUNC = 265,
57
-	RETURN = 266,
58
-	BREAK = 267,
59
-	CONTINUE = 268,
60
-	END = 269,
61
-	NONE = 270,
62
-	IDENT = 271,
63
-	INT = 272,
64
-	FLOAT = 273,
65
-	STRING = 274,
66
-	PLUS = 275,
67
-	MINUS = 276,
68
-	STAR = 277,
69
-	SLASH = 278,
70
-	PERCENT = 279,
71
-	DSTAR = 280,
72
-	BAND = 281,
73
-	BOR = 282,
74
-	BXOR = 283,
75
-	BNOT = 284,
76
-	LAND = 285,
77
-	LOR = 286,
78
-	LNOT = 287,
79
-	ASSIGN = 288,
80
-	ASSIGNPLUS = 289,
81
-	ASSIGNMINUS = 290,
82
-	ASSIGNSTAR = 291,
83
-	ASSIGNSLASH = 292,
84
-	ASSIGNDSTAR = 293,
85
-	ASSIGNBAND = 294,
86
-	ASSIGNBOR = 295,
87
-	ASSIGNBXOR = 296,
88
-	EQUAL = 297,
89
-	LESS = 298,
90
-	GREATER = 299,
91
-	LESSEQ = 300,
92
-	GREATEREQ = 301,
93
-	RSHIFT = 302,
94
-	LSHIFT = 303,
95
-	LBRACE = 304,
96
-	RBRACE = 305,
97
-	LPAREN = 306,
98
-	RPAREN = 307,
99
-	LBRACKET = 308,
100
-	RBRACKET = 309,
101
-	DOT = 310,
102
-	COLON = 311,
103
-	SEMICOLON = 312,
104
-	COMMA = 313,
105
-	POUND = 314
106
-};
46
+  enum yytokentype
47
+  {
48
+    IF = 258,
49
+    THEN = 259,
50
+    ELSE = 260,
51
+    WHILE = 261,
52
+    FOR = 262,
53
+    IN = 263,
54
+    DO = 264,
55
+    FUNC = 265,
56
+    RETURN = 266,
57
+    BREAK = 267,
58
+    CONTINUE = 268,
59
+    END = 269,
60
+    NONE = 270,
61
+    IDENT = 271,
62
+    INT = 272,
63
+    FLOAT = 273,
64
+    STRING = 274,
65
+    PLUS = 275,
66
+    MINUS = 276,
67
+    STAR = 277,
68
+    SLASH = 278,
69
+    PERCENT = 279,
70
+    DSTAR = 280,
71
+    BAND = 281,
72
+    BOR = 282,
73
+    BXOR = 283,
74
+    BNOT = 284,
75
+    LAND = 285,
76
+    LOR = 286,
77
+    LNOT = 287,
78
+    ASSIGN = 288,
79
+    ASSIGNPLUS = 289,
80
+    ASSIGNMINUS = 290,
81
+    ASSIGNSTAR = 291,
82
+    ASSIGNSLASH = 292,
83
+    ASSIGNDSTAR = 293,
84
+    ASSIGNBAND = 294,
85
+    ASSIGNBOR = 295,
86
+    ASSIGNBXOR = 296,
87
+    EQUAL = 297,
88
+    NEQUAL = 298,
89
+    LESS = 299,
90
+    GREATER = 300,
91
+    LESSEQ = 301,
92
+    GREATEREQ = 302,
93
+    RSHIFT = 303,
94
+    LSHIFT = 304,
95
+    LBRACE = 305,
96
+    RBRACE = 306,
97
+    LPAREN = 307,
98
+    RPAREN = 308,
99
+    LBRACKET = 309,
100
+    RBRACKET = 310,
101
+    DOT = 311,
102
+    COLON = 312,
103
+    SEMICOLON = 313,
104
+    COMMA = 314,
105
+    POUND = 315
106
+  };
107 107
 #endif
108 108
 
109
-
109
+/* Value type.  */
110 110
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
111 111
 typedef int YYSTYPE;
112 112
 # define YYSTYPE_IS_TRIVIAL 1
113
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
114 113
 # define YYSTYPE_IS_DECLARED 1
115 114
 #endif
116 115
 
116
+/* Location type.  */
117 117
 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
118
-typedef struct YYLTYPE {
119
-	int first_line;
120
-	int first_column;
121
-	int last_line;
122
-	int last_column;
123
-} YYLTYPE;
124
-# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
118
+typedef struct YYLTYPE YYLTYPE;
119
+struct YYLTYPE
120
+{
121
+  int first_line;
122
+  int first_column;
123
+  int last_line;
124
+  int last_column;
125
+};
125 126
 # define YYLTYPE_IS_DECLARED 1
126 127
 # define YYLTYPE_IS_TRIVIAL 1
127 128
 #endif
128 129
 
129 130
 
130
-#ifdef YYPARSE_PARAM
131
-#if defined __STDC__ || defined __cplusplus
132
-int yyparse (void *YYPARSE_PARAM);
133
-#else
134
-int yyparse ();
135
-#endif
136
-#else /* ! YYPARSE_PARAM */
137
-#if defined __STDC__ || defined __cplusplus
131
+
138 132
 int yyparse (stmt_node **program);
139
-#else
140
-int yyparse ();
141
-#endif
142
-#endif /* ! YYPARSE_PARAM */
143 133
 
144 134
 #endif /* !YY_YY_PARSER_TAB_H_INCLUDED  */

+ 2
- 1
parser.y View File

@@ -19,7 +19,7 @@
19 19
 %token INT FLOAT STRING
20 20
 %token PLUS MINUS STAR SLASH PERCENT DSTAR BAND BOR BXOR BNOT LAND LOR LNOT
21 21
 %token ASSIGN ASSIGNPLUS ASSIGNMINUS ASSIGNSTAR ASSIGNSLASH ASSIGNDSTAR ASSIGNBAND ASSIGNBOR ASSIGNBXOR
22
-%token EQUAL LESS GREATER LESSEQ GREATEREQ RSHIFT LSHIFT
22
+%token EQUAL NEQUAL LESS GREATER LESSEQ GREATEREQ RSHIFT LSHIFT
23 23
 %token LBRACE RBRACE LPAREN RPAREN LBRACKET RBRACKET DOT COLON SEMICOLON COMMA POUND
24 24
 
25 25
 %parse-param {stmt_node **program}
@@ -258,6 +258,7 @@ ulogic_expr:
258 258
 
259 259
 rel_expr:
260 260
   term_expr EQUAL rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_EQUAL; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
261
+| term_expr NEQUAL rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_NEQUAL; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
261 262
 | term_expr LESS rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LESS; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
262 263
 | term_expr GREATER rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_GREATER; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }
263 264
 | term_expr LESSEQ rel_expr { $$ = NEW_EX(); AS_EX($$)->type = EX_BINOP; AS_EX($$)->binop = NEW(binop_node); AS_EX($$)->binop->type = OP_LESSEQ; AS_EX($$)->binop->left = $1; AS_EX($$)->binop->right = $3; }

+ 4
- 0
runtime.c View File

@@ -306,6 +306,10 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
306 306
 					res = sol_new_int(state, BOOL_TO_INT(sol_cast_int(state, left->ops->cmp(state, list))->ival == 0));
307 307
 					break;
308 308
 
309
+				case OP_NEQUAL:
310
+					res = sol_new_int(state, BOOL_TO_INT(sol_cast_int(state, left->ops->cmp(state, list))->ival != 0));
311
+					break;
312
+
309 313
 				case OP_LESS:
310 314
 					res = sol_new_int(state, BOOL_TO_INT(sol_cast_int(state, left->ops->cmp(state, list))->ival < 0));
311 315
 					break;

+ 12
- 7
sol.h View File

@@ -9,8 +9,8 @@
9 9
 #include <stdarg.h>
10 10
 #include "dsl/dsl.h"
11 11
 
12
-#define VERSION "0.1a0"
13
-#define HEXVER 0x0001A00
12
+#define VERSION "0.1a1"
13
+#define HEXVER 0x0001A01
14 14
 
15 15
 // Forward declarations:
16 16
 struct sol_tag_object_t;
@@ -181,9 +181,6 @@ typedef struct sol_tag_state_t {
181 181
 	sol_object_t *modules;
182 182
 	sol_object_t *methods;
183 183
 	dsl_object_funcs obfuncs;
184
-#ifdef DEBUG_GC
185
-	dsl_seq *objects;
186
-#endif
187 184
 } sol_state_t;
188 185
 
189 186
 // state.c
@@ -506,14 +503,23 @@ sol_object_t *sol_util_call(sol_state_t *, sol_object_t *, int *, int, ...);
506 503
 
507 504
 sol_object_t *_int_sol_incref(const char *, sol_object_t *);
508 505
 void _int_sol_obj_free(const char *, sol_object_t *);
506
+sol_object_t *_sol_gc_dsl_copier(sol_object_t *);
507
+void _sol_gc_dsl_destructor(sol_object_t *);
508
+
509
+sol_object_t *_int_sol_alloc_object(const char *, sol_state_t *);
510
+
509 511
 #define sol_incref(obj) (_int_sol_incref(__func__, (obj)))
510 512
 #define sol_obj_free(obj) (_int_sol_obj_free(__func__, (obj)))
511 513
 
514
+#define sol_alloc_object(state) (_int_sol_alloc_object(__func__, (state)))
515
+
512 516
 #else
513 517
 
514 518
 #define sol_incref(obj) (++((obj)->refcnt), obj)
515 519
 void sol_obj_free(sol_object_t *);
516 520
 
521
+sol_object_t *sol_alloc_object(sol_state_t *);
522
+
517 523
 #endif
518 524
 
519 525
 #define sol_decref(obj) (--((obj)->refcnt))
@@ -521,8 +527,7 @@ void sol_obj_free(sol_object_t *);
521 527
 sol_object_t *sol_obj_acquire(sol_object_t *);
522 528
 void sol_obj_release(sol_object_t *);
523 529
 
524
-sol_object_t *sol_alloc_object(sol_state_t *);
525
-
530
+void sol_mm_initialize(sol_state_t *);
526 531
 void sol_mm_finalize(sol_state_t *);
527 532
 
528 533
 #define AS_OBJ(x) ((sol_object_t *) (x))

+ 5
- 0
solrun.c View File

@@ -55,6 +55,11 @@ int main(int argc, char **argv) {
55 55
 			ob_print(state.error);
56 56
 			printf("\n");
57 57
 		}
58
+		if(state.ret) {
59
+			printf("Toplevel return: ");
60
+			ob_print(state.ret);
61
+			printf("\n");
62
+		}
58 63
 		//st_free(program);
59 64
 		sol_state_cleanup(&state);
60 65
 		return 0;

+ 16
- 0
state.c View File

@@ -6,6 +6,8 @@ int sol_state_init(sol_state_t *state) {
6 6
 	sol_object_t *globals, *mod, *meths;
7 7
 	sol_object_t *btype, *bsize, *bobj;
8 8
 
9
+	sol_mm_initialize(state);
10
+
9 11
 	state->None = NULL;
10 12
 	state->OutOfMemory = NULL;
11 13
 	state->scopes = NULL;
@@ -14,6 +16,12 @@ int sol_state_init(sol_state_t *state) {
14 16
 	state->ret = NULL;
15 17
 	state->sflag = SF_NORMAL;
16 18
 
19
+#ifdef DEBUG_GC
20
+	// This is necessary for DEBUG_GC's early allocation; it gets overwritten,
21
+	// unfortunately, during sol_ops_init below, so it's duplicated.
22
+	state->SingletOps.tname = "singlet";
23
+#endif
24
+
17 25
 	// If any of the following fail, some very weird things are happening.
18 26
 	if(!(state->None = sol_new_singlet(state, "None"))) {
19 27
 		goto cleanup;
@@ -155,8 +163,13 @@ int sol_state_init(sol_state_t *state) {
155 163
 	state->StreamOps.free = sol_f_stream_free;
156 164
 	state->StreamOps.tostring = sol_f_stream_tostring;
157 165
 
166
+#ifdef DEBUG_GC
167
+	state->obfuncs.copy = (dsl_copier) _sol_gc_dsl_copier;
168
+	state->obfuncs.destr = (dsl_destructor) _sol_gc_dsl_destructor;
169
+#else
158 170
 	state->obfuncs.copy = (dsl_copier) sol_obj_acquire;
159 171
 	state->obfuncs.destr = (dsl_destructor) sol_obj_free;
172
+#endif
160 173
 
161 174
 	state->error = state->None;
162 175
 	state->scopes = sol_new_list(state);
@@ -246,6 +259,7 @@ int sol_state_init(sol_state_t *state) {
246 259
 	sol_map_set_name(state, mod, "OP_LAND", sol_new_int(state, OP_LAND));
247 260
 	sol_map_set_name(state, mod, "OP_LOR", sol_new_int(state, OP_LOR));
248 261
 	sol_map_set_name(state, mod, "OP_EQUAL", sol_new_int(state, OP_EQUAL));
262
+	sol_map_set_name(state, mod, "OP_NEQUAL", sol_new_int(state, OP_NEQUAL));
249 263
 	sol_map_set_name(state, mod, "OP_LESS", sol_new_int(state, OP_LESS));
250 264
 	sol_map_set_name(state, mod, "OP_GREATER", sol_new_int(state, OP_GREATER));
251 265
 	sol_map_set_name(state, mod, "OP_LESSEQ", sol_new_int(state, OP_LESSEQ));
@@ -417,6 +431,7 @@ void sol_state_cleanup(sol_state_t *state) {
417 431
 	}
418 432
 	sol_obj_free(state->modules);
419 433
 	sol_obj_free(state->methods);
434
+	sol_mm_finalize(state);
420 435
 }
421 436
 
422 437
 sol_object_t *sol_state_resolve(sol_state_t *state, sol_object_t *key) {
@@ -443,6 +458,7 @@ sol_object_t *sol_state_resolve(sol_state_t *state, sol_object_t *key) {
443 458
 	if(!sol_is_none(state, temp)) {
444 459
 		return temp;
445 460
 	}
461
+	// sol_obj_free(temp);
446 462
 
447 463
 	return sol_incref(state->None);
448 464
 }

+ 1
- 0
test_monty.sol View File

@@ -8,3 +8,4 @@ print('Resulting statement:')
8 8
 ast.print(stmt)
9 9
 print('---Running results begin here---')
10 10
 stmt()
11
+io.stdin:read(io.LINE)

+ 2
- 0
tokenizer.lex View File

@@ -164,6 +164,8 @@ None { return NONE; }
164 164
 
165 165
 "==" { return EQUAL; }
166 166
 
167
+"!=" { return NEQUAL; }
168
+
167 169
 "<" { return LESS; }
168 170
 
169 171
 ">" { return GREATER; }

Loading…
Cancel
Save