cpl-rewrite #1

Merged
edraft merged 11 commits from cpl-rewrite into master 2021-10-27 09:22:26 +02:00
27 changed files with 222 additions and 20 deletions
Showing only changes of commit a97de91fc4 - Show all commits

View File

@ -0,0 +1,13 @@
public lib Preview.Classes {
public class Test {
private var _name: string;
public constructor(name: string) {
this._name = name;
}
public getName(): string {
return this._name;
}
}
}

View File

@ -0,0 +1,5 @@
public lib Preview.Functions {
public func isTrue(value: bool): bool {
return value;
}
}

View File

@ -0,0 +1,8 @@
public lib Preview.Variables {
public var str: string = "Hello World";
public var test: bool = false;
public var test2: Test = empty;
public var test3: Test = Test(34);
}

View File

@ -0,0 +1,19 @@
use Preview.Variables;
use Preview.Functions;
use Preview.Classes;
public lib Main {
public class Program {
private var test: Test;
public constructor() {
this.test = Test(str);
}
public func Main(): void {
output(str, test, test2, test3);
output(isTrue(test));
output(this.test.getName());
}
}
}

View File

@ -4,7 +4,9 @@
"Projects": { "Projects": {
"cc-lang": "src/cc_lang/cc-lang.json", "cc-lang": "src/cc_lang/cc-lang.json",
"parser": "src/parser/parser.json", "parser": "src/parser/parser.json",
"lexer": "src/lexer/lexer.json" "lexer": "src/lexer/lexer.json",
"runtime": "src/runtime/runtime.json",
"cc-lang-interpreter": "src/cc_lang_interpreter/cc-lang-interpreter.json"
} }
} }
} }

View File

@ -1,5 +1,5 @@
from Interpreter.Interpreter import Interpreter from Interpreter.Interpreter import Interpreter
from CCLang_sly.Interpreter import Interpreter as SlyCCLangInterpreter # from CCLang_sly.Interpreter import Interpreter as SlyCCLangInterpreter
from Interpreter.Utils import Utils from Interpreter.Utils import Utils
from Interpreter.Repo import Repo from Interpreter.Repo import Repo
@ -10,4 +10,4 @@ class ServiceInitializer:
self.repo = Repo() self.repo = Repo()
self.utils = Utils(self.repo) self.utils = Utils(self.repo)
self.interpreter = Interpreter(self.repo, self.utils) self.interpreter = Interpreter(self.repo, self.utils)
self.sly_cclang_interpreter = SlyCCLangInterpreter(self.repo, self.utils) # self.sly_cclang_interpreter = SlyCCLangInterpreter(self.repo, self.utils)

View File

