Skip to content

Commit

Permalink
added a couple of path options to simplify usage
Browse files Browse the repository at this point in the history
  • Loading branch information
maniospas committed Oct 6, 2024
1 parent 757ac1a commit dc87785
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 54 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
__pachache_/*
temp/
build/
vcpkg/
vcpkg/
blombly.exe
*.dll
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,41 @@

[Learn more...](https://maniospas.github.io/Blombly/)

# Downloads
- [Windows executable](blombly.exe)
- Build from source: Download this repository and install gcc in your system. Run the following command from the directory of the `blombly.cpp` file:
# Very quick start

```gcc
g++ -std=c++20 -pthread -I./include src/*.cpp src/data/*.cpp src/interpreter/*.cpp blombly.cpp -o blombly -O2
```
Find the latest release [here](https://github.com/maniospas/Blombly/releases/tag/latest).
<br>Current build targets: *Windows x64*

Unzip the folder in a directory and create a file `main.bb` with the following contents:

```cpp
#include "libs/fmt"
enable fmt; // pretty read and print

name = read("What's your name?");
print("Hello ", name, "!");
```
Run `blombly.exe main.bb`, where the executable and main files can be any path, and check that everything is working properly.
Do not move the executable without all the `libs/` and dynamically linked libraries that are packaged with it.
# Build from source
Clone this repository and install gcc in your system. Then, follow the steps below, which include installing the `vcpkg` dependency manager:
```bash
# install vcpkg
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat # windows bootstraping (./bootstrap-vcpkg.sh for linux)
./vcpkg install zlib civetweb
cd ..
# build instructions
mkdir build
cmake -B ./build
cmake --build ./build --config Release # rerun this after making changes
```

# Credits

Expand Down
17 changes: 17 additions & 0 deletions blombly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@
// cmake -B ./build
// cmake --build ./build --config Release

std::string blombly_executable_path;



std::string get_executable_directory(const std::string& argv0) {
#ifdef _WIN32
size_t pos = argv0.find_last_of("\\");
#else
size_t pos = argv0.find_last_of("/");
#endif
if (pos != std::string::npos)
return argv0.substr(0, pos);
return ".";
}



int main(int argc, char* argv[]) {
blombly_executable_path = get_executable_directory(argv[0]);
Terminal::enableVirtualTerminalProcessing();
initializeOperationMapping();

Expand Down
Binary file modified blombly.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion libs/fmt.bb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ final fmt::fmt = {
argiter = std::iter(args);
while(arg as std::next(argiter)) {
formatted = formatted + std::str(arg);
formatted = formatted + " ";
// formatted = formatted + " ";
}
return formatted;
}
Expand Down
79 changes: 36 additions & 43 deletions main.bbvm
Original file line number Diff line number Diff line change
@@ -1,48 +1,41 @@
BEGIN _bb2
BUILTIN value I0
BUILTIN _bb4 I8000
server routes _bb4
BEGIN _bb6
BEGIN _bb7
BUILTIN _bb8 "The number of hi must be an integer."
return _bbresult0 _bb8
BEGIN _bb0
BUILTIN formatted ""
iter argiter args
next arg argiter
exists _bb4 arg
BEGIN _bb5
str _bb7 arg
add formatted formatted _bb7
next arg argiter
exists _bb4 arg
END
BUILTIN _bb10 Bfalse
int number number
exists _bb12 number
eq _bb9 _bb12 _bb10
if # _bb9 _bb7
BEGIN _bb13
BUILTIN _bb14 "Need a positive number of hi. Why must you take them away? :-("
return _bbresult1 _bb14
while # _bb4 _bb5
return _bbresult0 formatted
END
BUILTIN _bb16 I0
le _bb15 number _bb16
if # _bb15 _bb13
BUILTIN _bb18 I1
get _bb19 this value
add _bb17 _bb19 _bb18
set # this value _bb17
BUILTIN _bb21 " hi"
str _bb23 number
BUILTIN _bb25 " hello your "
get _bb27 this value
add _bb26 _bb27 number
str _bb28 _bb26
add _bb24 _bb28 _bb25
add _bb22 _bb24 _bb23
add _bb20 _bb22 _bb21
return _bbresult2 _bb20
IS fmt::fmt _bb0
final # fmt::fmt
time tic
BEGIN _bb10
BUILTIN _bb11 "What's your name?"
list args _bb11
END
BUILTIN _bb29 "/hi/<number>"
put # routes _bb29 _bb6
return _bbresult3 this
call _bb9 _bb10 fmt::fmt
read name _bb9
BEGIN _bb14
BUILTIN _bb15 "Hello "
BUILTIN _bb16 "!"
list args _bb15 name _bb16
END
new _bb0 _bb2
BUILTIN _bb30 "Give me some greetings at localhost:8000/hi/<number>"
print # _bb30
BUILTIN _bb31 Btrue
BEGIN _bb32
BUILTIN _bb31 Btrue
call _bb13 _bb14 fmt::fmt
print # _bb13
time _bb19
sub duration _bb19 tic
BEGIN _bb21
BUILTIN _bb22 "It was fun knowing you for "
BUILTIN _bb24 ".1f"
at _bb23 duration _bb24
BUILTIN _bb25 " seconds."
list args _bb22 _bb23 _bb25
END
while # _bb31 _bb32
call _bb20 _bb21 fmt::fmt
print # _bb20
14 changes: 11 additions & 3 deletions src/utils/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const std::string PARSER_NEW = "new";
const std::string PARSER_PRBB_INT = "print";
const std::string PARSER_COPY = "copy";
const std::string ANON = "_bb";
extern std::string blombly_executable_path;

class Parser {
private:
Expand Down Expand Up @@ -1149,11 +1150,18 @@ void macros(std::vector<Token>& tokens, const std::string& first_source) {

std::ifstream inputFile(source);
if (!inputFile.is_open()) {
std::filesystem::path execFilePath = std::filesystem::path(std::filesystem::current_path().string()) / source;
inputFile.open(execFilePath.string());
}
if (!inputFile.is_open()) {
std::filesystem::path execFilePath = std::filesystem::path(blombly_executable_path) / source;
inputFile.open(execFilePath.string());
}

if (!inputFile.is_open())
bberror("Unable to open file: " + source +
"\n \033[33m!!!\033[0m This issue makes it impossible to"
"\n complete the include statement.\n"
"\n \033[33m!!!\033[0m This issue makes it impossible to complete the include statement.\n"
+ Parser::show_position(tokens, i));
}

std::string code = "";
std::string line;
Expand Down

0 comments on commit dc87785

Please sign in to comment.