Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__pycache__/

.venv
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my virtual env. Nobody needs that checked in here.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def try_build(building:BuildingId) -> Integer:
<br>
all functions pass by value and all variables in the function are only in their own scope. Note that it is the same variable for every call of the function, so if you do not set the varible it will have the value for the last call. If you need a variable from ouside the funtion you can use global to access it. otherwize it will create a new function scoped veriable.
<br>

```
def build_around_tc(building:BuildingId, radius:Integer) -> Integer:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github's markdown renderer had some kind of strange bug rendering this code bit. Added newlines to hopefully force it to be normal.

global tc_location
Expand All @@ -189,6 +190,7 @@ def build_around_tc(building:BuildingId, radius:Integer) -> Integer:
chat_to_all("E: tc_location not set, cannot build_around_tc")
return -1
```

<br>
aoe2script Commands now look like functions, as you have seen above. but they are not the same!
if you use an aoe2script command it will work like it does in the original langauge. I have just added things for conveineince bellow.
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ version = "0.0.1"
description = "compile python code to aoe2script"
readme = "README.md"
requires-python = ">=3.6"
dependencies = []
dependencies = [
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are required to run the /src/main

"aenum>=3.1.10",
"colorama>=0.4.6",
"sortedcontainers>=2.4.0",
]

[dependency-groups]
dev = [
"colorama>=0.4.6",
"bs4<1",
"pytest>=7.0.1",
"aenum>=3.1.10",
]

[tool.pytest.ini_options]
Expand Down
11 changes: 7 additions & 4 deletions src/Compiler.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import ast
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sorted all the imports without thinking.
Is it helpful? No. But it's pretty, so I didn't undo it.

from copy import copy, deepcopy
import inspect
from itertools import chain

from aenum import EnumType, Enum

from custom_ast_nodes import Command, DefRule, Variable, aoeOp, EnumNode, Constructor, JumpType, FuncModule
from Memory import Memory, FUNC_RET_REG, ARRAY_RETURN_REG, FUNC_DEPTH_COUNT, FUNC_RETURN_LENGTH, ARRAY_RETURN_PTR, FUNC_RETURN_ARRAY, ARRAY_OFFSET
from MyLogging import logger
from scraper import *
from scraper import AOE2FUNC, Integer, Constant, Array, Register
from scraper import aoe2scriptFunctions as aoe2scriptFunctions
from custom_ast_nodes import Command, DefRule, Variable, aoeOp, EnumNode, Constructor, JumpType, FuncModule
from Memory import Memory, FUNC_RET_REG, ARRAY_RETURN_REG, FUNC_DEPTH_COUNT, FUNC_RETURN_LENGTH, ARRAY_RETURN_PTR, FUNC_RETURN_ARRAY, ARRAY_OFFSET
from copy import copy, deepcopy
from utils import ast_to_aoe, evaluate_expression, get_enum_classes, reverse_compare_op, get_aoe2_var_types, get_list_from_return, TEMP_SUPBSTRING
from utils_display import print_bordered
from MyLogging import logger


reserved_function_names = [
'range',
Expand Down
27 changes: 15 additions & 12 deletions src/Main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import argparse
import ast
from collections import namedtuple
import cProfile
from math import ceil, floor
from pathlib import Path
from pprint import pprint
import re
import sys
from time import time

from colorama import Fore, Back, Style

from Asserter import Asserter
from Printer import Printer
from Compiler import Compiler
import sys
from pprint import pprint
from pathlib import Path
from Parser import Parser
from colorama import Fore, Back, Style
import re
from math import ceil, floor
import ast
from collections import namedtuple
from Printer import Printer
from scraper import *
from utils_display import print_bright, print_bordered, print_stats
import argparse
from time import time
import cProfile


def main(file_name, arguments):
first_time = time()
Expand Down
13 changes: 8 additions & 5 deletions src/Memory.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import ast
import inspect
from pprint import pprint

from sortedcontainers import SortedDict

from MyLogging import logger
from scraper import (AOE2OBJ, Point, State, Integer, Boolean,
AOE2VarType, aoe2scriptEnums, Array, Constant, Timer, Register)
from sortedcontainers import SortedDict
from utils import normalize_var_type
from utils_display import print_bright, print_dim
from pprint import pprint
import ast
import inspect
from MyLogging import logger


#! find out where the return pts for functions is and is the 15900 still hardcoded

Expand Down
1 change: 1 addition & 0 deletions src/Parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast

from scraper import Constant

class Aoe2Tree:
Expand Down
19 changes: 11 additions & 8 deletions src/Printer.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import ast
from Compiler import Command, Variable, aoeOp
from scraper import *
from scraper import mathOp, compareOp, Strenum, typeOp
from utils_display import read_file_as_string
from colorama import Fore, Back, Style
from pprint import pprint
import re
from time import time

from aenum import EnumType
from colorama import Fore, Back, Style

from Compiler import Command, Variable, aoeOp
from MyLogging import logger
from scraper import *
from scraper import mathOp, compareOp, Strenum, typeOp
from utils import get_enum_classes
from time import time
from pprint import pprint
from utils_display import read_file_as_string


class DefRulePrintVisitor(ast.NodeVisitor):
def __init__(self, final_list, const_tree = [], NO_FILE=False, TEST=True):
Expand All @@ -27,7 +30,7 @@ def __init__(self, final_list, const_tree = [], NO_FILE=False, TEST=True):
name = node.targets[0].id
value = node.value.args[0].value
self.def_const_list.add(name + " " + str(value))
except IndexErrors:
except IndexError:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wee bug, yeah?

raise Exception(f"defined Constant has no parameter, line {node.lineno}")

def visit_if(self, node):
Expand Down
11 changes: 6 additions & 5 deletions src/custom_ast_nodes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import ast
from utils import get_enum_classes, get_function_list_typeOp
from scraper import aoe2scriptFunctions as aoe2scriptFunctions
from scraper import typeOp
from Memory import FUNC_RET_REG
from enum import Enum
from scraper import AOE2FUNC

from Memory import FUNC_RET_REG
from MyLogging import logger
from scraper import aoe2scriptFunctions as aoe2scriptFunctions
from scraper import AOE2FUNC, typeOp
from utils import get_enum_classes, get_function_list_typeOp


class JumpType(Enum):
last_rule_in_node = 0
Expand Down
10 changes: 6 additions & 4 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from scraper import *
import ast
import operator
import inspect
import enum
import inspect
import operator

from MyLogging import logger
from scraper import *
import scraper.aoe2scriptEnums
from scraper.aoe2scriptFunctions import function_list, AOE2VarType
from MyLogging import logger


TEMP_SUPBSTRING = "-temp"

Expand Down
4 changes: 3 additions & 1 deletion src/utils_display.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from colorama import Fore, Back, Style
from math import ceil, floor

from colorama import Fore, Back, Style


def print_completion_bar(percentage, bar_length=50):
"""
Prints a static completion bar with the given percentage filled.
Expand Down