GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add: import · CrazyProger1/FastPy@3bafe67

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • config
    • builtin.json
    • transpiler.json
  • cpp_code
    • base.cpp
    • minimal.cpp
  • fastpy_build/src
    • main.cpp
    • print.hpp
  • fastpy
    • dev_kit
      • config.py
      • transpiler.py
    • parser
      • nodes.py
    • transpiler
      • config.py
      • transpilers.py
  • main.fpy
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎config/builtin.json‎

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"builtin_functions": {
3+
"import": "import",
4+
"log": "log"
5+
},
6+
"builtin_types": {
7+
"string": "str",
8+
"integer": "int",
9+
"boolean": "bool"
10+
}
11+
}
Collapse file

‎config/transpiler.json‎

Copy file name to clipboardExpand all lines: config/transpiler.json
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"transpiler_class": "fastpy.transpiler.transpilers.Transpiler",
33
"cpp_main_template": "minimal_main.cpp",
44
"cpp_templates_dir": "cpp_code",
5+
"cpp_template": "minimal.cpp",
6+
57
"node_transpiling": {
68
"fastpy.parser.nodes.AssignNode": "fastpy.transpiler.node_transpilers.AssignNodeTranspiler",
79
"fastpy.parser.nodes.ValueNode": "fastpy.transpiler.node_transpilers.ValueNodeTranspiler",
Collapse file

‎cpp_code/base.cpp‎

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
{% block includes %}
4+
5+
{% endblock %}
6+
7+
8+
{{ additional_includes }}
9+
10+
11+
{% block builtin_types %}
12+
13+
{% endblock %}
14+
15+
16+
{% block builtin_functions %}
17+
18+
{% endblock %}
19+
20+
21+
{{ external_code }}
22+
23+
24+
{{ internal_code }}
Collapse file

‎cpp_code/minimal.cpp‎

Copy file name to clipboard
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{% extends 'base.cpp' %}
2+
3+
{% block includes %}
4+
#include<iostream>
5+
#include<string>
6+
#include"termcolor.hpp"
7+
{% endblock %}
8+
9+
10+
{% block builtin_types %}
11+
12+
typedef std::string str;
13+
14+
{% endblock %}
15+
16+
17+
{% block builtin_functions %}
18+
template<typename T>
19+
void log(const T &t, bool endl = false) {
20+
std::cout << t;
21+
if (endl) {
22+
std::cout << std::endl;
23+
}
24+
std::cout << termcolor::reset;
25+
}
26+
27+
28+
template<typename T>
29+
void log_error(const T &t, bool endl = false) {
30+
std::cout << termcolor::on_red << termcolor::grey;
31+
log(t, endl);
32+
}
33+
34+
template<typename T>
35+
void log_info(const T &t, bool endl = false) {
36+
std::cout << termcolor::on_blue << termcolor::grey;
37+
log(t, endl);
38+
39+
}
40+
41+
template<typename T>
42+
void log_warning(const T &t, bool endl = false) {
43+
std::cout << termcolor::on_yellow << termcolor::grey;
44+
log(t, endl);
45+
}
46+
{% endblock %}
Collapse file

‎fastpy/dev_kit/config.py‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from ..config import JsonConfig, CONFIG_FOLDER
2+
from ..filesystem import FileSystem as Fs
3+
4+
builtin_config = JsonConfig(
5+
filepath=Fs.join(CONFIG_FOLDER, 'builtin.json'),
6+
authoload=True
7+
)
8+
9+
BUILTIN_TYPES = builtin_config['builtin_types']
10+
BUILTIN_FUNCTIONS = builtin_config['builtin_functions']
Collapse file

‎fastpy/dev_kit/transpiler.py‎

Copy file name to clipboardExpand all lines: fastpy/dev_kit/transpiler.py
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from fastpy.filesystem import FileSystem as Fs
22
from fastpy.log import Logger
33
from fastpy.lexer import create_lexer, BaseToken
4-
from fastpy.parser import create_parser, BaseAST, ImportNode
4+
from fastpy.parser import create_parser, BaseAST
5+
from fastpy.parser.nodes import CallNode
56
from fastpy.module import Module
67
from fastpy.transpiler import create_transpiler
8+
from .config import BUILTIN_FUNCTIONS
79

810

911
class TranspileAPI:
@@ -63,9 +65,11 @@ def _transpile_file(self, module: Module) -> str:
6365

6466
# importing modules are processed after parsing
6567
for node in ast.nodes(module.name):
66-
if isinstance(node, ImportNode):
67-
importing_file = Fs.normalize_path(node.filepath.text)
68-
self._transpile_file(Module(importing_file))
68+
if isinstance(node, CallNode):
69+
if node.identifier.text == BUILTIN_FUNCTIONS['import']:
70+
for importing_file in node.arguments:
71+
importing_file = Fs.normalize_path(importing_file.value.text)
72+
self._transpile_file(Module(importing_file))
6973

7074
# third step: transpiling
7175
cpp_code = self._translate_file(module, ast)
Collapse file

‎fastpy/parser/nodes.py‎

Copy file name to clipboardExpand all lines: fastpy/parser/nodes.py
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ def line(self) -> int:
191191
return self.condition[0].line
192192

193193

194-
class ImportNode(BasicNode, PrintableNode):
195-
def __init__(self, filepath: BaseToken = None, parts: list[BaseToken] = None):
196-
self.filepath = filepath
197-
self.parts = parts
198-
199-
@property
200-
def line(self) -> int:
201-
if not self.filepath:
202-
return -1
203-
return self.filepath.line
194+
# class ImportNode(BasicNode, PrintableNode):
195+
# def __init__(self, filepath: BaseToken = None, parts: list[BaseToken] = None):
196+
# self.filepath = filepath
197+
# self.parts = parts
198+
#
199+
# @property
200+
# def line(self) -> int:
201+
# if not self.filepath:
202+
# return -1
203+
# return self.filepath.line
Collapse file

‎fastpy/transpiler/config.py‎

Copy file name to clipboardExpand all lines: fastpy/transpiler/config.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
CPP_TEMPLATES_DIR = transpiler_config['cpp_templates_dir']
1212
CPP_MAIN_TEMPLATE_PATH = transpiler_config['cpp_main_template']
13+
CPP_TEMPLATE_PATH = transpiler_config['cpp_template']
1314

1415
NODE_TRANSPILING = transpiler_config['node_transpiling']
1516

Collapse file

‎fastpy/transpiler/transpilers.py‎

Copy file name to clipboardExpand all lines: fastpy/transpiler/transpilers.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def _load_template(self):
4646

4747
if self._current_module.name == '__main__':
4848
self._code_template = env.get_template(CPP_MAIN_TEMPLATE_PATH)
49+
else:
50+
self._code_template = env.get_template(CPP_TEMPLATE_PATH)
4951

5052
def _transpile_node(self, node: BaseNode, **kwargs) -> BaseCode:
5153
Logger.log_info(f'Transpiling: {node.line}: {node}')
Collapse file

‎fastpy_build/src/main.cpp‎

Copy file name to clipboardExpand all lines: fastpy_build/src/main.cpp
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ log((1 + 1) * 1);
5858

5959

6060
int main(){
61-
int a = 200;
61+
import("print.fpy");
62+
63+
int a = 200;
6264

6365

6466
auto b = 10;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.