@ -12,7 +12,7 @@ class Main:
self.__utils = self.__services.utils self.__utils = self.__services.utils
self.__repo = self.__services.repo self.__repo = self.__services.repo
self.__interpreter = self.__services.interpreter self.__interpreter = self.__services.interpreter
self.__sly_cclang_interpreter = self.__services.sly_cclang_interpreter # self.__sly_cclang_interpreter = self.__services.sly_cclang_interpreter
def console(self) -> None: def console(self) -> None:
""" """
@ -22,8 +22,8 @@ class Main:
i = 0 i = 0
while self.__repo.error is None: while self.__repo.error is None:
self.__repo.line_number = i + 1 self.__repo.line_number = i + 1
#self.__interpreter.interpret(input('> ')) self.__interpreter.interpret(input('> '))
self.__sly_cclang_interpreter.interpret(input('> ')) # self.__sly_cclang_interpreter.interpret(input('> '))
i += 1 i += 1
def files(self, file: str) -> None: def files(self, file: str) -> None:
@ -43,8 +43,8 @@ class Main:
f = open(file, 'r', encoding='utf-8').readlines() f = open(file, 'r', encoding='utf-8').readlines()
for i in range(0, len(f)): for i in range(0, len(f)):
self.__repo.line_number = i + 1 self.__repo.line_number = i + 1
# self.__interpreter.interpret(f[i]) self.__interpreter.interpret(f[i])
self.__sly_cclang_interpreter.interpret(f[i]) # self.__sly_cclang_interpreter.interpret(f[i])
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -25,11 +25,11 @@
"Classifiers": [] "Classifiers": []
}, },
"BuildSettings": { "BuildSettings": {
"ProjectType": "console", "ProjectType": "library",
"SourcePath": "", "SourcePath": "",
"OutputPath": "../../dist", "OutputPath": "../../dist",
"Main": "cc_lang.main", "Main": "",
"EntryPoint": "cc-lang", "EntryPoint": "",
"IncludePackageData": false, "IncludePackageData": false,
"Included": [], "Included": [],
"Excluded": [ "Excluded": [

View File

@ -0,0 +1 @@
# imports:

View File

@ -3,14 +3,28 @@ from cpl.configuration import ConfigurationABC
from cpl.console import Console from cpl.console import Console
from cpl.dependency_injection import ServiceProviderABC from cpl.dependency_injection import ServiceProviderABC
from lexer.abc.lexer_abc import LexerABC
class Application(ApplicationABC): class Application(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
ApplicationABC.__init__(self, config, services) ApplicationABC.__init__(self, config, services)
self._lexer: LexerABC = services.get_service(LexerABC)
self._path = config.get_configuration('p')
def _console(self): pass
def _files(self): pass
def configure(self): def configure(self):
pass pass
def main(self): def main(self):
Console.write_line('Hello World') Console.write_line(self._configuration.additional_arguments, self._path)
if self._path is None:
self._console()
return
self._files()

View File

@ -0,0 +1,43 @@
{
"ProjectSettings": {
"Name": "cc-lang-interpreter",
"Version": {
"Major": "0",
"Minor": "0",
"Micro": "0"
},
"Author": "",
"AuthorEmail": "",
"Description": "",
"LongDescription": "",
"URL": "",
"CopyrightDate": "",
"CopyrightName": "",
"LicenseName": "",
"LicenseDescription": "",
"Dependencies": [
"sh_cpl==2021.4.0.post2"
],
"PythonVersion": ">=3.9.2",
"PythonPath": {
"linux": ""
},
"Classifiers": []
},
"BuildSettings": {
"ProjectType": "console",
"SourcePath": "",
"OutputPath": "../../dist",
"Main": "cc_lang_interpreter.main",
"EntryPoint": "cc-lang-interpreter",
"IncludePackageData": false,
"Included": [],
"Excluded": [
"*/__pycache__",
"*/logs",
"*/tests"
],
"PackageData": {},
"ProjectReferences": []
}
}

View File

@ -1,7 +1,7 @@
from cpl.application import ApplicationBuilder from cpl.application import ApplicationBuilder
from cc_lang.application import Application from cc_lang_interpreter.application import Application
from cc_lang.startup import Startup from cc_lang_interpreter.startup import Startup
def main(): def main():

View File

@ -1,7 +1,10 @@
from cpl.application import StartupABC from cpl.application import StartupABC
from cpl.configuration import ConfigurationABC from cpl.configuration import ConfigurationABC, ConsoleArgument
from cpl.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl.dependency_injection import ServiceProviderABC, ServiceCollectionABC
from lexer.abc.lexer_abc import LexerABC
from lexer.service.lexer_service import LexerService
class Startup(StartupABC): class Startup(StartupABC):
@ -13,7 +16,12 @@ class Startup(StartupABC):
self._services = services self._services = services
def configure_configuration(self) -> ConfigurationABC: def configure_configuration(self) -> ConfigurationABC:
self._configuration.add_console_argument(ConsoleArgument('-', 'p', [], ' '))
self._configuration.add_console_arguments()
return self._configuration return self._configuration
def configure_services(self) -> ServiceProviderABC: def configure_services(self) -> ServiceProviderABC:
self._services.add_singleton(LexerABC, LexerService)
return self._services.build_service_provider() return self._services.build_service_provider()

View File

@ -1 +1 @@
# imports: # imports

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,7 @@
from abc import ABC, abstractmethod
class LexerABC(ABC):
@abstractmethod
def __init__(self): pass

View File

@ -28,8 +28,8 @@
"ProjectType": "library", "ProjectType": "library",
"SourcePath": "", "SourcePath": "",
"OutputPath": "../../dist", "OutputPath": "../../dist",
"Main": "lexer.main", "Main": "",
"EntryPoint": "lexer", "EntryPoint": "",
"IncludePackageData": false, "IncludePackageData": false,
"Included": [], "Included": [],
"Excluded": [ "Excluded": [

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,7 @@
from lexer.abc.lexer_abc import LexerABC
class LexerService(LexerABC):
def __init__(self):
pass

View File

@ -28,8 +28,8 @@
"ProjectType": "library", "ProjectType": "library",
"SourcePath": "", "SourcePath": "",
"OutputPath": "../../dist", "OutputPath": "../../dist",
"Main": "parser.main", "Main": "",
"EntryPoint": "parser", "EntryPoint": "",
"IncludePackageData": false, "IncludePackageData": false,
"Included": [], "Included": [],
"Excluded": [ "Excluded": [

1
src/runtime/__init__.py Normal file
View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,7 @@
from abc import ABC, abstractmethod
class ClassStackABC(ABC):
@abstractmethod
def __init__(self): pass

View File

@ -0,0 +1,7 @@
from abc import ABC, abstractmethod
class FunctionStackABC(ABC):
@abstractmethod
def __init__(self): pass

View File

@ -0,0 +1,7 @@
from abc import ABC, abstractmethod
class LibraryStackABC(ABC):
@abstractmethod
def __init__(self): pass

View File

@ -0,0 +1,7 @@
from abc import ABC, abstractmethod
class VariableStackABC(ABC):
@abstractmethod
def __init__(self): pass

43
src/runtime/runtime.json Normal file
View File

@ -0,0 +1,43 @@
{
"ProjectSettings": {
"Name": "runtime",
"Version": {
"Major": "0",
"Minor": "0",
"Micro": "0"
},
"Author": "",
"AuthorEmail": "",
"Description": "",
"LongDescription": "",
"URL": "",
"CopyrightDate": "",
"CopyrightName": "",
"LicenseName": "",
"LicenseDescription": "",
"Dependencies": [
"sh_cpl==2021.4.0.post2"
],
"PythonVersion": ">=3.9.2",
"PythonPath": {
"linux": ""
},
"Classifiers": []
},
"BuildSettings": {
"ProjectType": "library",
"SourcePath": "",
"OutputPath": "../../dist",
"Main": "",
"EntryPoint": "",
"IncludePackageData": false,
"Included": [],
"Excluded": [
"*/__pycache__",
"*/logs",
"*/tests"
],
"PackageData": {},
"ProjectReferences": []
}
}