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
93aa43fe
Commit
93aa43fe
authored
3 years ago
by
Augustin Jaujay
Browse files
Options
Downloads
Patches
Plain Diff
Question 10.3 complète
parent
9bb44698
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
expr/basic/tests/an_example.expr
+1
-1
1 addition, 1 deletion
expr/basic/tests/an_example.expr
expr/fun/toPfx.ml
+8
-42
8 additions, 42 deletions
expr/fun/toPfx.ml
with
9 additions
and
43 deletions
expr/basic/tests/an_example.expr
+
1
−
1
View file @
93aa43fe
(
fun x ->
(fun
y
-> x
- y) 3 ) 2
((fun
x
-> x
+ 1) 7)
This diff is collapsed.
Click to expand it.
expr/fun/toPfx.ml
+
8
−
42
View file @
93aa43fe
...
...
@@ -7,46 +7,12 @@ let add_var var env = env := (var, -1)::(!env) ; print_endline (var ^ " was adde
let
rec
generate
env
=
function
|
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
)
->
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
]
|
Binop
(
Badd
,
a
,
b
)
->
let
y
=
(
generate
env
b
)
in
y
@
(
generate
env
a
)
@
[
Add
]
|
Binop
(
Bsub
,
a
,
b
)
->
let
y
=
(
generate
env
b
)
in
y
@
(
generate
env
a
)
@
[
Sub
]
|
Binop
(
Bmul
,
a
,
b
)
->
let
y
=
(
generate
env
b
)
in
y
@
(
generate
env
a
)
@
[
Mul
]
|
Binop
(
Bdiv
,
a
,
b
)
->
let
y
=
(
generate
env
b
)
in
y
@
(
generate
env
a
)
@
[
Div
]
|
Binop
(
Bmod
,
a
,
b
)
->
let
y
=
(
generate
env
b
)
in
y
@
(
generate
env
a
)
@
[
Rem
]
|
App
(
Fun
(
v
,
t
)
,
arg
)
->
(
add_var
v
env
);
let
y
=
(
generate
env
arg
)
in
y
@
[
InstructionSeq
(
generate
env
t
);
Exec
;
Swap
;
Pop
]
|
Uminus
x
->
(
generate
env
x
)
@
[
Push
0
]
@
[
Sub
]
|
Var
x
->
print_endline
(
"Argument "
^
x
^
" is being called"
)
;
increment
env
;
[
Push
((
List
.
assoc
x
!
env
)
-
1
);
Get
]
|
_
->
[]
\ No newline at end of file
(* 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