Lasca is Scala shifted towards Haskell.
Lasca is a LLVM-based statically or dynamically typed strict functional programming language. Simplified OCaml if you will.
It has a 'dynamic' compilation mode, meaning instant code generation without compile time type checking/inference, allowing instant compilation/execution cycle, and more freedom dynamic languages give.
It has a full type inference, parametric polymorphism, GC, algebraic data types, pattern matching, and type classes are coming soon.
Imagine
Inspired by:
Current implementation uses braces and semicolons, but I consider adding indentation-based syntax, or semicolon inference.
-- Algebraic data type a la Haskell
data JValue
= JNull
| JNum(n: Float)
| JString(s: String)
| JBool(v: Bool)
| JArray(v: [JValue])
| JObject(v: Map String JValue)
-- function argument type annotations are optional, compiler infers those
def jsonToString(js: JValue) = match js {
JObject(m) ->
if Map.isEmpty(m) then "{}" else {
println(toString(m));
res = Array.makeArray(m.size, "");
var idx = 0;
Map.foreachWithKey(m, { k, v ->
setIndex(res, idx.readVar, "\"${k}\": ${jsonToString(v)}");
idx := idx.readVar + 1;
});
s = String.join(", ", res);
"{ ${s} }"
}
JNull -> "null"
JNum(n) -> toString(n)
JBool(v) -> toString(v)
JString(v) -> "\"${v}\""
JArray(v) -> {
values = Array.map(v, jsonToString);
toString(values);
}
}
lasca -e --mode dynamic hello.lasca)String, Bool, Int, Byte, Int16, Int32, Float, Array, ByteArray, Var, FileHandleList, Option, Either, Map, ArrayBuffer+ - * / operatorsConsider Nix as package manager
GC, concurrent mark and sweep per actor/green thread GC Consider MultiCore Ocaml GC
for now, use Boehm conservative GC
def toString(s: String) = ...
"Hello".toString
def plus(l: Num, r: Num)
1.plus(2)
brew install boehmgc pcre2
brew install nau/lasca/lasca-compiler
Setup LASCAPATH environment variable. Add this to your .bash_profile
export LASCAPATH="$(brew --prefix lasca-compiler)/src"
Try it!
echo 'def main() = println("Hello Lasca!")' > hello.lasca
lasca -e hello.lasca
> Hello Lasca!
Add bash completion config for lasca compiler options:
lasca --bash-completion-script lasca > $(brew --prefix)/etc/bash_completion.d/lasca
You need LLVM 6.0 installed, and latest Haskell Stack.
brew install cmake boehmgc pcre2
brew install llvm-hs/llvm/llvm-6.0 # this compiles llvm from sources, make take some time
brew install haskell-stack
stack setup
Setup LASCAPATH environment variable. Add this to your .bash_profile
export LASCAPATH="${lasca-compiler-src-dir}/libs/base"
Add your ~/.local/bin directory to your PATH
export PATH=$PATH:~/.local/bin
Build and install lasca compiler
make install
Add bash completion config for lasca compiler options:
lasca --bash-completion-script lasca > $(brew --prefix)/etc/bash_completion.d/lasca
Run hello.lasca
lasca --exec examples/hello.lasca
Requirements: Haskell Stack > 1.6, Cabal > 2.0, LLVM 6, CMake
Don't install Haskell Stack from apt. It's likely to be older than 1.6 and won't be able to upgrade
Do this instead:
curl -sSL https://get.haskellstack.org/ | sh
sudo apt install llvm-6.0-dev libgc-dev zlib1g-dev cmake
sudo add-apt-repository universe
sudo apt install libpcre2-dev
export LASCAPATH="${lasca-compiler-src-dir}/libs/base"
export PATH=$PATH:~/.local/bin
stack setup
make install
lasca -e examples/hello.lasca
There are several implementation of n-body problem Currently it's quite slow due to boxing.
$ time lasca -e -O2 examples/nbody.lasca -- 50000000
-0.169075164
-0.169059907
real 7m13.261s
user 7m39.476s
sys 0m38.716s
find src -name "*.hs" | xargs cat | wc -l
4738
cat rts/runtime.c rts/builtin.c rts/lasca.h | wc -l
1324
C
89.0%
Haskell
9.0%
Lasca is Scala shifted towards Haskell.
Lasca is a LLVM-based statically or dynamically typed strict functional programming language. Simplified OCaml if you will.
It has a 'dynamic' compilation mode, meaning instant code generation without compile time type checking/inference, allowing instant compilation/execution cycle, and more freedom dynamic languages give.
It has a full type inference, parametric polymorphism, GC, algebraic data types, pattern matching, and type classes are coming soon.
Imagine
Inspired by:
Current implementation uses braces and semicolons, but I consider adding indentation-based syntax, or semicolon inference.
-- Algebraic data type a la Haskell
data JValue
= JNull
| JNum(n: Float)
| JString(s: String)
| JBool(v: Bool)
| JArray(v: [JValue])
| JObject(v: Map String JValue)
-- function argument type annotations are optional, compiler infers those
def jsonToString(js: JValue) = match js {
JObject(m) ->
if Map.isEmpty(m) then "{}" else {
println(toString(m));
res = Array.makeArray(m.size, "");
var idx = 0;
Map.foreachWithKey(m, { k, v ->
setIndex(res, idx.readVar, "\"${k}\": ${jsonToString(v)}");
idx := idx.readVar + 1;
});
s = String.join(", ", res);
"{ ${s} }"
}
JNull -> "null"
JNum(n) -> toString(n)
JBool(v) -> toString(v)
JString(v) -> "\"${v}\""
JArray(v) -> {
values = Array.map(v, jsonToString);
toString(values);
}
}
lasca -e --mode dynamic hello.lasca)String, Bool, Int, Byte, Int16, Int32, Float, Array, ByteArray, Var, FileHandleList, Option, Either, Map, ArrayBuffer+ - * / operatorsConsider Nix as package manager
GC, concurrent mark and sweep per actor/green thread GC Consider MultiCore Ocaml GC
for now, use Boehm conservative GC
def toString(s: String) = ...
"Hello".toString
def plus(l: Num, r: Num)
1.plus(2)
brew install boehmgc pcre2
brew install nau/lasca/lasca-compiler
Setup LASCAPATH environment variable. Add this to your .bash_profile
export LASCAPATH="$(brew --prefix lasca-compiler)/src"
Try it!
echo 'def main() = println("Hello Lasca!")' > hello.lasca
lasca -e hello.lasca
> Hello Lasca!
Add bash completion config for lasca compiler options:
lasca --bash-completion-script lasca > $(brew --prefix)/etc/bash_completion.d/lasca
You need LLVM 6.0 installed, and latest Haskell Stack.
brew install cmake boehmgc pcre2
brew install llvm-hs/llvm/llvm-6.0 # this compiles llvm from sources, make take some time
brew install haskell-stack
stack setup
Setup LASCAPATH environment variable. Add this to your .bash_profile
export LASCAPATH="${lasca-compiler-src-dir}/libs/base"
Add your ~/.local/bin directory to your PATH
export PATH=$PATH:~/.local/bin
Build and install lasca compiler
make install
Add bash completion config for lasca compiler options:
lasca --bash-completion-script lasca > $(brew --prefix)/etc/bash_completion.d/lasca
Run hello.lasca
lasca --exec examples/hello.lasca
Requirements: Haskell Stack > 1.6, Cabal > 2.0, LLVM 6, CMake
Don't install Haskell Stack from apt. It's likely to be older than 1.6 and won't be able to upgrade
Do this instead:
curl -sSL https://get.haskellstack.org/ | sh
sudo apt install llvm-6.0-dev libgc-dev zlib1g-dev cmake
sudo add-apt-repository universe
sudo apt install libpcre2-dev
export LASCAPATH="${lasca-compiler-src-dir}/libs/base"
export PATH=$PATH:~/.local/bin
stack setup
make install
lasca -e examples/hello.lasca
There are several implementation of n-body problem Currently it's quite slow due to boxing.
$ time lasca -e -O2 examples/nbody.lasca -- 50000000
-0.169075164
-0.169059907
real 7m13.261s
user 7m39.476s
sys 0m38.716s
find src -name "*.hs" | xargs cat | wc -l
4738
cat rts/runtime.c rts/builtin.c rts/lasca.h | wc -l
1324
C
89.0%
Haskell
9.0%