Skip to content

Commit

Permalink
Add std lib to macro system
Browse files Browse the repository at this point in the history
  • Loading branch information
ArgosOfIthica committed Aug 6, 2023
1 parent 1c3e783 commit aa1edbf
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 217 deletions.
141 changes: 2 additions & 139 deletions scalu/native/std.scalu
Original file line number Diff line number Diff line change
@@ -1,147 +1,10 @@
sandbox std
map {
print: @print
bitshift_right: @bitshift_right
bitshift_left: @bitshift_left
multiply: @multiply
divide: @divide
rng: @rng
entropy_rng: @entropy_rng
char: @char
pow: @pow
sqrt: @sqrt
}


/* int to render = input */
service print {
jump (input) { {[echo 0]} {[echo 1]} {[echo 2]} {[echo 3]} {[echo 4]} {[echo 5]} {[echo 6]} {[echo 7]} {[echo 8]} {[echo 9]} {[echo 10]} {[echo 11]} {[echo 12]} {[echo 13]} {[echo 14]} {[echo 15]} {[echo 16]} {[echo 17]} {[echo 18]} {[echo 19]} {[echo 20]} {[echo 21]} {[echo 22]} {[echo 23]} {[echo 24]} {[echo 25]} {[echo 26]} {[echo 27]} {[echo 28]} {[echo 29]} {[echo 30]} {[echo 31]} {[echo 32]} {[echo 33]} {[echo 34]} {[echo 35]} {[echo 36]} {[echo 37]} {[echo 38]} {[echo 39]} {[echo 40]} {[echo 41]} {[echo 42]} {[echo 43]} {[echo 44]} {[echo 45]} {[echo 46]} {[echo 47]} {[echo 48]} {[echo 49]} {[echo 50]} {[echo 51]} {[echo 52]} {[echo 53]} {[echo 54]} {[echo 55]} {[echo 56]} {[echo 57]} {[echo 58]} {[echo 59]} {[echo 60]} {[echo 61]} {[echo 62]} {[echo 63]} {[echo 64]} {[echo 65]} {[echo 66]} {[echo 67]} {[echo 68]} {[echo 69]} {[echo 70]} {[echo 71]} {[echo 72]} {[echo 73]} {[echo 74]} {[echo 75]} {[echo 76]} {[echo 77]} {[echo 78]} {[echo 79]} {[echo 80]} {[echo 81]} {[echo 82]} {[echo 83]} {[echo 84]} {[echo 85]} {[echo 86]} {[echo 87]} {[echo 88]} {[echo 89]} {[echo 90]} {[echo 91]} {[echo 92]} {[echo 93]} {[echo 94]} {[echo 95]} {[echo 96]} {[echo 97]} {[echo 98]} {[echo 99]} {[echo 100]} {[echo 101]} {[echo 102]} {[echo 103]} {[echo 104]} {[echo 105]} {[echo 106]} {[echo 107]} {[echo 108]} {[echo 109]} {[echo 110]} {[echo 111]} {[echo 112]} {[echo 113]} {[echo 114]} {[echo 115]} {[echo 116]} {[echo 117]} {[echo 118]} {[echo 119]} {[echo 120]} {[echo 121]} {[echo 122]} {[echo 123]} {[echo 124]} {[echo 125]} {[echo 126]} {[echo 127]} {[echo 128]} {[echo 129]} {[echo 130]} {[echo 131]} {[echo 132]} {[echo 133]} {[echo 134]} {[echo 135]} {[echo 136]} {[echo 137]} {[echo 138]} {[echo 139]} {[echo 140]} {[echo 141]} {[echo 142]} {[echo 143]} {[echo 144]} {[echo 145]} {[echo 146]} {[echo 147]} {[echo 148]} {[echo 149]} {[echo 150]} {[echo 151]} {[echo 152]} {[echo 153]} {[echo 154]} {[echo 155]} {[echo 156]} {[echo 157]} {[echo 158]} {[echo 159]} {[echo 160]} {[echo 161]} {[echo 162]} {[echo 163]} {[echo 164]} {[echo 165]} {[echo 166]} {[echo 167]} {[echo 168]} {[echo 169]} {[echo 170]} {[echo 171]} {[echo 172]} {[echo 173]} {[echo 174]} {[echo 175]} {[echo 176]} {[echo 177]} {[echo 178]} {[echo 179]} {[echo 180]} {[echo 181]} {[echo 182]} {[echo 183]} {[echo 184]} {[echo 185]} {[echo 186]} {[echo 187]} {[echo 188]} {[echo 189]} {[echo 190]} {[echo 191]} {[echo 192]} {[echo 193]} {[echo 194]} {[echo 195]} {[echo 196]} {[echo 197]} {[echo 198]} {[echo 199]} {[echo 200]} {[echo 201]} {[echo 202]} {[echo 203]} {[echo 204]} {[echo 205]} {[echo 206]} {[echo 207]} {[echo 208]} {[echo 209]} {[echo 210]} {[echo 211]} {[echo 212]} {[echo 213]} {[echo 214]} {[echo 215]} {[echo 216]} {[echo 217]} {[echo 218]} {[echo 219]} {[echo 220]} {[echo 221]} {[echo 222]} {[echo 223]} {[echo 224]} {[echo 225]} {[echo 226]} {[echo 227]} {[echo 228]} {[echo 229]} {[echo 230]} {[echo 231]} {[echo 232]} {[echo 233]} {[echo 234]} {[echo 235]} {[echo 236]} {[echo 237]} {[echo 238]} {[echo 239]} {[echo 240]} {[echo 241]} {[echo 242]} {[echo 243]} {[echo 244]} {[echo 245]} {[echo 246]} {[echo 247]} {[echo 248]} {[echo 249]} {[echo 250]} {[echo 251]} {[echo 252]} {[echo 253]} {[echo 254]} {[echo 255]}}
}

