Skip to content

Commit

Permalink
cutting chapter 3 in two
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Aug 13, 2024
1 parent 8293080 commit 70e942d
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 367 deletions.
367 changes: 0 additions & 367 deletions Chapters/3-MethodsAndBytecode/methodsbytecode.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions Chapters/5-DeeperBytecode/contextReification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Contexts


Push, store, and jump bytecodes require only small changes to the state of the interpreter.
Objects may be moved to or from the stack, and the instruction pointer is always changed; but most of the state remains the same. Send and return bytecodes require much larger changes to the interpreter's state.

When a new message is sent \(for example message `x` or `-` above\), all five parts of the interpreter's state may have to be changed to execute a different CompiledMethod in response to this new message. The interpreter's old state must be remembered because the bytecodes after the send must be executed after the value of the message is returned.

The interpreter saves its state in objects called _contexts_. There will be many contexts in the system at any one time. The context that represents the current state of the interpreter is called the _active_ context. When a send bytecode in the active context's CompiledMethod requires a new compiled method to be executed, the active context becomes _suspended_ and a new context is created and made active. The suspended context retains the state associated with the original compiled method until that context becomes active again. A context must remember the context that it suspended so that the suspended context can be resumed when a result is returned. The suspended context is called the new context's _sender_.



We extend the form used to show the interpreter's state. The active context will be indicated by the word **Active** in its top delimiter. Suspended contexts will say **Suspended**.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions Chapters/5-DeeperBytecode/figures/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://www.gnu.org/software/make/manual/html_node/
# https://crates.io/crates/svgbob_cli
# https://github.com/ivanceras/svgbob?tab=readme-ov-file

# Find all the -ascii.txt files we want to compile
# Note the single quotes around the * expressions. The shell will incorrectly expand these otherwise, but we want to send the * directly to the find command.
SRC_DIRS := .
BUILD_DIR := .
SRCS := $(shell find $(SRC_DIRS) -name '*-ascii.txt')
PDFs := $(SRCS:-ascii.txt=.pdf)

.PHONY: default
default: all

all: $(PDFs)

%.svg : %-ascii.txt
svgbob_cli $< -o $@

%.pdf : %.svg
rsvg-convert -f pdf -o $@ $<

.PHONY: clean
clean:
rm -rf *.svg $(PDFs)
36 changes: 36 additions & 0 deletions Chapters/5-DeeperBytecode/figures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# About the figures

## Old figures: omnigraffle

Old figures are made with omnigraffle and exported to pdf and png.
Latex output uses pdf.

The problem with these is that keeping the same look and feel over all of these is very complicated.

## New figures: asciiart -> svg -> pdf

Using asciiart allows me (Guille) to keep the same look and feel in the figures.
Converting ascii art to pdf requires two command line tools: `aasvg` and `rsvg-convert` which I installed as follows in Mac:

```bash
npm install -g aasvg
sudo apt-get install librsvg2-bin
```
If the previous apt-get does not work

Notice that you should also install svgbob

```
brew install librsvg
brew install svgbob
```

Figure source code is asciiart and named `*-ascii.txt`.
We then convert them to svg using the following commands.

**TIP: Use the makefile ;)**

```
aasvg < x.txt > x.svg
rsvg-convert -f pdf -o x.pdf x.svg
```
16 changes: 16 additions & 0 deletions Chapters/5-DeeperBytecode/figures/compile_method_shape-ascii.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

compiled method
\
v
method header -------->+---------------------+
|'Hello'
|#nextPutAll:
|...
byte code -----------> +---------------------+
|80
|put real one here
|
method trailer ----> +---------------------+
|
|
method end ----> +---------------------+
Binary file not shown.
Binary file added Chapters/5-DeeperBytecode/figures/frames.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
363 changes: 363 additions & 0 deletions Chapters/5-DeeperBytecode/methodsbytecode.md

Large diffs are not rendered by default.

Binary file added _support/latex/CreativeCommons-BY-NC-ND.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions _support/latex/common.tex
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@
\newenvironment{todo}{%
\begin{leftbar}\textsf{\textbf{To do}}\quad
}{\end{leftbar}}


\bodpage{}
1 change: 1 addition & 0 deletions _support/templates/latex/main.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
\usepackage[color=magenta,width=5mm]{_support/latex/overcolored}
\fi

\bodpage{}

% =================================================================
\title{«& title»}
Expand Down
1 change: 1 addition & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This work is also supported by the Action Exploratoire Alamvic led by G. Polito
<!inputFile|path=Chapters/2-ObjectStructure/objectStructure.md!>
<!inputFile|path=Chapters/3-MethodsAndBytecode/methodsbytecode.md!>
<!inputFile|path=Chapters/4-Interpreter/theInterpreter.md!>
<!inputFile|path=Chapters/5-DeeperBytecode/methodsbytecode.md!>


## Slang
Expand Down

0 comments on commit 70e942d

Please sign in to comment.