Skip to content

Commit

Permalink
Merge branch 'arxlang:main' into transpiler
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasgrewal16 authored Oct 17, 2024
2 parents fc36e76 + 7785ba7 commit 4cd2232
Show file tree
Hide file tree
Showing 22 changed files with 709 additions and 47 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
release:
documentation:
runs-on: ubuntu-latest
timeout-minutes: 15

Expand All @@ -24,7 +24,7 @@ jobs:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
with:
Expand All @@ -34,7 +34,7 @@ jobs:
activate-environment: astx
auto-update-conda: true
conda-solver: libmamba
python-version: "3.8.1"
python-version: "3.9.*"

- name: Install deps
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
cancel-in-progress: true

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -29,9 +29,9 @@ jobs:
tests:
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
python_version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
Expand All @@ -50,7 +50,7 @@ jobs:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
with:
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
cancel-in-progress: true

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:

jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 10

Expand All @@ -18,7 +17,7 @@ jobs:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
with:
Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.makim.yaml
docs/changelog.md
1 change: 1 addition & 0 deletions conda/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ channels:
- conda-forge
dependencies:
- graphviz
- openjdk # java is required by asciinet
- python
- poetry >=1.5
- nodejs # used by semantic-release
Expand Down
3 changes: 2 additions & 1 deletion conda/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ channels:
- conda-forge
dependencies:
- graphviz
- python >=3.8.1,<3.12
- python >=3.9,<3.13
- openjdk
- poetry >=1.5
- nodejs >=18.17 # used by semantic-release
- shellcheck
Expand Down
24 changes: 14 additions & 10 deletions docs/tutorials/fibonacci.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,23 @@
"# Recursive case: return fib(n - 1) + fib(n - 2);\n",
"fib_n1_call = astx.FunctionCall(\n",
" fib_fn, \n",
" args=[astx.BinaryOp(\n",
" op_code=\"-\", \n",
" lhs=astx.Variable(name=\"n\"), \n",
" rhs=astx.LiteralInt32(1)\n",
" )]\n",
" args=(\n",
" astx.BinaryOp(\n",
" op_code=\"-\", \n",
" lhs=astx.Variable(name=\"n\"), \n",
" rhs=astx.LiteralInt32(1)\n",
" ),\n",
" )\n",
")\n",
"fib_n2_call = astx.FunctionCall(\n",
" fib_fn, \n",
" args=[astx.BinaryOp(\n",
" op_code=\"-\", \n",
" lhs=astx.Variable(name=\"n\"), \n",
" rhs=astx.LiteralInt32(2)\n",
" )]\n",
" args=(\n",
" astx.BinaryOp(\n",
" op_code=\"-\", \n",
" lhs=astx.Variable(name=\"n\"), \n",
" rhs=astx.LiteralInt32(2)\n",
" ),\n",
" )\n",
")\n",
"recursive_return = astx.FunctionReturn(\n",
" astx.BinaryOp(\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"\n",
"# Create a function call to 'simple_math'\n",
"fn_math_call = fn_math(\n",
" args=astx.Arguments(\n",
" args=(\n",
" astx.LiteralInt32(1),\n",
" astx.LiteralInt32(2),\n",
" astx.LiteralInt32(3)\n",
Expand Down
29 changes: 24 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ graphviz = ">=0.20.1"
asciinet = ">=0.3.1"
msgpack = ">=1"
plum-dispatch = ">=2.0"
typeguard = ">=4"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.3.2"
Expand All @@ -43,7 +44,7 @@ mkdocs-macros-plugin = ">=0.7.0,<1"
mkdocs-material = ">=9.1.15"
mkdocstrings = {version=">=0.24.3", extras=["python"]}
jupyterlab = ">=4.0.5"
makim = "1.15.1"
makim = "1.17.0"
umlizer = ">=0.1.0"
nbmake = ">=1.4.6"
mkdocs-gen-files = ">=0.5.0"
Expand Down
17 changes: 16 additions & 1 deletion src/astx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@
BinaryOp,
UnaryOp,
)
from astx.packages import Module, Package, Program, Target
from astx.packages import (
AliasExpr,
ImportExpr,
ImportFromExpr,
ImportFromStmt,
ImportStmt,
Module,
Package,
Program,
Target,
)
from astx.variables import (
InlineVariableDeclaration,
Variable,
Expand All @@ -115,6 +125,7 @@ def get_version() -> str:


__all__ = [
"AliasExpr",
"Argument",
"Arguments",
"AST",
Expand Down Expand Up @@ -146,6 +157,10 @@ def get_version() -> str:
"FunctionReturn",
"get_version",
"If",
"ImportFromExpr",
"ImportExpr",
"ImportStmt",
"ImportFromStmt",
"InlineVariableDeclaration",
"Int16",
"Int32",
Expand Down
13 changes: 13 additions & 0 deletions src/astx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from hashlib import sha256
from typing import ClassVar, Optional, Type, Union, cast

from typeguard import typechecked

from astx.types import ReprStruct
from astx.viz import graph_to_ascii, traverse_ast_ascii

Expand Down Expand Up @@ -48,6 +50,7 @@ class SourceLocation:
line: int
col: int

@typechecked
def __init__(self, line: int, col: int):
self.line = line
self.col = col
Expand Down Expand Up @@ -118,6 +121,13 @@ class ASTKind(Enum):
Decimal128DTKind = -620
Decimal256DTKind = -621

# imports
ImportStmtKind = -700
ImportFromStmtKind = -701
AliasExprKind = -702
ImportExprKind = -800
ImportFromExprKind = -801


class ASTMeta(type):
def __str__(cls) -> str:
Expand All @@ -135,6 +145,7 @@ class AST(metaclass=ASTMeta):
parent: Optional[ASTNodes] = None
ref: str

@typechecked
def __init__(
self,
loc: SourceLocation = NO_SOURCE_LOCATION,
Expand Down Expand Up @@ -227,6 +238,7 @@ class ASTNodes(AST):
nodes: list[AST]
position: int = 0

@typechecked
def __init__(
self,
name: str = "entry",
Expand Down Expand Up @@ -298,6 +310,7 @@ class DataType(Expr):
name: str
_tmp_id: ClassVar[int] = 0

@typechecked
def __init__(
self,
loc: SourceLocation = NO_SOURCE_LOCATION,
Expand Down
7 changes: 7 additions & 0 deletions src/astx/callables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, Optional, cast

from public import public
from typeguard import typechecked

from astx.base import (
NO_SOURCE_LOCATION,
Expand Down Expand Up @@ -34,6 +35,7 @@ class Argument(Variable):
type_: ExprType
default: Expr

@typechecked
def __init__(
self,
name: str,
Expand Down Expand Up @@ -66,6 +68,7 @@ def get_struct(self, simplified: bool = False) -> ReprStruct:
class Arguments(ASTNodes):
"""AST class for argument definition."""

@typechecked
def __init__(self, *args: Argument, **kwargs: Any) -> None:
super().__init__(**kwargs)
for arg in args:
Expand Down Expand Up @@ -94,6 +97,7 @@ class FunctionCall(DataType):
fn: Function
args: tuple[DataType, ...]

@typechecked
def __init__(
self,
fn: Function,
Expand Down Expand Up @@ -143,6 +147,7 @@ class FunctionPrototype(StatementType):
scope: ScopeKind
visibility: VisibilityKind

@typechecked
def __init__(
self,
name: str,
Expand Down Expand Up @@ -174,6 +179,7 @@ class FunctionReturn(StatementType):

value: DataType

@typechecked
def __init__(
self,
value: DataType,
Expand Down Expand Up @@ -203,6 +209,7 @@ class Function(StatementType):
prototype: FunctionPrototype
body: Block

@typechecked
def __init__(
self,
prototype: FunctionPrototype,
Expand Down
Loading

0 comments on commit 4cd2232

Please sign in to comment.