From a3c5134ee7581168947df8a050c332d7cb7aa426 Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 26 Jun 2023 23:41:21 -0500 Subject: Strings and so much more --- examples/hello.sloth | 40 +++------------------------------------- examples/mandelbrot.sloth | 25 ++++++++++++++----------- 2 files changed, 17 insertions(+), 48 deletions(-) (limited to 'examples') 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; } -- cgit v1.2.3