Giter Site home page Giter Site logo

cc_cl_cam_ac_uk's Introduction

cc2020_cl_cam_ac_uk

cc_cl_cam_ac_uk's People

Contributors

dhruvtapasvi avatar dougboyle avatar henrymercer avatar pspencil avatar raphael-proust avatar timothy-g-griffin avatar tmvector avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cc_cl_cam_ac_uk's Issues

APPLY instruction in I2

(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:

| (APPLY :: ds, V(CLOSURE (c, env)) :: (V v) :: evs, s)
-> (c @ ds, (V v) :: (EV env) :: evs, s)

be optimised to:

 | (APPLY :: ds,  V(CLOSURE (c, env)) :: (V v) :: evs, s)  
                                                   -> (c @ ds, (V v) :: evs, s) 

and then remove the SWAP POP from here:

| App(e1, e2) -> (compile e2) (* I chose to evaluate arg first *)
@ (compile e1)
@ [APPLY;
SWAP; POP] (* get rid of env left on stack *)

Call-by-value Semantics

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?

Closures in interpreters 3 and 4

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.