Skip to content

Commit

Permalink
updated docs, readme and cli
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierOramas committed Jan 13, 2023
1 parent b90ddee commit 85302bd
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 81 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ TZscript es un DSL para la creación de contratos inteligentes, tiene como objet

Para saber como luce un contrato inteligente en TZscript,asi como las palabras claves de este lenguaje puede consultar la documentación en la carpeta doc del proyecto.

## Lexing
Para el lexer de este proyecto se utiliza la biblioteca `sly`
## Parsing
Para el parsing se desarrolló un parser SLR desde 0
## Procesamiento del AST
El AST generado por el parser es procesado utilizando el patrón Visitor.
Entre las distintas operaciones que se realizan sobre el AST destacan:
- Type Check (Realiza un checkeo de tipos sobre el AST)
- Semantic Check (Realiza un checkeo de semántico sobre el AST)
- Intermediate Representation (Genera una representación intermedia que se utiliza luego para generar Código Michelson)
- Michelson Generator (A partir de la representación intermedia genera código Michelson)
## CLI:
Se brinda una interfaz de consola para construir los ficheros `.tz` de michelson o para obtener una representacion de AST.

Expand Down
39 changes: 0 additions & 39 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,6 @@
from visitors.michelson_generator_visitor import MichelsonGenerator
import typer

fibonacci = '''contract get_fib_n(n:int){
let last_fib_calculated: int = 0;
entry get_fib(n: int){
let result: int = fib(n);
last_fib_calculated = result;
}
func fib(n: int) : int{
if (n <= 1) {
return n;
}
else {
let a: int = n - 1;
let b: int = n - 2;
return fib(a) + fib(b);
}
}
}'''

app = Typer()


Expand Down Expand Up @@ -181,23 +160,5 @@ def represent(file: str = Argument("", help="tzscript file to be parsed"),
progress.update(1)
print(f"\nGenerated {out_file}")


@app.command()
def build_run(file: str = Argument("", help="tzscript file to be parsed"),
out_file: str = Argument(None, help='michelson file to be generated and runned')):
""" generates the .tz michelson script from the tzscript file specified and executes it"""
build(file, out_file)
print("Executing file...")
# Run out_file
# TODO make the run script


@app.command()
def run(file: str = Argument(None, help='michelson file to be runned')):
print("Executing file...")
# Run out_file
# TODO make the run script


if __name__ == "__main__":
app()
23 changes: 18 additions & 5 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

## Contrato para guardar un valor positivo
```

```python
contract store_value(admin: adress){

var storage: nat = 0;
Expand All @@ -9,14 +10,26 @@ contract store_value(admin: adress){
storage = new_value;
}

entry double_previous_value(){
storage = storage * 2;
}
}
```

## Contrato que calcula n-esimo termino de fibonacci
## Contrato para sumar 2 numeros
```python
contract sum_2nums(n:int){
let x: int = 0;

entry sum(n:int){

let a: int = 2;
let b: int = 3;
x = a + b;
}

}
```

## Contrato que calcula n-esimo termino de fibonacci (no disponible su generación)
```python
contract get_fib_n(){
let last_fib_calculated = 0;

Expand Down
2 changes: 1 addition & 1 deletion docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Documentacion
El núcleo de esta documentación es la Referencia del lenguaje organizada en cuatro partes (Declaraciones, Tipos, Instrucciones y Expresiones), sobre las que se encuentran artículos temáticos que explican los conceptos básicos del lenguaje y los detalles de su implementación.

## Hello World
## Variable modification
```
contract store_value(value: int){
Expand Down
8 changes: 6 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ Se usa para representar cuando un valor puede ser de un tipo o None.
optional[<type>]
```

## Features Pendientes:

Debido a restricciones de tiempo no se pudieron desarrollar satisfactoriamente los siguientes features:



- Soporte a multiples `entry` en un mismo contract.
- Soporte a `func`
- Deploy en la blockchain de un contrato (actualmente se prueba en jupyter notebook con el kernel de michelson el codigo generado)
- Soporte a Bucles `while`
8 changes: 4 additions & 4 deletions test.tz
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
parameter int %sum;
parameter optional %sum;
storage int;
code {
UNPAIR;
PUSH int 2;
PUSH int 3;
PUSH nat 2;
PUSH nat 3;
DIG 1;
DIG 1;
ADD;
DIG 0;
DIG 1;
DROP
NIL operation;
PAIR;
Expand Down
4 changes: 3 additions & 1 deletion test.tzs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
contract sum_2nums(n:int){
calledBy
let x: int = 0;

entry sum(n:int){
entry sum(n:optional){

let a: int = 2;
let b: int = 3;
x = a + b;
Expand Down
29 changes: 0 additions & 29 deletions test.tzs.rep
Original file line number Diff line number Diff line change
@@ -1,29 +0,0 @@
\__ProgramNode: contract node.idx(n : int) [<stat>; ... <stat>;]
\__AttrDeclarationNode: n : int
\__VarDeclarationNode: let last_fib_calculated = <expr> : int
\__ ConstantNumNode: 1
\__FuncDeclarationNode: def fib(n : int) : int
\__ElseNode: else [<stat>; ... <stat>;]
\__VarDeclarationNode: let a = <expr> : nat
\__ MinusNode
\__ VariableNode: n
\__ ConstantNumNode: 1
\__VarDeclarationNode: let b = <expr> : int
\__ MinusNode
\__ VariableNode: n
\__ ConstantNumNode: 2
\__ReturnStatementNode: return <expr>
\__ PlusNode
\__CallNode: fib(<expr>, ..., <expr>)
\__ VariableNode: a
\__CallNode: fib(<expr>, ..., <expr>)
\__ VariableNode: b
\__EntryDeclarationNode: Entry get_fib(n : int)
\__AttrDeclarationNode: n : int
\__VarDeclarationNode: let ad = <expr> : address
\__ ConstantStringNode: "tz1QV341nbgxbyzd8SYU7fJtNScaLVPMZkGC"
\__VarDeclarationNode: let result = <expr> : int
\__CallNode: fib(<expr>, ..., <expr>)
\__ VariableNode: n
\__VarCallNode: last_fib_calculated = <expr>
\__ VariableNode: result

0 comments on commit 85302bd

Please sign in to comment.