Skip to content

Commit

Permalink
improve the variable stack
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Jan 16, 2024
1 parent ae607db commit e63012f
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 143 deletions.
344 changes: 205 additions & 139 deletions docs/tutorials/variables.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/astx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class ASTKind(Enum):

# variables
VariableKind = -10
VarKind = -11 # var keyword for variable declaration
VarDeclKind = -11
VarAssignKind = -12

# operators
UnaryOpKind = -20
Expand Down
5 changes: 5 additions & 0 deletions src/astx/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ def get_struct(self) -> ReprStruct:
# Data Types


@public
class Any(DataTypeOps):
"""Generic data type expression."""


@public
class Number(DataTypeOps):
"""Number data type expression."""
Expand Down
24 changes: 21 additions & 3 deletions src/astx/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,27 @@ def __init__(
self.var_names = var_names
self.type_name = type_name
self.body = body
self.kind = ASTKind.VarKind
self.kind = ASTKind.VarDeclKind


@public
class VarAssignment(StatementType):
"""AST class for variable declaration."""

var_names: tuple[str, ...]
body: Block

def __init__(
self,
var_names: tuple[str, ...],
body: Block,
loc: SourceLocation = SourceLocation(0, 0),
) -> None:
"""Initialize the VarExprAST instance."""
self.loc = loc
self.var_names = var_names
self.body = body
self.kind = ASTKind.VarAssignKind


@public
Expand All @@ -58,8 +78,6 @@ class Variable(DataTypeOps):
def __init__(
self,
name: str,
type_: ExprType,
value: DataType,
loc: SourceLocation = SourceLocation(0, 0),
) -> None:
"""Initialize the Variable instance."""
Expand Down

0 comments on commit e63012f

Please sign in to comment.