diff --git a/examples/mandelbrot.sloth b/examples/mandelbrot.sloth index fb22b88..f9ebdc8 100644 --- a/examples/mandelbrot.sloth +++ b/examples/mandelbrot.sloth @@ -1,24 +1,34 @@ -val size: Int = 200; -val maxVal: Float = 4.0; -val maxIter: Int = 50; -val plane: Float = 4.0; +foreign fn termpos(x: Int, y: Int); +foreign fn print(str: String); -for x in 0 .. size { - for y in 0 .. size { - var cReal: Float = (x * plane / size) - 2; - var cImg: Float = (y * plane / size) - 2; - var zReal: Float = 0; - var zImg: Float = 0; - var count: Float = 0; - while (zReal * zReal + zImg * zImg) <= maxVal && count < 4{ - var temp: Float = (zReal * zReal) - (zImg * zImg) + cReal; - zImg = 2 * zReal * zImg + cImg; - zReal = temp; - count += 1; - } - if count == maxIter { - termpos(x, y); - print("*"); +fn main() Int{ + var size: Float = 200.0; + var maxVal: Float = 4.0; + var maxIter: Int = 50; + var plane: Float = 4.0; + # lmao + var x: Int = 0; + while x < size { + var y: Int = 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 temp: Float = (zReal * zReal) - (zImg * zImg) + cReal; + zImg = 2.0 * zReal * zImg + cImg; + zReal = temp; + count = count + 1; + } + if count == maxIter { + termpos(x, y); + print("*"); + } + y = y + 1; } + x = x + 1; } + return 0; } diff --git a/vim/ftdetect.vim b/vim/ftdetect.vim new file mode 100644 index 0000000..c19a7ca --- /dev/null +++ b/vim/ftdetect.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.sloth set filetype=sloth diff --git a/vim/syntax.vim b/vim/syntax.vim new file mode 100644 index 0000000..af0f062 --- /dev/null +++ b/vim/syntax.vim @@ -0,0 +1,8 @@ +:syntax keyword Statement while fn foreign fn var if else return as in +:syntax keyword Type Int String Float Void Bool +:syntax match Number '[1234567890]' +:syntax match Operator '[+ \- \* \/ <= == >= &&]' +:syntax region String start=+"+ skip=+\\+ end=+"+ +:syntax match paren "(" +:syntax match Function "\w\+\s*(" contains=paren +:syntax match Comment "#.*"