Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compilerLaLog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JAUJAY Augustin
compilerLaLog
Commits
9bb44698
Commit
9bb44698
authored
3 years ago
by
Augustin Jaujay
Browse files
Options
Downloads
Patches
Plain Diff
Ajout debuggage question 10
parent
f13adb30
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
expr/fun/toPfx.ml
+36
-7
36 additions, 7 deletions
expr/fun/toPfx.ml
with
36 additions
and
7 deletions
expr/fun/toPfx.ml
+
36
−
7
View file @
9bb44698
open
Ast
open
BasicPfx
.
Ast
let
increment
env
=
env
:=
(
List
.
map
(
fun
(
name
,
v
)
->
(
name
,
v
+
1
))
!
env
)
let
increment
env
=
env
:=
(
List
.
map
(
fun
(
name
,
v
)
->
print_endline
(
name
^
" is now associated to index "
^
(
string_of_int
(
v
+
1
)));
(
name
,
v
+
1
))
!
env
)
let
add_var
var
env
=
env
:=
(
var
,
0
)
::
(
!
env
)
let
add_var
var
env
=
env
:=
(
var
,
-
1
)
::
(
!
env
)
;
print_endline
(
var
^
" was added to env with index -1"
)
let
rec
generate
env
=
function
|
Const
x
->
increment
env
;
[
Push
x
]
|
Const
x
->
print_endline
(
"Argument is being pushed"
);
increment
env
;
[
Push
x
]
|
Binop
(
Badd
,
a
,
b
)
->
(
generate
env
b
)
@
(
generate
env
a
)
@
[
Add
]
|
Binop
(
Bsub
,
a
,
b
)
->
(
generate
env
b
)
@
(
generate
env
a
)
@
[
Sub
]
|
Binop
(
Bsub
,
a
,
b
)
->
print_endline
(
"Bsub "
^
(
string_of_expr
a
)
^
" "
^
(
string_of_expr
b
));
(
generate
env
b
)
@
(
generate
env
a
)
@
[
Sub
]
|
Binop
(
Bmul
,
a
,
b
)
->
(
generate
env
b
)
@
(
generate
env
a
)
@
[
Mul
]
|
Binop
(
Bdiv
,
a
,
b
)
->
(
generate
env
b
)
@
(
generate
env
a
)
@
[
Div
]
|
Binop
(
Bmod
,
a
,
b
)
->
(
generate
env
b
)
@
(
generate
env
a
)
@
[
Rem
]
|
App
(
Fun
(
v
,
t
)
,
arg
)
->
(
add_var
v
env
);
(
generate
env
arg
)
@
[
InstructionSeq
(
generate
env
t
);
Exec
]
|
Uminus
x
->
increment
env
;
(
generate
env
x
)
@
[
Push
0
]
@
[
Sub
]
|
Var
x
->
increment
env
;
[
Push
((
List
.
assoc
x
!
env
)
-
1
);
Get
]
|
Var
x
->
print_endline
(
"Argument "
^
x
^
" is being called"
)
;
increment
env
;
[
Push
((
List
.
assoc
x
!
env
)
-
1
);
Get
]
|
_
->
[]
(* Il faut incrémenter env à chaque Push
(*
Remarques du 22/03:
Il faut incrémenter env à chaque Push
Pistes: disjonction de cas pour les Binop où quand on reconnait
Const / Var / Uminus, on inc un des environnements (si c'est c
/ v / u et un binop on inc le binop) *)
(* Remarques de Claire 30/03: Les fonctions increment et add_var sont correctes.
Le problème semble la récursivité: il faudrait des appels de fonctions qui attendent
que la fonction appelée ait fini de s'exécuter pour passer à la suite. Sauf que ça
semble assez compliqué de mettre en place un système sync / async ou wait pour ça...
Je sais pas si l'ordre des prints est parfaitement fiable, cependant on constate
ici que c'est un peu le bordel (par exemple, seul x devrait passer à 0 lors du premier
increment, y n'est pas encore supposé avoir été ajouté).
File ./basic/tests/an_example.expr is being treated!
x was added to env with index -1
y was added to env with index -1
Bsub x y
Argument x is being called
y is now associated to index 0
x is now associated to index 0
Argument y is being called
y is now associated to index 1
x is now associated to index 1
Argument is being pushed
y is now associated to index 2
x is now associated to index 2
Argument is being pushed
y is now associated to index 3
x is now associated to index 3
0 args: Push 2 [Push 3 [Push 0 Get Push -1 Get Sub] Exec] Exec
Raised error Cannot get negative index in state executing Get with stack -1332 *)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment