Skip to content

Commit

Permalink
OC check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Dec 25, 2024
1 parent 2d28164 commit 5861a6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Chapters/05-EvaluatorStructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Below we define a first test for it: `testReturnInteger`.
```
CInterpreterTest >> testReturnInteger
| ast result |
ast := Parser parseMethod: (CInterpretable >> #returnInteger) sourceCode.
ast := OCParser parseMethod: (CInterpretable >> #returnInteger) sourceCode.
result := self interpreter execute: ast.
self assert: result equals: 5
```
Expand Down Expand Up @@ -191,7 +191,7 @@ We already defined that our interpreter understands the `execute:` message, so
```
CInterpreterTest >> testReturnFloat
| ast result |
ast := Parser parseMethod: (CInterpretable >> #returnFloat) sourceCode.
ast := OCParser parseMethod: (CInterpretable >> #returnFloat) sourceCode.
result := self interpreter execute: ast.
self assert: result equals: 3.14
```
Expand All @@ -210,7 +210,7 @@ The method `executeSelector:` extracts some common logic that will make our test
```
CHInterpreterTest >> executeSelector: aSymbol
| ast |
ast := Parser parseMethod: (CInterpretable >> aSymbol) sourceCode.
ast := OCParser parseMethod: (CInterpretable >> aSymbol) sourceCode.
^ self interpreter execute: ast
```

Expand Down
6 changes: 3 additions & 3 deletions Chapters/07-EvaluatorFirstMessage.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ CInterpreter >> visitMessageNode: aMessageNode
| newReceiver method ast |
newReceiver := self visitNode: aMessageNode receiver.
method := newReceiver class compiledMethodAt: aMessageNode selector.
ast := RBParser parseMethod: method sourceCode.
ast := OCParser parseMethod: method sourceCode.
^ self execute: ast withReceiver: newReceiver
```

Expand All @@ -170,13 +170,13 @@ All our tests should pass and in particular `testSelfSend`.

Pharo provides a way to get an AST from a compiled method, but we do not want to use
because the AST it returns is different from the one we want for this book (the variables are resolved based on a semantical analysis).
This is why we use `RBParser parseMethod: method sourceCode.`
This is why we use `OCParser parseMethod: method sourceCode.`

To encapsulate such a decision we define the method `astOf:` and use it.

```
astOf: aCompiledMethod
^ RBParser parseMethod: aCompiledMethod sourceCode.
^ OCParser parseMethod: aCompiledMethod sourceCode.
```

```
Expand Down
4 changes: 2 additions & 2 deletions Chapters/08-EvaluatorMessageArg.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ CInterpreterTest >> testWriteTemporaryVariable
Since temporary variable name resolution is already managed by our method scopes, we just need to implement `write:withValue:` in it to make all our tests pass.

```
CHMethodScope >> write: aString withValue: aValue
CMethodScope >> write: aString withValue: aValue
variables at: aString put: aValue
```

Expand All @@ -349,7 +349,7 @@ CHMethodScope >> write: aString withValue: aValue
The last thing we need to make sure is that arguments are evaluated in the correct order.
The evaluation order in Pharo goes as follows: before evaluating a message, the receiver and all arguments are evaluated. The receiver is evaluated before the arguments. Arguments are evaluated in left-to-right order.

Testing the evaluation order in a black-box fashion as we were doing so far is rather challenging with our current evaluator. Indeed, our evaluator does not yet handle arithmetics, allocations nor other kind of primitive, so we are not able to easily count! A simple approach to test is to make a counter out of [Peano Axioms](https://en.wikipedia.org/wiki/Peano_axioms). The main idea is to implement numbers as nested sets, where the empty set is the zero, the set that contains the zero is one, the set that contains a one is a two, and so on. The only support we need for this is to extend our literal support for dynamic array literals. The code illustrating the idea follows.
Testing the evaluation order in a black-box fashion, as we have been doing so far, is rather challenging with our current evaluator. Indeed, our evaluator does not yet handle arithmetics, allocations, or other kinds of primitive, so we cannot easily count! A simple approach to test is to make a counter out of [Peano Axioms](https://en.wikipedia.org/wiki/Peano_axioms). The main idea is to implement numbers as nested sets, where the empty set _(S())_ represents the number `0`, the set _(S(S())_ that contains the empty set (`0`) represents the number `1`, the set _(S(S(S())))_ that contains the number `1` represents the number `2`, and so on. The only support we need for this is to extend our literal support for dynamic array literals. The code illustrating the idea follows.

```
CInterpretable >> initialize
Expand Down

0 comments on commit 5861a6d

Please sign in to comment.