Skip to content

Instantly share code, notes, and snippets.

@prabhatexit0
Last active August 25, 2023 21:18
Show Gist options
  • Save prabhatexit0/0ab3a7fec99e61eacccbcd4cf309b255 to your computer and use it in GitHub Desktop.
Save prabhatexit0/0ab3a7fec99e61eacccbcd4cf309b255 to your computer and use it in GitHub Desktop.
This is what the trace output of Carbon Explorer was like after the Google Summer of Code 23 project was completed.
* * * * * * * * * * starting execution * * * * * * * * * *
------------------------------------------------------------
- - - - - initializing globals - - - - -
------------------------------------------
>[] stack-push: DeclarationAction pos: 0 `namespace N` (./testfile.carbon:3)
->> step DeclarationAction pos: 0 `namespace N` (./testfile.carbon:3) --->
*** declaration at (./testfile.carbon:3)
```
namespace N;
```
<[] stack-pop: DeclarationAction pos: 0 `namespace N` (./testfile.carbon:3)
>[] stack-push: DeclarationAction pos: 0 `fn N.Add` (./testfile.carbon:7)
->> step DeclarationAction pos: 0 `fn N.Add` (./testfile.carbon:7) --->
*** declaration at (./testfile.carbon:7)
```
fn Add (a: i32, b: i32) -> i32
{
return (a + b);
}
```
<[] stack-pop: DeclarationAction pos: 0 `fn N.Add` (./testfile.carbon:7)
>[] stack-push: DeclarationAction pos: 0 `fn Main` (./testfile.carbon:12)
->> step DeclarationAction pos: 0 `fn Main` (./testfile.carbon:12) --->
*** declaration at (./testfile.carbon:12)
```
fn Main () -> i32
{
var sum: auto = N.Add(1, 2);
return sum;
}
```
<[] stack-pop: DeclarationAction pos: 0 `fn Main` (./testfile.carbon:12)
- - - - - calling main function - - - - -
-------------------------------------------
>[] stack-push: ValueExpressionAction pos: 0 `Main()` (<Main()>:0)
->> step ValueExpressionAction pos: 0 `Main()` (<Main()>:0) --->
>[] stack-push: ExpressionAction pos: 0 `Main()` (<Main()>:0)
->> step ExpressionAction pos: 0 `Main()` (<Main()>:0) --->
>[] stack-push: ValueExpressionAction pos: 0 `Main` (<Main()>:0)
->> step ValueExpressionAction pos: 0 `Main` (<Main()>:0) --->
>[] stack-push: ExpressionAction pos: 0 `Main` (<Main()>:0)
->> step ExpressionAction pos: 0 `Main` (<Main()>:0) --->
<[] stack-pop: ExpressionAction pos: 0 `Main` (<Main()>:0)
->> step ValueExpressionAction pos: 1 `Main` results: [`fun<Main>`] (<Main()>:0) --->
<[] stack-pop: ValueExpressionAction pos: 1 `Main` results: [`fun<Main>`] (<Main()>:0)
->> step ExpressionAction pos: 1 `Main()` results: [`fun<Main>`] scope: [] (<Main()>:0) --->
-() calling function: fun<Main>
=== match pattern `()`
from value expression with value `()`
>[] stack-push: ScopeAction pos: 0 scope: [] (None)
>[] stack-push: StatementAction pos: 0 `{ ... }` (./testfile.carbon:12)
->> step StatementAction pos: 0 `{ ... }` (./testfile.carbon:12) --->
*** statement at (./testfile.carbon:12)
```
{
var sum: auto = N.Add(1, 2);
return sum;
}
```
>[] stack-push: StatementAction pos: 0 `var ... = ...;` (./testfile.carbon:10)
->> step StatementAction pos: 0 `var ... = ...;` (./testfile.carbon:10) --->
*** statement at (./testfile.carbon:10)
```
var sum: auto = N.Add(1, 2);
```
++# memory-alloc: #1 `Uninit<i32>` uninitialized
>[] stack-push: ExpressionAction pos: 0 `N.Add(1, 2)` (./testfile.carbon:10)
->> step ExpressionAction pos: 0 `N.Add(1, 2)` (./testfile.carbon:10) --->
>[] stack-push: ValueExpressionAction pos: 0 `N.Add` (./testfile.carbon:10)
->> step ValueExpressionAction pos: 0 `N.Add` (./testfile.carbon:10) --->
>[] stack-push: ExpressionAction pos: 0 `N.Add` (./testfile.carbon:10)
->> step ExpressionAction pos: 0 `N.Add` (./testfile.carbon:10) --->
<[] stack-pop: ExpressionAction pos: 0 `N.Add` (./testfile.carbon:10)
>[] stack-push: ExpressionAction pos: 0 `Add` (./testfile.carbon:10)
->> step ExpressionAction pos: 0 `Add` (./testfile.carbon:10) --->
<[] stack-pop: ExpressionAction pos: 0 `Add` (./testfile.carbon:10)
->> step ValueExpressionAction pos: 1 `N.Add` results: [`fun<N.Add>`] (./testfile.carbon:10) --->
<[] stack-pop: ValueExpressionAction pos: 1 `N.Add` results: [`fun<N.Add>`] (./testfile.carbon:10)
->> step ExpressionAction pos: 1 `N.Add(1, 2)` results: [`fun<N.Add>`] scope: [] (./testfile.carbon:10) --->
>[] stack-push: ExpressionAction pos: 0 `1` (./testfile.carbon:10)
->> step ExpressionAction pos: 0 `1` (./testfile.carbon:10) --->
<[] stack-pop: ExpressionAction pos: 0 `1` (./testfile.carbon:10)
->> step ExpressionAction pos: 2 `N.Add(1, 2)` results: [`fun<N.Add>`, `1`] scope: [] (./testfile.carbon:10) --->
>[] stack-push: ExpressionAction pos: 0 `2` (./testfile.carbon:10)
->> step ExpressionAction pos: 0 `2` (./testfile.carbon:10) --->
<[] stack-pop: ExpressionAction pos: 0 `2` (./testfile.carbon:10)
->> step ExpressionAction pos: 3 `N.Add(1, 2)` results: [`fun<N.Add>`, `1`, `2`] scope: [] (./testfile.carbon:10) --->
-() calling function: fun<N.Add>
=== match pattern `(Placeholder<a>, Placeholder<b>)`
from value expression with value `(1, 2)`
=== match pattern `Placeholder<a>`
from value expression with value `1`
=== match pattern `Placeholder<b>`
from value expression with value `2`
>[] stack-push: ScopeAction pos: 0 scope: [`a: i32`: `1`, `b: i32`: `2`] (None)
>[] stack-push: StatementAction pos: 0 `{ ... }` (./testfile.carbon:7)
->> step StatementAction pos: 0 `{ ... }` (./testfile.carbon:7) --->
*** statement at (./testfile.carbon:7)
```
{
return (a + b);
}
```
>[] stack-push: StatementAction pos: 0 `return ...;` (./testfile.carbon:6)
->> step StatementAction pos: 0 `return ...;` (./testfile.carbon:6) --->
*** statement at (./testfile.carbon:6)
```
return (a + b);
```
>[] stack-push: ValueExpressionAction pos: 0 `(a + b)` (./testfile.carbon:6)
->> step ValueExpressionAction pos: 0 `(a + b)` (./testfile.carbon:6) --->
>[] stack-push: ExpressionAction pos: 0 `(a + b)` (./testfile.carbon:6)
->> step ExpressionAction pos: 0 `(a + b)` (./testfile.carbon:6) --->
>[] stack-push: ValueExpressionAction pos: 0 `a` (./testfile.carbon:6)
->> step ValueExpressionAction pos: 0 `a` (./testfile.carbon:6) --->
>[] stack-push: ExpressionAction pos: 0 `a` (./testfile.carbon:6)
->> step ExpressionAction pos: 0 `a` (./testfile.carbon:6) --->
<[] stack-pop: ExpressionAction pos: 0 `a` (./testfile.carbon:6)
->> step ValueExpressionAction pos: 1 `a` results: [`1`] (./testfile.carbon:6) --->
<[] stack-pop: ValueExpressionAction pos: 1 `a` results: [`1`] (./testfile.carbon:6)
->> step ExpressionAction pos: 1 `(a + b)` results: [`1`] (./testfile.carbon:6) --->
>[] stack-push: ValueExpressionAction pos: 0 `b` (./testfile.carbon:6)
->> step ValueExpressionAction pos: 0 `b` (./testfile.carbon:6) --->
>[] stack-push: ExpressionAction pos: 0 `b` (./testfile.carbon:6)
->> step ExpressionAction pos: 0 `b` (./testfile.carbon:6) --->
<[] stack-pop: ExpressionAction pos: 0 `b` (./testfile.carbon:6)
->> step ValueExpressionAction pos: 1 `b` results: [`2`] (./testfile.carbon:6) --->
<[] stack-pop: ValueExpressionAction pos: 1 `b` results: [`2`] (./testfile.carbon:6)
->> step ExpressionAction pos: 2 `(a + b)` results: [`1`, `2`] (./testfile.carbon:6) --->
<[] stack-pop: ExpressionAction pos: 2 `(a + b)` results: [`1`, `2`] (./testfile.carbon:6)
->> step ValueExpressionAction pos: 1 `(a + b)` results: [`3`] (./testfile.carbon:6) --->
<[] stack-pop: ValueExpressionAction pos: 1 `(a + b)` results: [`3`] (./testfile.carbon:6)
->> step StatementAction pos: 1 `return ...;` results: [`3`] (./testfile.carbon:6) --->
*** statement at (./testfile.carbon:6)
```
return (a + b);
```
--> memory-write: #1 `3`
<[] stack-pop: StatementAction pos: 1 `return ...;` results: [`3`] (./testfile.carbon:6)
<[] stack-pop: StatementAction pos: 1 `{ ... }` scope: [] (./testfile.carbon:7)
<[] stack-pop: ScopeAction pos: 0 scope: [`a: i32`: `1`, `b: i32`: `2`] (None)
>[] stack-push: CleanUpAction pos: 0 scope: [`a: i32`: `1`, `b: i32`: `2`] (stack cleanup:1)
>[] stack-push: CleanUpAction pos: 0 scope: [] (stack cleanup:1)
->> step CleanUpAction pos: 0 scope: [] (stack cleanup:1) --->
<[] stack-pop: CleanUpAction pos: 0 scope: [] (stack cleanup:1)
->> step CleanUpAction pos: 0 scope: [`a: i32`: `1`, `b: i32`: `2`] (stack cleanup:1) --->
<[] stack-pop: CleanUpAction pos: 0 scope: [`a: i32`: `1`, `b: i32`: `2`] (stack cleanup:1)
->> step ExpressionAction pos: 4 `N.Add(1, 2)` results: [`fun<N.Add>`, `1`, `2`, `3`] scope: [] (./testfile.carbon:10) --->
<[] stack-pop: ExpressionAction pos: 4 `N.Add(1, 2)` results: [`fun<N.Add>`, `1`, `2`, `3`] scope: [] (./testfile.carbon:10)
>[] stack-push: CleanUpAction pos: 0 scope: [] (stack cleanup:1)
->> step CleanUpAction pos: 0 scope: [] (stack cleanup:1) --->
<[] stack-pop: CleanUpAction pos: 0 scope: [] (stack cleanup:1)
->> step StatementAction pos: 1 `var ... = ...;` results: [`3`] (./testfile.carbon:10) --->
*** statement at (./testfile.carbon:10)
```
var sum: auto = N.Add(1, 2);
```
<-- memory-read: #1 `3`
=== match pattern `Placeholder<sum>`
from initializing expression with value `3`
<[] stack-pop: StatementAction pos: 1 `var ... = ...;` results: [`3`] (./testfile.carbon:10)
->> step StatementAction pos: 1 `{ ... }` scope: [`sum: auto`: `lval<Allocation(1)>`] (./testfile.carbon:12) --->
*** statement at (./testfile.carbon:12)
```
{
var sum: auto = N.Add(1, 2);
return sum;
}
```
>[] stack-push: StatementAction pos: 0 `return ...;` (./testfile.carbon:11)
->> step StatementAction pos: 0 `return ...;` (./testfile.carbon:11) --->
*** statement at (./testfile.carbon:11)
```
return sum;
```
>[] stack-push: ValueExpressionAction pos: 0 `sum` (./testfile.carbon:11)
->> step ValueExpressionAction pos: 0 `sum` (./testfile.carbon:11) --->
>[] stack-push: ExpressionAction pos: 0 `sum` (./testfile.carbon:11)
->> step ExpressionAction pos: 0 `sum` (./testfile.carbon:11) --->
<-- memory-read: #1 `3`
<[] stack-pop: ExpressionAction pos: 0 `sum` (./testfile.carbon:11)
->> step ValueExpressionAction pos: 1 `sum` results: [`3`] (./testfile.carbon:11) --->
<[] stack-pop: ValueExpressionAction pos: 1 `sum` results: [`3`] (./testfile.carbon:11)
->> step StatementAction pos: 1 `return ...;` results: [`3`] (./testfile.carbon:11) --->
*** statement at (./testfile.carbon:11)
```
return sum;
```
<[] stack-pop: StatementAction pos: 1 `return ...;` results: [`3`] (./testfile.carbon:11)
<[] stack-pop: StatementAction pos: 2 `{ ... }` scope: [`sum: auto`: `lval<Allocation(1)>`] (./testfile.carbon:12)
<[] stack-pop: ScopeAction pos: 0 scope: [] (None)
>[] stack-push: CleanUpAction pos: 0 scope: [] (stack cleanup:1)
>[] stack-push: CleanUpAction pos: 0 scope: [`sum: auto`: `lval<Allocation(1)>`] (stack cleanup:1)
->> step CleanUpAction pos: 0 scope: [`sum: auto`: `lval<Allocation(1)>`] (stack cleanup:1) --->
<-- memory-read: #1 `3`
>[] stack-push: DestroyAction pos: 0 (None)
->> step DestroyAction pos: 0 (None) --->
<[] stack-pop: DestroyAction pos: 0 (None)
->> step CleanUpAction pos: 1 scope: [`sum: auto`: `lval<Allocation(1)>`] (stack cleanup:1) --->
--# memory-dealloc: #1 `3`
->> step CleanUpAction pos: 2 scope: [`sum: auto`: `lval<Allocation(1)>`] (stack cleanup:1) --->
<[] stack-pop: CleanUpAction pos: 2 scope: [`sum: auto`: `lval<Allocation(1)>`] (stack cleanup:1)
->> step CleanUpAction pos: 0 scope: [] (stack cleanup:1) --->
<[] stack-pop: CleanUpAction pos: 0 scope: [] (stack cleanup:1)
->> step ExpressionAction pos: 2 `Main()` results: [`fun<Main>`, `3`] scope: [] (<Main()>:0) --->
<[] stack-pop: ExpressionAction pos: 2 `Main()` results: [`fun<Main>`, `3`] scope: [] (<Main()>:0)
>[] stack-push: CleanUpAction pos: 0 scope: [] (stack cleanup:1)
->> step CleanUpAction pos: 0 scope: [] (stack cleanup:1) --->
<[] stack-pop: CleanUpAction pos: 0 scope: [] (stack cleanup:1)
->> step ValueExpressionAction pos: 1 `Main()` results: [`3`] (<Main()>:0) --->
<[] stack-pop: ValueExpressionAction pos: 1 `Main()` results: [`3`] (<Main()>:0)
==> interpreter result: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment