timothy-g-griffin / cc_cl_cam_ac_uk Goto Github PK
View Code? Open in Web Editor NEWOCaml code for Compiler Construction course at University of Cambridge
OCaml code for Compiler Construction course at University of Cambridge
(I was trying to ask about this after the lecture but I don't think I explained myself very well.)
Since APPLY is only ever generated in a single place and a SWAP then POP follows, could the following line:
cc_cl_cam_ac_uk/slang/interp_2.ml
Lines 266 to 267 in aabaf64
| (APPLY :: ds, V(CLOSURE (c, env)) :: (V v) :: evs, s)
-> (c @ ds, (V v) :: evs, s)
and then remove the SWAP POP from here:
cc_cl_cam_ac_uk/slang/interp_2.ml
Lines 311 to 314 in aabaf64
Are function applications e1 e2
supposed to evaluate e2
before e1
?
For example, in interpreter 0, an application App (e1, e2)
is evaluated by
let (v2, store1) = interpret(e2, env, store) in
let (v1, store2) = interpret(e1, env, store1) in
( match v1 with
| FUN f -> f (v2, store2)
| v -> complain "runtime error. Expecting a function!")
evaluated e2
before e1
.
However, this doesn't adhere to the call-by-value semantics for L3 defined in IB Semantics with evaluation contexts
E[.] ::= [.] | E e | v E | ...
and transition rule
<e, s> -> <e', s'>
------------------------- (Eval)
<E[e], s> -> <E[e'], s'>
which results in e1
being evaluated before e2
is in the expression e1 e2
, and since Slang is a subset of L3, then should it not implement this evaluation order?
Due to interpreters 3 and 4 using function names for the labels of closures in many cases, it is possible to make them give errors on programs which run correctly with the other interpreters.
See the examples below:
(* Error in i3 and i4 *)
let L0 (x : int) : int =
if x = 0 then 1 else x * L0 (x-1) end
in
L0 1
end
(* Error in just i4 *)
let f (x : int) : int =
if x = 0 then 1 else x * f (x-1) end
in
let f (y : int * int) : int =
if (fst y) = 0 then 1 else (fst y) * f ((fst y) - 1, 0) end
in f (3,0) end end
(* Error in just i3 *)
let f (x : int) : int =
let f (y : int) : int = x + y in
f 9 end
in f 5 end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.