Skip to content

Commit

Permalink
Tests and SubCommand optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
SujalChoudhari committed Sep 20, 2023
1 parent c42b4d4 commit b77aa20
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 28 deletions.
7 changes: 6 additions & 1 deletion Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Coda {
return runnable(argc, argv);
}
catch (const std::exception& e) {
std::cerr << Utils::Colors::ACCENT << "[CODA ]: \033[0;31mA fatal error occurred in the interpreter.\n" << e.what() << Utils::Colors::RESET << std::endl;
std::cerr << Utils::Colors::ACCENT << "[CODA ]: \033[0;31mA fatal error occurred in the interpreter.\n" << e.what() << Utils::Colors::RESET << std::endl;
result = EXIT_FAILURE;
}
catch (...) {
Expand Down Expand Up @@ -54,7 +54,12 @@ namespace Coda {
source = importer.import(mMainFileName);

}
else if (importer.fileExists(subCommand)) {
mMainFileName = subCommand;
source = importer.import(mMainFileName);
}
else {

mMainFileName = "./.coda";
source = importer.import(mMainFileName);

Expand Down
34 changes: 17 additions & 17 deletions Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ namespace Coda {

public:
const std::string title = "\033[1;96m\n\
dddddddd \n\
CCCCCCCCCCCCC d::::::d \n\
CCC::::::::::::C d::::::d \n\
CC:::::::::::::::C d::::::d \033[0mv0.2\033[1;96m \n\
C:::::CCCCCCCC::::C d:::::d \n\
C:::::C CCCCCC ooooooooooo ddddddddd:::::d aaaaaaaaaaaaa \n\
C:::::C oo:::::::::::oo dd::::::::::::::d a::::::::::::a \n\
C:::::C o:::::::::::::::o d::::::::::::::::d aaaaaaaaa:::::a \n\
C:::::C o:::::ooooo:::::od:::::::ddddd:::::d a::::a \n\
C:::::C o::::o o::::od::::::d d:::::d aaaaaaa:::::a \n\
C:::::C o::::o o::::od:::::d d:::::d aa::::::::::::a \n\
C:::::C o::::o o::::od:::::d d:::::d a::::aaaa::::::a \n\
C:::::C CCCCCCo::::o o::::od:::::d d:::::d a::::a a:::::a \n\
C:::::CCCCCCCC::::Co:::::ooooo:::::od::::::ddddd::::::dda::::a a:::::a \n\
CC:::::::::::::::Co:::::::::::::::o d:::::::::::::::::da:::::aaaa::::::a \n\
CCC::::::::::::C oo:::::::::::oo d:::::::::ddd::::d a::::::::::aa:::a\n\
CCCCCCCCCCCCC ooooooooooo ddddddddd ddddd aaaaaaaaaa aaaa\033[0m";
dddddddd \n\
CCCCCCCCCCCCC d::::::d \n\
CCC::::::::::::C d::::::d \n\
CC:::::::::::::::C d::::::d \033[0mv0.2\033[1;96m \n\
C:::::CCCCCCCC::::C d:::::d \n\
C:::::C CCCCCC ooooooooooo ddddddddd:::::d aaaaaaaaaaaaa \n\
C:::::C oo:::::::::::oo dd::::::::::::::d a::::::::::::a \n\
C:::::C o:::::::::::::::o d::::::::::::::::d aaaaaaaaa:::::a \n\
C:::::C o:::::ooooo:::::o d:::::::ddddd:::::d a::::a \n\
C:::::C o::::o o::::o d::::::d d:::::d aaaaaaa:::::a \n\
C:::::C o::::o o::::o d:::::d d:::::d aa::::::::::::a \n\
C:::::C o::::o o::::o d:::::d d:::::d a::::aaaa::::::a \n\
C:::::C CCCCCC o::::o o::::o d:::::d d:::::d a::::a a:::::a \n\
C:::::CCCCCCCC::::C o:::::ooooo:::::o d::::::ddddd::::::dd a::::a a:::::a \n\
CC:::::::::::::::C o:::::::::::::::o d:::::::::::::::::d a:::::aaaa::::::a \n\
CCC::::::::::::C oo:::::::::::oo d:::::::::ddd::::d a::::::::::aa:::a\n\
CCCCCCCCCCCCC ooooooooooo ddddddddd ddddd aaaaaaaaaa aaaa\033[0m";

const std::string helpMessage = "\033[0;33m\n\
========================================\n\
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0] - 18-09-2023
## [0.3.0] - 20-09-2023

### Added
- `OS` package.

### Changed
- `import` statements will work in `repl` environment.
- `print` will print an entire list (when given)
- `run` subcommand is optional.

## [0.2.0] - 16-9-2023

Expand Down
7 changes: 4 additions & 3 deletions Frontend/Importer/Importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Coda {
class Importer {
public:
/*
Imports the file from the given path,
Imports the file from the given path,
recursively handles the import declaration
and returns the final source code.
*/
Expand All @@ -24,7 +24,7 @@ namespace Coda {
find the poistion of next import statement
*/
size_t findNextImport(const std::string& sourceCode, size_t startIndex);

/*
find the position of end of import statement
*/
Expand All @@ -34,7 +34,7 @@ namespace Coda {
get the import string
*/
std::string extractImportString(const std::string& sourceCode, size_t importIndex, size_t importEndIndex);

/*
replaces the import statement with the contents of the given file
*/
Expand All @@ -52,6 +52,7 @@ namespace Coda {
/*
check if file exists or nots
*/
public:
bool fileExists(const std::string& filePath);
};
} // namespace Frontend
Expand Down
13 changes: 10 additions & 3 deletions Test/debug.coda
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import os
let float x = 200;

def lll(){os.run("echo 1i");}
def takeInput() {
const inp = input("Enter a number");
return 0;
}

lll();
for (let i = 0;i < 100 ;i++) {
println(parseInt(takeInput()));
}

quit(0);
86 changes: 86 additions & 0 deletions Test/demo.coda
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import Maths
// Comment
// Comments can be closed by a semi colon;
let int X = 30; // this would run;
// this would also run; let float y = 40.0

// this is how you define functions
def function_name (param1,param2){
// code goes here
return 0;
}

// we have SCOPES!!

scope scopename {
let string x = "Hello World";
const int PI = 3.14; // consts cannot be changed

def fuc(param){
return 3;
}
}



// to use SCOPES
// we use the dot operator
println(scopename.x); // and yes semicolon is optional



// here is the list of keywords we use in this language, it is keyword -> purpose
// let -> LET
// const -> CONST
// def -> DEF
// if -> IF
// elif -> ELIF
// else -> ELSE
// for -> FOR
// while -> WHILE
// break -> JUMP
// return -> JUMP
// scope -> SCOPE
// continue -> JUMP
// typeof -> UNARY_OPERATOR
// sizeof -> UNARY_OPERATOR
// do -> DO
// in -> IN
// native -> NATIVE
// int -> TYPE
// bool -> TYPE
// byte -> TYPE
// float -> TYPE
// list -> TYPE
// object -> TYPE
// double -> TYPE
// string -> TYPE
// long -> TYPE

// We have objects!!

let obj = {
x: 30,
y: 50,
func: def(param1,para2){
// yes there are funcs in objects as well...
}
}

while(let x < 0){
x++;
}



// lists in our language
const list abc = [1,2,4,5];

//Types
// (int|bool|byte|float|list|object|double|string|long)

// Keywords
//(let|const|def|if|elif|else|for|while|break|return|scope|continue|typeof|sizeof|do|in|native)

// BuiltIn Functions
// (print|println|sleep|input|parseInt|parseFloat|parseDouble|parseByte|parseBool|quit|exit)
1 change: 0 additions & 1 deletion Test/demo.txt

This file was deleted.

2 changes: 0 additions & 2 deletions dll/OS/OS.coda
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ scope fs {
}
}



scope os {
def run(command) {
return native OS coda_run_command(command);
Expand Down

0 comments on commit b77aa20

Please sign in to comment.