Compare commits
3
Commits
master
..
c8f3cd61f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8f3cd61f4 | ||
|
|
138d503bce | ||
|
|
e49ebba346 |
@@ -5,6 +5,7 @@
|
|||||||
!/exl
|
!/exl
|
||||||
!/include
|
!/include
|
||||||
!/src
|
!/src
|
||||||
|
!/tests
|
||||||
|
|
||||||
# Files
|
# Files
|
||||||
!/.clang-format
|
!/.clang-format
|
||||||
|
|||||||
+14
-95
@@ -35,108 +35,27 @@ add_executable(fz
|
|||||||
src/vm/main.c)
|
src/vm/main.c)
|
||||||
|
|
||||||
#
|
#
|
||||||
# ========== Compilation tests ==========
|
# ========== Tests ==========
|
||||||
#
|
#
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
add_test(
|
file(GLOB TEST_PROGS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "tests/programs/*.fzs")
|
||||||
NAME compile_hw
|
foreach (TEST_FILE IN LISTS TEST_PROGS)
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/hw.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/hw.fzs"
|
get_filename_component(TEST_NAME "${TEST_FILE}" NAME_WE)
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_print_empty
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/print_empty.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/print_empty.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_problematic_hw
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/problematic_hw.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/problematic_hw.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_base_math
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/base_math.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/base_math.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_variables
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/variables.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/variables.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_conditions
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/conditions.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/conditions.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_fn
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/fn.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/fn.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_comment
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/comment.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/comment.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_class
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/class.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/class.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_raii
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/raii.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/raii.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_borrow
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/borrow.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/borrow.fzs"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME compile_hard_1
|
|
||||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/hard-1.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/exl/hard-1.fzs"
|
|
||||||
)
|
|
||||||
|
|
||||||
set_tests_properties(compile_problematic_hw PROPERTIES WILL_FAIL TRUE)
|
|
||||||
|
|
||||||
#
|
|
||||||
# ========== Runtime tests ==========
|
|
||||||
#
|
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
NAME runtime_hw
|
NAME "progs_compile_${TEST_NAME}"
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/hw.fzb"
|
COMMAND fzc -o "p_${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE}"
|
||||||
)
|
)
|
||||||
add_test(
|
add_test(
|
||||||
NAME runtime_print_empty
|
NAME "progs_runtime_${TEST_NAME}"
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/print_empty.fzb"
|
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/p_${TEST_NAME}.fzb"
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_base_math
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/base_math.fzb"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_variables
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/variables.fzb"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_conditions
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/conditions.fzb"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_fn
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/fn.fzb"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_comment
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/comment.fzb"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_class
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/class.fzb"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_raii
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/raii.fzb"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_borrow
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/borrow.fzb"
|
|
||||||
)
|
|
||||||
add_test(
|
|
||||||
NAME runtime_hard_1
|
|
||||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/hard-1.fzb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (TEST_NAME MATCHES "neg_")
|
||||||
|
set_tests_properties("progs_compile_${TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
|
||||||
|
set_tests_properties("progs_runtime_${TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
.PHONY: configure build debug-c debug-vm test
|
.PHONY: build debug-c debug-vm test
|
||||||
|
|
||||||
configure:
|
build:
|
||||||
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
|
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
cmake --build build
|
||||||
|
|
||||||
build: configure
|
build-release:
|
||||||
|
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
|
||||||
cmake --build build
|
cmake --build build
|
||||||
|
|
||||||
debug-c: build
|
debug-c: build
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ Working examples of code can be found in `exl/` directory.
|
|||||||
## Building
|
## Building
|
||||||
|
|
||||||
1. Clone the repository: `git clone https://git.samsonium.dev/samsonium/fz-lang.git`
|
1. Clone the repository: `git clone https://git.samsonium.dev/samsonium/fz-lang.git`
|
||||||
2. Build: `make build`
|
2. Build: `make build-release`
|
||||||
|
|
||||||
After this, a "build" directory will appear in the project root. It will contain two executable files:
|
After this, a "build" directory will appear in the project root. It will contain two executable files:
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@
|
|||||||
## Инструкции по сборке
|
## Инструкции по сборке
|
||||||
|
|
||||||
1. Склонировать проект: `git clone https://git.samsonium.dev/samsonium/fz-lang.git`
|
1. Склонировать проект: `git clone https://git.samsonium.dev/samsonium/fz-lang.git`
|
||||||
2. Собрать проект: `make build`
|
2. Собрать проект: `make build-release`
|
||||||
|
|
||||||
После этого в корне появится директория **"build"**. В ней будут лежать два скомпилированных бинарных файла:
|
После этого в корне появится директория **"build"**. В ней будут лежать два скомпилированных бинарных файла:
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// There are two ways to work with variables
|
||||||
|
// 1. Declare variable:
|
||||||
|
str someString = "world, hello!";
|
||||||
|
|
||||||
|
// 2. Change variable value:
|
||||||
|
someString = "hello, world!";
|
||||||
|
|
||||||
|
// Variables helps you store values to use it later
|
||||||
|
int a = 2;
|
||||||
|
int b = a + a * a;
|
||||||
|
int c = a * b;
|
||||||
|
|
||||||
|
printline("Now we got 12:");
|
||||||
|
printline(c);
|
||||||
|
|
||||||
|
// Also, there is many different types to help your program
|
||||||
|
// work with many things:
|
||||||
|
int signedInteger;
|
||||||
|
uint unsignedInteger
|
||||||
|
str string;
|
||||||
|
bool boolean;
|
||||||
|
|
||||||
|
i8 integer1; // 8-byte int
|
||||||
|
i16 integer2; // 16-byte int
|
||||||
|
i32 integer3; // 32-byte int
|
||||||
|
i64 integer4; // 64-byte int
|
||||||
|
|
||||||
|
u8 integer5; // unsigned 8-byte integer
|
||||||
|
u16 integer6; // unsigned 16-byte integer
|
||||||
|
u32 integer7; // unsigned 32-byte integer
|
||||||
|
u64 integer8; // unsigned 64-byte integer
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// When you need to check some value
|
||||||
|
// a conditional statements might help you
|
||||||
|
|
||||||
|
int valueToCheck = 2 + 2;
|
||||||
|
if (valueToCheck == 4)
|
||||||
|
{
|
||||||
|
printline("Yay! 2 + 2 = 4");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conditional statement uses condition in pairs
|
||||||
|
// after `if` keyword and executes command(s) after
|
||||||
|
// if condition turns out to be true
|
||||||
|
|
||||||
|
// Otherwise, to execute block when condition turns
|
||||||
|
// out to be false, you can use `else` keyword:
|
||||||
|
|
||||||
|
int age = 30;
|
||||||
|
|
||||||
|
if (age <= 20)
|
||||||
|
printline("You're too young");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
age = 20;
|
||||||
|
printline("You looks too young!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: If you need to execute only one statement
|
||||||
|
// inside `if` or `else` block, then the curly
|
||||||
|
// braces can be omitted.
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// If you have some code section which is
|
||||||
|
// duplicated in program several times
|
||||||
|
// then it means your program needs some
|
||||||
|
// functions!
|
||||||
|
|
||||||
|
fn doSomeWork()
|
||||||
|
{
|
||||||
|
printline("Some work");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the function makes some kind of
|
||||||
|
// calculations then you should specify
|
||||||
|
// the result type
|
||||||
|
|
||||||
|
fn sum(int a, int b) int
|
||||||
|
{
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The `return` keyword can be used to
|
||||||
|
// actually return the value from the
|
||||||
|
// function. Also, you can specify list
|
||||||
|
// of arguments that you will use inside
|
||||||
|
// the function
|
||||||
|
|
||||||
|
int first = 5;
|
||||||
|
int second = 6;
|
||||||
|
int result = sum(first, second);
|
||||||
|
printline(result);
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
printline(1 + );
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
int value = 42
|
||||||
|
printline(value);
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
if (true)
|
||||||
|
{
|
||||||
|
printline("missing closing brace");
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
printline("unterminated string);
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// Arithmetic precedence and operators.
|
||||||
|
printline(2 + 2 * 2);
|
||||||
|
printline(-1 + 1);
|
||||||
|
printline(2 ^ 2);
|
||||||
|
printline(4 % 2);
|
||||||
|
printline(10 / 2);
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
class Point
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
|
||||||
|
fn move(int dx, int dy)
|
||||||
|
{
|
||||||
|
this.x = this.x + dx;
|
||||||
|
this.y = this.y + dy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Point point = new Point;
|
||||||
|
point.x = 1;
|
||||||
|
point.y = 2;
|
||||||
|
point.move(9, 8);
|
||||||
|
|
||||||
|
if (point.x == 10 && point.y == 10)
|
||||||
|
printline("class method passed");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printline("class method failed");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// Line comments are ignored by the parser.
|
||||||
|
printline('single-quoted string');;;;;
|
||||||
|
printline("");
|
||||||
|
printline("double-quoted string");
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
bool flag = true;
|
||||||
|
|
||||||
|
if (!flag)
|
||||||
|
{
|
||||||
|
printline("unexpected false");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else if (2 + 2 >= 4)
|
||||||
|
{
|
||||||
|
printline("condition passed");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printline("unexpected branch");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
printline("standalone block");
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
fn fib(int n) int
|
||||||
|
{
|
||||||
|
if (n <= 1)
|
||||||
|
return n;
|
||||||
|
|
||||||
|
return fib(n - 1) + fib(n - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sum(uint a, uint b) uint
|
||||||
|
{
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fib(7) == 13 && sum(2, 2) == 4)
|
||||||
|
printline("functions passed");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printline("functions failed");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
class Item
|
||||||
|
{
|
||||||
|
int value;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn maybe_item(bool create) Item
|
||||||
|
{
|
||||||
|
if (create)
|
||||||
|
return new Item;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Item empty = maybe_item(false);
|
||||||
|
Item present = maybe_item(true);
|
||||||
|
if (empty == null && present != null)
|
||||||
|
printline("null handling passed");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printline("null handling failed");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
uint work_it = 21 * 2 ^ 2;
|
||||||
|
int make_it = 10;
|
||||||
|
u64 do_it;
|
||||||
|
do_it = 15;
|
||||||
|
char make_us;
|
||||||
|
str floyd = "hello, Pink Floyd!";
|
||||||
|
bool flag = true;
|
||||||
|
|
||||||
|
printline(work_it);
|
||||||
|
printline(make_it + do_it);
|
||||||
|
printline(floyd);
|
||||||
|
printline(flag);
|
||||||
|
|
||||||
Reference in New Issue
Block a user