/* num to bitshift = input, amount to shift = input2, answer = output */
service bitshift_right {
jump (input2) { {output = input >> 0} {output = input >> 1} {output = input >> 2} {output = input >> 3} {output = input >> 4} {output = input >> 5} {output = input >> 6} {output = input >> 7}}
}

/* num to bitshift = input, amount to shift = input2, answer = output */
service bitshift_left {
jump (input2) { {output = input << 0} {output = input << 1} {output = input << 2} {output = input << 3} {output = input << 4} {output = input << 5} {output = input << 6} {output = input << 7}}
}

/* multiplicand = input, multiplier = input2, product = output */
service multiply {
output = 0
if input2 > input {
temp = input2
temp2 = input
}
else {
temp = input
temp2 = input2
}
@multiply2
}

service multiply2 {
if temp2 != 0 {
temp3 = temp2 & 1
if temp3 == 1 {
output = output + temp
}
temp = temp << 1
temp2 = temp2 >> 1
@multiply2
}
}

/* dividend = input, divisor = input2, quotient = output, remainder = output2 */
service divide {
output = 0
temp = input
temp2 = input2
@divide2
}

service divide2 {
if (temp2 != 0) {
if (temp >= temp2) {
temp = temp - temp2
output = output + 1
@divide2
} else {
output2 = temp
}
} else {
output = 0 /* clamp to zero */
}
}

/* base = input, exponent = input2, product = output */
service pow {
if (input2 == 0) {
output = 1
}
else {
temp5 = input2
input2 = input /* For calling multiply service in pow2 */
@pow2
}
}

service pow2 {
if (temp5 == 1) {
output = input
} else {
@multiply
input = output
temp5 = temp5 - 1
@pow2
}
}

/* num to find sq of = input, floor(sqrt) = output */
service sqrt {
output = 0
temp2 = 1 << 6 /* The second from top bit is set */
temp3 = 0
temp4 = input
@sqrt2
}

service sqrt2 {
if (temp4 < temp2) {
temp2 = temp2 >> 2
@sqrt2
} else {
@sqrt3
}
}

service sqrt3 {
if (temp2 != 0) {
temp3 = output + temp2
if (temp4 < temp3) {
output = output >> 1
}
else {
temp4 = temp4 - (output + temp2)
output = (output >> 1) + temp2
}
temp2 = temp2 >> 2
@sqrt3
}
}

/* rng value = rng */
service rng {
rng = rng + 1
rng = rng ^ (rng << 7)
rng = rng ^ (rng >> 5)
rng = rng ^ (rng << 3)
}

service entropy_rng {
rng = rng + 1
service init {
input = 0
}

/* char to render = input */
Expand Down
Loading

0 comments on commit aa1edbf

Please sign in to comment.