Skip to content

Commit 083278e

Browse files
Merge pull request #4 from unknowncoder05/dev
basic and unfinished python compiler
2 parents 88a2cf1 + f9237f7 commit 083278e

File tree

31 files changed

+790
-110
lines changed

31 files changed

+790
-110
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# App architect
22

3+
### Python Compiler
4+
There is no faster way for understanding than trying it yourself.
5+
you can execute the next command in the root of the project (this folder) and a simple code wil be generated.
6+
```sh
7+
python .\compiler\compiler.py c "python.json.v1" ./blueprints/examples/calculator/v2/services/processing/operations/sum.code.json code.py
8+
```
9+
10+
You can check the base blueprint for this project in the route examples/calculator/v2/services/processing/operations/sum.code.json
11+
12+
```py
13+
def sum(number_a:int, number_b:int, *, debug:bool=False)->int:
14+
result:str = number_a+number_b
15+
if debug:
16+
print(result)
17+
return result
18+
```
19+
This is the expected answer, a simple function with all that we specified in the code.json file and ready to be used.
20+
21+
#### What is so special about this?
22+
This is a basic format for you to generate code in any language, in any framework as long as the correct compiler is available.
23+
24+
### Current roadmap for this project
25+
26+
- Finish the basic Python compiler
27+
- Add tests
28+
- Work in the JS Express compiler
29+
- Create a UI from where to Edit code and generate the proper code.json, then you can choose from your saved snippets or those that other people had made public
30+
### App Compiler
331
Design your application in a json like structure, this way the resulting project is going to be easily understood both by human and by machine.
432

533
This json like structure will let you:

blueprints/examples/calculator/v2/services/operate.service.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
"endpoints": {
33
"sum":{
44
"request":{"a":{"type":"int"}, "b":{"type":"int"}},
5-
"response":{"a":{"type":"int"}, "b":{"type":"int"}},
5+
"response":{"result":{"type":"int"}},
66
"processing":{
7-
"from": "processing.operations.sum",
8-
"number_a": "a",
9-
"number_b": "b",
10-
"message": "calculating sum"
7+
"__extends":{
8+
"__from": "processing.operations.sum"
9+
}
1110
}
1211
}
1312
}
Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
{
22
"engine": "python3.8",
3+
"__description": "what seams like a simple sum",
34
"__constructor":{
4-
"description": "what seams like a simple sum",
55
"number_a":{"type":"str", "default":"number_a"},
66
"number_b":{"type":"str", "default":"number_b"},
7-
"message":{"type":"str", "default":"adding {__number_a} to {__number_b}"}
7+
"message":{"type":"str", "default":"adding {__number_a} to {__number_b}"},
8+
"function_name":{"type":"str", "default":"sum"}
89
},
9-
"inputs":{
10-
"__number_a":{"type":"str", "required":true},
11-
"__number_b":{"type":"str", "required":true}
10+
"type": "function",
11+
"name": "__function_name",
12+
"args":{
13+
"__number_a":{"type":"int", "required":true},
14+
"__number_b":{"type":"int", "required":true}
15+
},
16+
"kwargs":{
17+
"debug":{"type":"bool", "default":false}
18+
},
19+
"outputs":{
20+
"result":{"type":"int", "required":true}
1221
},
1322
"code": [
14-
{
15-
"type": "function",
16-
"name": "print",
17-
"args": ["f\"__message\""]
18-
},
1923
{
2024
"type": "variable",
2125
"variable_type": "str",
22-
"name": "sum_result",
23-
"equals": ["__number_a+number_b"]
26+
"name": "result",
27+
"expression": "__number_a+number_b"
28+
},
29+
{
30+
"type": "conditional",
31+
"condition": "debug",
32+
"code": [
33+
{
34+
"type": "function_call",
35+
"function":"print",
36+
"args": ["result"]
37+
}
38+
]
2439
},
2540
{
2641
"type": "return",
27-
"args": ["sum_result"]
42+
"args": ["result"]
2843
}
2944
]
3045
}

blueprints/examples/facebook/main.app.json

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@
22
"name": "facebook",
33
"models": {
44
"user":"global.utils.auth.user.models.user",
5-
"conversation":"global.communication.chat.models.conversation",
6-
"message":"global.communication.chat.feed.models.message"
5+
"conversation":{"__extends":{
6+
"__from":"global.communication.chat.models.conversation",
7+
"user":"user"
8+
}},
9+
"message":{"__extends":{
10+
"__from":"global.communication.chat.feed.models.message",
11+
"user":"user"
12+
}}
713
},
814
"services": {
9-
"user":"global.utils.services.user",
10-
"conversation":"global.communication.chat.services.conversation",
11-
"message":"global.communication.chat.services.message"
15+
"user":{"__extends":{
16+
"__from":"global.utils.auth.user.services.user",
17+
"user":"user"
18+
}},
19+
"conversation":{"__extends":{
20+
"__from":"global.communication.chat.services.conversation",
21+
"user":"user",
22+
"conversation":"conversation"
23+
}},
24+
"message":{"__extends":{
25+
"__from":"global.communication.chat.services.message",
26+
"user":"user"
27+
}}
1228
}
1329
}

