|
103 | 103 | from .__float import _orf, _andf, _notf, _xorf, _float_oper, _fpush, _fpop |
104 | 104 |
|
105 | 105 | # String arithmetic functions |
106 | | -from .__str import _addstr |
| 106 | +from .__str import _addstr, _loadstr, _storestr, _jzerostr, _jnzerostr, _retstr, _paramstr, _fparamstr |
107 | 107 |
|
108 | 108 | # String comparison functions |
109 | 109 | from .__str import _ltstr, _gtstr, _eqstr, _lestr, _gestr, _nestr, _str_oper, _lenstr |
@@ -704,48 +704,6 @@ def _in(ins): |
704 | 704 | return output |
705 | 705 |
|
706 | 706 |
|
707 | | -def _loadstr(ins): |
708 | | - """Loads a string value from a memory address.""" |
709 | | - temporal, output = _str_oper(ins.quad[2], no_exaf=True) |
710 | | - |
711 | | - if not temporal: |
712 | | - output.append(runtime_call(RuntimeLabel.LOADSTR)) |
713 | | - |
714 | | - output.append("push hl") |
715 | | - return output |
716 | | - |
717 | | - |
718 | | -def _storestr(ins): |
719 | | - """Stores a string value into a memory address. |
720 | | - It copies content of 2nd operand (string), into 1st, reallocating |
721 | | - dynamic memory for the 1st str. These instruction DOES ALLOW |
722 | | - immediate strings for the 2nd parameter, starting with '#'. |
723 | | -
|
724 | | - Must prepend '#' (immediate sigil) to 1st operand, as we need |
725 | | - the & address of the destination. |
726 | | - """ |
727 | | - op1 = ins.quad[1] |
728 | | - indirect = op1[0] == "*" |
729 | | - if indirect: |
730 | | - op1 = op1[1:] |
731 | | - |
732 | | - immediate = op1[0] == "#" |
733 | | - if immediate and not indirect: |
734 | | - raise InvalidIC("storestr does not allow immediate destination", ins.quad) |
735 | | - |
736 | | - if not indirect: |
737 | | - op1 = "#" + op1 |
738 | | - |
739 | | - tmp1, tmp2, output = _str_oper(op1, ins.quad[2], no_exaf=True) |
740 | | - |
741 | | - if not tmp2: |
742 | | - output.append(runtime_call(RuntimeLabel.STORE_STR)) |
743 | | - else: |
744 | | - output.append(runtime_call(RuntimeLabel.STORE_STR2)) |
745 | | - |
746 | | - return output |
747 | | - |
748 | | - |
749 | 707 | def _cast(ins): |
750 | 708 | """Convert data from typeA to typeB (only numeric data types)""" |
751 | 709 | # Signed and unsigned types are the same in the Z80 |
@@ -803,79 +761,11 @@ def _jump(ins): |
803 | 761 | return ["jp %s" % str(ins.quad[1])] |
804 | 762 |
|
805 | 763 |
|
806 | | -def _jzerostr(ins): |
807 | | - """Jumps if top of the stack contains a NULL pointer |
808 | | - or its len is Zero |
809 | | - """ |
810 | | - # TODO: Check if this is ever used? |
811 | | - output = [] |
812 | | - disposable = False # True if string must be freed from memory |
813 | | - |
814 | | - if ins.quad[1][0] == "_": # Variable? |
815 | | - output.append("ld hl, (%s)" % ins.quad[1][0]) |
816 | | - else: |
817 | | - output.append("pop hl") |
818 | | - output.append("push hl") # Saves it for later |
819 | | - disposable = True |
820 | | - |
821 | | - output.append(runtime_call(RuntimeLabel.STRLEN)) |
822 | | - |
823 | | - if disposable: |
824 | | - output.append("ex (sp), hl") |
825 | | - output.append(runtime_call(RuntimeLabel.MEM_FREE)) |
826 | | - output.append("pop hl") |
827 | | - |
828 | | - output.append("ld a, h") |
829 | | - output.append("or l") |
830 | | - output.append("jp z, %s" % str(ins.quad[2])) |
831 | | - return output |
832 | | - |
833 | | - |
834 | | -def _jnzerostr(ins): |
835 | | - """Jumps if top of the stack contains a string with |
836 | | - at less 1 char |
837 | | - """ |
838 | | - # TODO: Check if this is ever used? |
839 | | - output = [] |
840 | | - disposable = False # True if string must be freed from memory |
841 | | - |
842 | | - if ins.quad[1][0] == "_": # Variable? |
843 | | - output.append("ld hl, (%s)" % ins.quad[1][0]) |
844 | | - else: |
845 | | - output.append("pop hl") |
846 | | - output.append("push hl") # Saves it for later |
847 | | - disposable = True |
848 | | - |
849 | | - output.append(runtime_call(RuntimeLabel.STRLEN)) |
850 | | - |
851 | | - if disposable: |
852 | | - output.append("ex (sp), hl") |
853 | | - output.append(runtime_call(RuntimeLabel.MEM_FREE)) |
854 | | - output.append("pop hl") |
855 | | - |
856 | | - output.append("ld a, h") |
857 | | - output.append("or l") |
858 | | - output.append("jp nz, %s" % str(ins.quad[2])) |
859 | | - return output |
860 | | - |
861 | | - |
862 | 764 | def _ret(ins): |
863 | 765 | """Returns from a procedure / function""" |
864 | 766 | return ["jp %s" % str(ins.quad[1])] |
865 | 767 |
|
866 | 768 |
|
867 | | -def _retstr(ins): |
868 | | - """Returns from a procedure / function a string pointer (16bits) value""" |
869 | | - tmp, output = _str_oper(ins.quad[1], no_exaf=True) |
870 | | - |
871 | | - if not tmp: |
872 | | - output.append(runtime_call(RuntimeLabel.LOADSTR)) |
873 | | - |
874 | | - output.append("#pragma opt require hl") |
875 | | - output.append("jp %s" % str(ins.quad[2])) |
876 | | - return output |
877 | | - |
878 | | - |
879 | 769 | def _call(ins): |
880 | 770 | """Calls a function XXXX (or address XXXX) |
881 | 771 | 2nd parameter contains size of the returning result if any, and will be |
@@ -1009,33 +899,6 @@ def _enter(ins): |
1009 | 899 | return output |
1010 | 900 |
|
1011 | 901 |
|
1012 | | -def _paramstr(ins): |
1013 | | - """Pushes an 16 bit unsigned value, which points |
1014 | | - to a string. For indirect values, it will push |
1015 | | - the pointer to the pointer :-) |
1016 | | - """ |
1017 | | - (tmp, output) = _str_oper(ins.quad[1]) |
1018 | | - output.pop() # Remove a register flag (useless here) |
1019 | | - tmp = ins.quad[1][0] in ("#", "_") # Determine if the string must be duplicated |
1020 | | - |
1021 | | - if tmp: |
1022 | | - output.append(runtime_call(RuntimeLabel.LOADSTR)) # Must be duplicated |
1023 | | - |
1024 | | - output.append("push hl") |
1025 | | - return output |
1026 | | - |
1027 | | - |
1028 | | -def _fparamstr(ins): |
1029 | | - """Passes a string ptr as a __FASTCALL__ parameter. |
1030 | | - This is done by popping out of the stack for a |
1031 | | - value, or by loading it from memory (indirect) |
1032 | | - or directly (immediate) --prefixed with '#'-- |
1033 | | - """ |
1034 | | - (tmp1, output) = _str_oper(ins.quad[1]) |
1035 | | - |
1036 | | - return output |
1037 | | - |
1038 | | - |
1039 | 902 | def _memcopy(ins): |
1040 | 903 | """Copies a block of memory from param 2 addr |
1041 | 904 | to param 1 addr. |
|
0 commit comments