aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-06-26 23:41:21 -0500
committerCody <cody@codyq.dev>2023-06-26 23:41:21 -0500
commita3c5134ee7581168947df8a050c332d7cb7aa426 (patch)
tree01631812f37e4c3d124928a14f169796c58a7a0e /examples
parent8c9bd55e161ba5fcaea626a1db2e0b685ac4f096 (diff)
downloadsloth-a3c5134ee7581168947df8a050c332d7cb7aa426.tar.gz
Strings and so much more
Diffstat (limited to 'examples')
-rw-r--r--examples/hello.sloth40
-rw-r--r--examples/mandelbrot.sloth25
2 files changed, 17 insertions, 48 deletions
diff --git a/examples/hello.sloth b/examples/hello.sloth
index db71b01..13415a9 100644
--- a/examples/hello.sloth
+++ b/examples/hello.sloth
@@ -1,40 +1,6 @@
-fn test() [Int] {
- var list: [Int] = [500, 5, 7];
+foreign fn print(x: String) Void;
- vpushi(list, 3);
- vpushi(list, 3);
- vpushi(list, 3);
- vpushi(list, 5);
-
- var x: Int = vpopi(list);
- vpushi(list, x);
- vpushi(list, x * 2);
- vpushi(list, x * 3);
-
- return list;
-}
-
-fn testtwo(list: [Int]) Int {
- #vpopi(list);
- var x: Int = vpopi(list);
- return x;
-}
-
-fn testthree(list: [Int]) Int {
- var x: Int = vlen(list);
- return x;
-}
-
-foreign fn testback(x: Int) Void;
-
-fn testfour(list: [Int]) Int {
- vseti(list, 0, 888);
- var i: Int = 0;
- while i < vlen(list) {
- var value: Int = vgeti(list, i);
- testback(value);
- i = i + 1;
- }
+fn main() Int {
+ print("gaming\n");
return 0;
}
-
diff --git a/examples/mandelbrot.sloth b/examples/mandelbrot.sloth
index f9ebdc8..1765e8e 100644
--- a/examples/mandelbrot.sloth
+++ b/examples/mandelbrot.sloth
@@ -1,34 +1,37 @@
-foreign fn termpos(x: Int, y: Int);
foreign fn print(str: String);
+foreign fn printint(i: Int);
+foreign fn as_int(x: Float) Int;
+
+foreign fn termpos(x: Int, y: Int) Void;
fn main() Int{
var size: Float = 200.0;
var maxVal: Float = 4.0;
- var maxIter: Int = 50;
+ var maxIter: Float = 50.0;
var plane: Float = 4.0;
# lmao
- var x: Int = 0;
+ var x: Float = 0.0;
while x < size {
- var y: Int = 0;
+ var y: Float = 0.0;
while y < size {
var cReal: Float = (x * plane / size) - 2.0;
var cImg: Float = (y * plane / size) - 2.0;
var zReal: Float = 0.0;
var zImg: Float = 0.0;
- var count: Int = 0;
- while (zReal * zReal + zImg * zImg) <= maxVal && count < 4{
+ var count: Float = 0.0;
+ while (zReal * zReal + zImg * zImg) <= maxVal && count < maxIter {
var temp: Float = (zReal * zReal) - (zImg * zImg) + cReal;
zImg = 2.0 * zReal * zImg + cImg;
zReal = temp;
- count = count + 1;
+ count = count + 1.0;
}
- if count == maxIter {
- termpos(x, y);
+ if as_int(count) == as_int(maxIter) {
+ termpos(as_int(x), as_int(y));
print("*");
}
- y = y + 1;
+ y = y + 1.0;
}
- x = x + 1;
+ x = x + 1.0;
}
return 0;
}