StdString.icl 1.79 KB
Newer Older
1 2 3
implementation module StdString

// ****************************************************************************************
4 5
//	Concurrent Clean Standard Library Module Version 3.0
//	Copyright 2019 University of Nijmegen
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// ****************************************************************************************

import	StdOverloaded

instance == {#Char}
where
 (==) :: !{#Char} !{#Char} -> Bool
 (==) a b
	= code inline {
		.d 2 0
			jsr eqAC
		.o 0 1 b	
	}

instance < {#Char}
where
 (<) :: !{#Char} !{#Char} -> Bool
 (<) a b
	= code inline {
		.d 2 0
			jsr cmpAC
		.o 0 1 i
			pushI 0
			gtI
	}

instance toString Int
where
34
 toString :: !Int -> {#Char}
35 36 37 38 39 40 41 42 43
 toString a
	= code inline {
		.d 0 1 i
			jsr ItoAC
		.o 1 0
	}

instance toString Char
where
44
 toString :: !Char -> {#Char}
45 46 47 48 49 50 51
 toString a
	= code inline {
			CtoAC
	}

instance toString Real
where
52
 toString :: !Real -> {#Char}
53 54
 toString a
	= code inline {
Camil Staps's avatar
Camil Staps committed
55
		.d 0 1 r
56 57 58
			jsr RtoAC
		.o 1 0
	}
Camil Staps's avatar
Camil Staps committed
59

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
instance toString Bool
where
 toString :: !Bool -> {#Char}
 toString a
	= code inline {
		.d 0 1 b
			jsr BtoAC
		.o 1 0
	}

instance toString {#Char}
where
 toString :: !{#Char} -> {#Char} //	dummy
 toString a
	= code inline {
		no_op
	}

instance fromString {#Char}
where
 fromString :: !{#Char} -> {#Char} //	dummy
 fromString a
	= code inline {
		no_op
	}

instance % {#Char}
where
 (%) ::!{#Char} !(!Int,!Int) -> {#Char}
 (%) str (a,b)
	= code inline {
		.d 1 2 ii
			jsr sliceAC
		.o 1 0
	}

instance +++ {#Char}
where
 (+++) :: !{#Char} !{#Char} -> {#Char}
 (+++) a b
	= code inline {
		.d 2 0
			jsr catAC
		.o 1 0
	}

(+++.) infixr 5 :: !{#Char} !{#Char} -> .{#Char}
(+++.) a b
	= code inline {
		.d 2 0
			jsr catAC
		.o 1 0
	}

(:=) infixl 9 :: !{#Char} !(!Int,!Char) -> {#Char}	//	update i-th element
(:=) s (i,c)
	= code inline {
		.d 1 2 ic
			jsr updateAC
		.o 1 0
	}