-
Notifications
You must be signed in to change notification settings - Fork 2
Home
a statically-typed functional programming language with powerful objective syntax Try now: scopion.coord-e.com/try
(argc, argv){
io = @import#c:stdio.h;
v1 = v2 = [
real: 10,
add: (val, self){
newv = self;
newv.real = self.real + val;
|> newv;
},
+: (rhs, self){
|> self.:add(rhs.real);
},
];
v1.=add(1);
io.printf("v1.real => %d\n", v1.real); // 11
io.printf("(v1+v2).real => %d\n", (v1+v2).real); // 21
}
v1.real => 11
(v1+v2).real => 21
This project is heavily under development.
- no such thing like 'global'
- almost all functions has a referentially transparency
- support powerful objective syntax
- no reserved words
- statically typed
- types are suggested in almost scene
- Embedded garbage collection
- Optimization and native code generation by LLVM
- llvm, clang (v5.0.0~)
- Boost.Filesystem (v1.62~)
- libgc
- ctags
- macOS
- GNU/Linux
Only x86_64 is currently supported.
If you are in Ubuntu 17.04~, Debian stretch~, or macOS Sierra~, just paste this at a terminal prompt:
curl -fsSL https://scopion.coord-e.com/get | bash
docker pull coorde/scopion
docker run -it coorde/scopion /bin/bash
Now you can compile your scopion source
scopc prog.scc -o prog
usage: scopc [options] ... filename ...
options:
-t, --type Specify the type of output (ir, ast, asm, obj) (string [=obj])
-o, --output Specify the output path (string [=./a.out])
-a, --arch Specify the target triple (string [=native])
-O, --optimize Enable optimization (1-3) (int [=1])
-h, --help Print this help
-V, --version Print version
if there is no suitable prebuilt binary for your environment, you can build scopion from source.
- (Installation prerequirements)
- Boost (v1.62~)
- cmake (v3.7~)
git clone https://github.com/coord-e/scopion
cd scopion
mkdir build && cd $_
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DFORMAT_BEFORE_BUILD=OFF
make -j"$(nproc)" # build
sudo make install # install
- Add package management system
- Varadic array and structure
- Associative array
- Logging
- Conpile-time execution of functions
- Cast operator
- Coroutine
- Add more features to stdlib
- Tuple (array with different types)
This document is written in progress. See Parser.cpp for full syntax definition.
identifier ::= alpha (alnum | '_' )*
Identifier is used to identify variables, structure's keys, etc...
primary ::= int | bool | string | raw_string | variable |
pre_variable | structure | array |
function | scope | ('(' expression ')');
An integer literal expresses signed 32-bit integer literal.
A bool literal expresses true or false.
string ::= ('"' ("\"" | char - '"')* '"');
raw_string ::= (''' ("\'" | char - '\'')* ''');
A string (with "") has escape sequences. To use " in raw string, use ".
Sequence | Character | Code |
---|---|---|
\n | NEWLINE | 0x0a |
\r | CARRIAGE RETURN | 0x0d |
\t | HORIZONTAL TAB | 0x09 |
\v | VERTICAL TAB | 0x0b |
\b | BACKSPACE | 0x08 |
\f | NEWPAGE | 0x0c |
\a | AUDIBLE BELL | 0x07 |
\ | \ | 0x5c |
A raw string (with '') doesn't have escape sequences. To use ' in raw string, use '. Both string literal style can include a newline. For example, both of them below is legal code.
str = "Hello, World.
Hogehoge";
rstr = 'Raw string.
Piyopiyo';
function ::= '(' argment-list ')' '{' (expression ';')* '}'
argment-list ::= (identifier ','?)*
A function is a lazy-evaluated group of expressions that together perform a task using arguments and return a result.
struct_key ::= identifier | '+' | '-' | '*' | '/' | '%' | '<' | '>' | '&' | '|' | '^' | '~' | '!' | (('!' | '=' | '<' | '>') > '=') |
x3::repeat(2)[x3::char_("+\\-<>&|")] |
"[]" |
"()"
structure ::= '[' (struct_key ':' expression ','?)* ']'
A structure is a composition of data. A structure has a field that matches keys and values. You can access the value to specify the key with dot operator.
io = @import#c:stdio.h
struct = [
value: 10,
func: (arg){ <| arg + 1; }
];
io.printf("%d\n", struct.value); // 10
scope ::= '{' (expression ';')* '}'
A scope literal is a lazy-evaluated group of expressions that doesn't take arguments. A scope has a scope which inherits that of its declaration.
var = 10;
scope = {
var = var + 2;
};
var = 5;
scope(); // now var is 7
It often used in conditional operator.
variable ::= identifier
pre_variable ::= '@' > identifier;
Variable has a same syntax with identifier.
To declare a variable, you just have to assign to a new variable with initial value. The type will be suggested by the value.
You can use the variable's value to write the variable's name.
Also you can assign to the variable with the same way you declared that. If the right operand has a different type with the variable, it is illegal.
pre_variable, which is a predefined variable start with '@', is used to make a special action on a compiler.
-
@import
Use@import
to import other file. You can specify the path to the file:-
#m
Specify the path to other scorpion file Returns the top level value of the file -
#ir
Specify the path to llvm ir file Returns a structure contains all function declarations in the file -
#c
Specify the c header Returns a structure contains all function declarations in the file
-
-
@self
This value refers the function that you're in.(){ @self(); }() // infinite loop
This program is licensed by GPL v3. See COPYING
.