blueprints/global/communication/chat/feed/models/feed.model.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"__constructor":{
33
"user":{
4-
"description":"user to be used"
5-
}
4+
"description":"user model to be used",
5+
"type":"str"
6+
}
67
},
78
"attributes":{
89
"id": {"type":"id"},
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"__constructor":{
33
"user":{
4-
"description":"user to be used"
5-
}
4+
"description":"user model to be used",
5+
"type":"str"
6+
}
7+
},
8+
"__extends":{
9+
"__from":"global.communication.chat.models.message",
10+
"user":"__user"
611
},
712
"attributes":{
813
"feed":{"type":"feed", "required":true, "user":"__user"}
9-
},
10-
"__extends":{
11-
"__from":"global.communication.chat.models.message"
1214
}
1315
}

blueprints/global/communication/chat/feed/models/reaction.model.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"__constructor":{
33
"user":{
4-
"description":"user to be used"
5-
}
4+
"description":"user model to be used",
5+
"type":"str"
6+
}
67
},
78
"attributes":{
89
"id": {"type":"id"},

blueprints/global/communication/chat/models/conversation.model.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"__constructor":{
33
"user":{
44
"description":"user model to be used",
5-
"default":"global.auth.user.models.user"
5+
"type":"str"
66
}
77
},
88
"attributes":{
@@ -23,8 +23,8 @@
2323
},
2424
"get":{
2525
"__extends":{
26-
"__from":"create",
27-
"__excludes":[ "id"]
26+
"__from":"attributes",
27+
"__excludes":["id"]
2828
}
2929
}
3030
}

blueprints/global/communication/chat/models/message.model.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"__constructor":{
33
"user":{
4-
"type":"str",
5-
"description":"route to user to be used"
4+
"description":"user model to be used",
5+
"type":"str"
66
}
77
},
88
"attributes":{
@@ -25,7 +25,7 @@
2525
},
2626
"get":{
2727
"__extends":{
28-
"__from":"create",
28+
"__from":"attributes",
2929
"__excludes":[ "id"]
3030
}
3131
}

blueprints/global/communication/chat/services/conversation.service.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"__constructor":{
33
"conversation":{
44
"description":"conversation model to be used",
5-
"default":"global.communication.chat.models.conversation"
5+
"type": "str"
66
}
77
},
88
"endpoints":{

blueprints/global/utils/auth/user/models/user.model.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
"list":{
2323
"response":{
2424
"__extends":{
25-
"from":"attributes",
25+
"__from":"attributes",
2626
"__excludes":["password"]
2727
}
2828
}
2929
},
3030
"get":{
3131
"request":{
3232
"__extends":{
33-
"from":"attributes",
33+
"__from":"attributes",
3434
"__includes":["id"]
3535
}
3636
},
3737
"response":{
3838
"__extends":{
39-
"from":"attributes",
39+
"__from":"attributes",
4040
"__excludes":["id"]
4141
}
4242
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
3+
}

compiler/compiler.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
1-
from json_compiler.Compiler import Compiler as json_compiler
1+
import json
22
import sys
3-
COMPILERS = {
4-
"django-postgres.v1": "under development",
5-
"flask-mongo.v1": "under development",
6-
"nodejs-mongo.v1": "under development",
3+
from json_compiler.Compiler import Compiler as json_compiler
4+
from django_compiler.Compiler import Compiler as django_compiler
5+
from python_compiler.Compiler import Compiler as python_compiler
6+
7+
COMPILERS = { # "framework.language.version: compiler"
8+
"django.json.v1": django_compiler,
9+
"python.json.v1": python_compiler,
10+
"flask.json.v1": "under development",
11+
"nodejs.json.v1": "under development",
712
"json.v1": json_compiler
813
}
914
def compile(compiler_name, project_name):
10-
compiler = COMPILERS[compiler_name](project_name)
11-
compiler.compile()
15+
compiler = COMPILERS[compiler_name](main_file=project_name)
16+
compiled_project = compiler.compile()
17+
print(compiled_project)
18+
# TODO: propper file extension and format saving
19+
'''
20+
with open(f"./{sys.argv[4]}", "w") as f:
21+
json.dump(compiled_project, f, indent=4)
22+
'''
1223
OPTIONS = {
1324
"compile": compile,
1425
"c": compile
1526
}
1627
def main():
28+
# 1 action
29+
# 2 compiler
30+
# 3 project
31+
# 4 destination folder
1732
OPTIONS[sys.argv[1]](sys.argv[2], sys.argv[3])
1833
return
1934

2035
main()
21-
# python .\compiler.py c "json.v1" ../blueprints/examples/facebook/main.app.json
22-
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/import.app.json
23-
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/construct.app.json
36+
# python .\compiler.py c "json.v1" ../blueprints/examples/facebook/main.app.json build
37+
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/import.app.json build
38+
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/construct.app.json build
39+
# python .\compiler.py c "json.v1" ../blueprints/examples/calculator/v2/main.app.json build
40+
41+
# python .\compiler.py c "django.json.v1" ../blueprints/examples/facebook/main.app.json build
42+
# python .\compiler.py c "python.json.v1" ../blueprints/examples/calculator/v2/services/processing/operations/sum.code.json build/build
43+

0 commit comments

Comments
 (0)