mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:21:16 +01:00
Global variables (#378)
* global variables * implemented type checking of global variable, added test case * added a comment * improvements based on Dave's suggestions * improvements based on Jon's suggestions * added test cases about global variable ordering
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
********** source program **********
|
||||
fn f () -> Int {
|
||||
return 0;
|
||||
|
||||
}
|
||||
var Int : y = f()
|
||||
fn main () -> Int {
|
||||
return y;
|
||||
|
||||
}
|
||||
********** type checking **********
|
||||
--- step exp Int --->
|
||||
--- step exp Int --->
|
||||
--- step exp Int --->
|
||||
--- step exp Int --->
|
||||
--- step exp Int --->
|
||||
--- step exp Int --->
|
||||
|
||||
********** type checking complete **********
|
||||
fn f () -> Int {
|
||||
return 0;
|
||||
}
|
||||
var Int : y = f()
|
||||
fn main () -> Int {
|
||||
return y;
|
||||
}
|
||||
********** starting execution **********
|
||||
********** initializing globals **********
|
||||
--- step exp () --->
|
||||
--- step exp f() --->
|
||||
--- step exp f --->
|
||||
--- handle value fun<f> with f()<1>(fun<f>,) --->
|
||||
--- step exp () --->
|
||||
--- handle value () with f()<2>(fun<f>,(),) --->
|
||||
pattern_match((), ())
|
||||
--- step stmt return 0; --->
|
||||
--- step exp 0 --->
|
||||
--- handle value 0 with return 0;<1>(0,) --->
|
||||
--- step exp () --->
|
||||
********** calling main function **********
|
||||
{
|
||||
stack: top{main()<-1>}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
--- step exp main() --->
|
||||
{
|
||||
stack: top{main<-1> :: main()<0>}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
--- step exp main --->
|
||||
{
|
||||
stack: top{fun<main><-1> :: main()<0>}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
--- handle value fun<main> with main()<1>(fun<main>,) --->
|
||||
{
|
||||
stack: top{()<-1> :: main()<1>(fun<main>,)}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
--- step exp () --->
|
||||
{
|
||||
stack: top{()<-1> :: main()<1>(fun<main>,)}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
--- handle value () with main()<2>(fun<main>,(),) --->
|
||||
pattern_match((), ())
|
||||
{
|
||||
stack: main{return y;<-1>} :: top{}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
--- step stmt return y; --->
|
||||
{
|
||||
stack: main{y<-1> :: return y;<0>} :: top{}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
--- step exp y --->
|
||||
{
|
||||
stack: main{0<-1> :: return y;<0>} :: top{}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
--- handle value 0 with return y;<1>(0,) --->
|
||||
{
|
||||
stack: top{0<-1>}
|
||||
heap: fun<f>, 0, fun<main>,
|
||||
env: main: fun<main>, y: 0, f: fun<f>,
|
||||
}
|
||||
result: 0
|
||||
Reference in New Issue
Block a user