Skip to content

Commit 49f95f1

Browse files
committed
Refactor memory allocation in paper.tex.
1 parent b2b5ba2 commit 49f95f1

File tree

3 files changed

+70
-57
lines changed

3 files changed

+70
-57
lines changed

DEPENDS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ hard lastpage
3030
hard lh
3131
hard libertine
3232
hard makecell
33+
hard microtype
3334
hard ncctools
3435
hard paralist
3536
hard preprint

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ installed.
2323
Once compiled and packaged, upload zip archive to [arXiv].
2424

2525
[PDF]: https://github.com/objectionary/reducing-programs-to-objects/blob/gh-pages/paper.pdf
26-
[arXiv]: https://arxiv.org/abs/2112.11988
26+
[arXiv]: https://arxiv.org/abs/2112.11988

paper.tex

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,20 @@ \subsubsection{Backward Jump}
102102

103103
\begin{ffcode}
104104
[] > f
105-
memory 0 > i
106-
seq > @
107-
i.write 1
108-
goto
109-
[g]
110-
seq > @
111-
i.write (i.plus 1)
112-
if.
113-
i.lt 10
114-
g.backward
115-
TRUE
116-
QQ.io.stdout "Finished!"
105+
malloc.of > @
106+
0
107+
[i] >>
108+
seq * > @
109+
i.write 1
110+
go.to
111+
[g] >>
112+
seq * > @
113+
i.write (i.plus 1)
114+
if.
115+
i.lt 10
116+
g.backward
117+
true
118+
QQ.io.stdout "Finished!"
117119
\end{ffcode}
118120

119121
Here, the one-argument abstract atom \ff{goto} is being copied with a one-argument abstract anonymous object, which is the sequence of objects incrementing \ff{i} and then comparing it with the number ten. If the condition is true, \ff{g.backward} is called, which leads to a backward jump and re-iteration of \ff{goto}.
@@ -136,21 +138,24 @@ \subsubsection{Forward Jump}
136138

137139
\begin{ffcode}
138140
[x] > f
139-
memory 0 > r
140-
seq > @
141-
r.write 0
142-
goto
143-
[g]
144-
seq > @
145-
if.
146-
x.eq 0
147-
g.forward TRUE
148-
TRUE
149-
r.write (42.div x)
150-
r
141+
malloc.of > @
142+
0
143+
[r] >>
144+
seq * > @
145+
r.write 0
146+
go.to
147+
[g] >>
148+
seq * > @
149+
if.
150+
x.eq 0
151+
g.forward true
152+
true
153+
r.write (42.div x)
154+
r
151155
\end{ffcode}
152156

153-
Here, the same abstract atom \ff{goto} is copied with an abstract one-argument object, which is a sequence of objects. When the condition is true, a forward jump is performed by \ff{g.forward} atom.
157+
Here, the same abstract atom \ff{goto} is copied with an abstract one-argument object, which is a sequence of objects.
158+
When the condition is true, a forward jump is performed by \ff{g.forward} atom.
154159

155160
Similarly, the atom \ff{goto} may be used to simulate other conditional jump statements, like \ff{break}, \ff{continue}, or \ff{return} in the middle of a function body (see \cref{sec:procedures}).
156161

@@ -170,7 +175,8 @@ \subsubsection{Complex Case}
170175
}
171176
\end{ffcode}
172177

173-
In order to translate this code to \eolang{}, it has to be refactored as \cref{fig:goto} demonstrates. The function \ff{f()} is copied twice and each copy has its own execution flow implemented.
178+
In order to translate this code to \eolang{}, it has to be refactored as \cref{fig:goto} demonstrates.
179+
The function \ff{f()} is copied twice and each copy has its own execution flow implemented.
174180

175181
\begin{figure}
176182
\includegraphics[width=0.9\columnwidth]{goto-pic}
@@ -194,7 +200,7 @@ \subsubsection{Complex Case}
194200
}
195201
\end{ffcode}
196202

197-
Then, the translation to \eolang{} is trivial, with the use of the \ff{goto} object.
203+
Then, the translation to \eolang{} is trivial, with the use of the \ff{go.to} object.
198204

199205
In more complex cases, a program may first be restructured to replace \ff{goto} statements with loops and branching, as suggested by~\citet{williams1985restructuring,pan1996formal,erosa1994taming,ceccato2008goto}.
200206

@@ -211,17 +217,17 @@ \subsubsection{Multiple Returns}
211217
}
212218
\end{ffcode}
213219

214-
This can be mapped to the following \eolang{} code using \ff{goto} object:
220+
This can be mapped to the following \eolang{} code using \ff{go.to} object:
215221

216222
\begin{ffcode}
217223
[x] > abs
218-
goto > @
219-
[g]
220-
seq > @
224+
go.to > @
225+
[g] >>
226+
seq * > @
221227
if.
222228
x.gt 0
223229
g.forward x
224-
TRUE
230+
true
225231
g.forward
226232
-1.times x
227233
\end{ffcode}
@@ -231,11 +237,13 @@ \subsubsection{Multiple Returns}
231237
\subsection{Pointers}
232238
\label{sec:pointers}
233239

234-
A pointer is an object in many programming languages that stores a memory address. Pointers may point to data memory or program memory.
240+
A pointer is an object in many programming languages that stores a memory address.
241+
Pointers may point to data memory or program memory.
235242

236243
\subsubsection{Pointers to Data}
237244

238-
This is an example of C code, where the pointer \ff{p} is first incremented by seven times \ff{sizeof(book)} (which is equal to 108) and then de-referenced to become a struct \ff{book} mapped to memory. Then, the \ff{title} part of the struct is filled with a string and the \ff{price} part is returned as a result of the function \ff{f}:
245+
This is an example of C code, where the pointer \ff{p} is first incremented by seven times \ff{sizeof(book)} (which is equal to 108) and then de-referenced to become a struct \ff{book} mapped to memory.
246+
Then, the \ff{title} part of the struct is filled with a string and the \ff{price} part is returned as a result of the function \ff{f}:
239247

240248
\begin{ffcode}
241249
#include "string.h"
@@ -266,7 +274,7 @@ \subsubsection{Pointers to Data}
266274
0
267275
108
268276
[p] > f
269-
seq > @
277+
seq * > @
270278
book (p.add 7) > b
271279
b.title.write
272280
("Object Thinking").as-bytes
@@ -299,7 +307,7 @@ \subsubsection{Pointers to Code}
299307
x.plus y > @
300308
[] > f
301309
cage 0 > p
302-
seq > @
310+
seq * > @
303311
p.write
304312
[x y]
305313
foo x y > @
@@ -338,7 +346,7 @@ \subsubsection{Variables in Stack}
338346
8
339347
[b] (b.as-int > @)
340348
[] > f
341-
seq > @
349+
seq * > @
342350
malloc. > stack
343351
heap 32 > h
344352
16
@@ -369,13 +377,13 @@ \subsection{Procedures}
369377

370378
\begin{ffcode}
371379
[a b] > max
372-
goto > @
373-
[g]
374-
seq > @
380+
go.to > @
381+
[g] >>
382+
seq * > @
375383
if.
376384
a.gt b
377385
g.forward a
378-
TRUE
386+
true
379387
b
380388
\end{ffcode}
381389

@@ -401,7 +409,7 @@ \subsubsection{Impure Functions}
401409
\begin{ffcode}
402410
memory 42 > a
403411
[x] > inc!
404-
seq > @
412+
seq * > @
405413
x.write
406414
x.plus 1
407415
inc
@@ -480,7 +488,7 @@ \subsection{Destructors}
480488
QQ.io.stdout "Dead" > @
481489
[] > main
482490
foo > f
483-
seq > @
491+
seq * > @
484492
f.constructor
485493
f.destructor
486494
\end{ffcode}
@@ -602,7 +610,7 @@ \subsection{Anonymous Functions}
602610
if. > @
603611
t.starts-with "#"
604612
b t
605-
TRUE
613+
true
606614
scan
607615
array
608616
[x]
@@ -614,7 +622,8 @@ \subsection{Anonymous Functions}
614622
\subsection{Generators}
615623
\label{sec:generators}
616624

617-
A generator is a routine that can be used to control the iteration behavior of a loop. For example, this PHP program will print first ten Fibonacci numbers:
625+
A generator is a routine that can be used to control the iteration behavior of a loop.
626+
For example, this PHP program will print first ten Fibonacci numbers:
618627

619628
\begin{ffcode}
620629
function fibonacci(int $limit):generator {
@@ -637,18 +646,18 @@ \subsection{Generators}
637646
memory 0 > a
638647
memory 0 > b
639648
memory 0 > i
640-
seq > @
649+
seq * > @
641650
a.write 1
642651
b.write 1
643652
f 0
644653
while.
645654
seq (i.write (i.plus 1)) (i.lt limit)
646655
[idx]
647-
seq > @
656+
seq * > @
648657
b.write (a.plus b)
649658
a.write (b.minus a)
650659
f (b.minus a)
651-
TRUE
660+
true
652661
fibonacci > @
653662
10
654663
[n]
@@ -718,7 +727,8 @@ \subsection{Types and Type Casting}
718727
\subsection{Reflection}
719728
\label{sec:reflection}
720729
721-
Reflection is the ability of a process to examine, introspect, and modify its own structure and behavior. In the following Python example the method \ff{hello} of an instance of class \ff{Foo} is not called directly on the object, but is first retrieved through reflection functions \ff{globals} and \ff{getattr}, and then executed:
730+
Reflection is the ability of a process to examine, introspect, and modify its own structure and behavior.
731+
In the following Python example the method \ff{hello} of an instance of class \ff{Foo} is not called directly on the object, but is first retrieved through reflection functions \ff{globals} and \ff{getattr}, and then executed:
722732
723733
\begin{ffcode}
724734
def Foo():
@@ -732,7 +742,8 @@ \subsection{Reflection}
732742
733743
\subsubsection{Monkey Patching}
734744
735-
Monkey patching is making changes to a module or a class while the program is running. This JavaScript program adds a new method \ff{print} to the object \ff{b} after the object has already been instantiated:
745+
Monkey patching is making changes to a module or a class while the program is running.
746+
This JavaScript program adds a new method \ff{print} to the object \ff{b} after the object has already been instantiated:
736747
737748
\begin{ffcode}
738749
function Book(t) { this.title = t; }
@@ -749,7 +760,7 @@ \subsubsection{Monkey Patching}
749760
[] > app
750761
cage 0 > b
751762
b' > copy
752-
seq > @
763+
seq * > @
753764
b.write
754765
[] > book
755766
[t] > new
@@ -759,7 +770,7 @@ \subsubsection{Monkey Patching}
759770
b.write
760771
[] > book
761772
[t] > new
762-
seq > @
773+
seq * > @
763774
[]
764775
copy > @
765776
[] > print
@@ -896,7 +907,7 @@ \subsubsection{Multiple Inheritance}
896907
dog > d
897908
friend > f
898909
[] > listen
899-
seq > @
910+
seq * > @
900911
d.bark
901912
QQ.io.stdout "listen!"
902913
\end{ffcode}
@@ -1027,7 +1038,7 @@ \subsection{Annotations}
10271038
10281039
\begin{ffcode}
10291040
[] > book
1030-
ship TRUE > a1
1041+
ship true > a1
10311042
[] > new
10321043
[] > @
10331044
[] > song
@@ -1040,7 +1051,7 @@ \subsection{Annotations}
10401051
if. > @
10411052
i.a1.value
10421053
# Mark the cart shippable
1043-
TRUE
1054+
true
10441055
FALSE
10451056
\end{ffcode}
10461057
@@ -1070,7 +1081,8 @@ \section{Traceability}
10701081
10711082
\section{Conclusion}
10721083
1073-
We demonstrated how some language features often present in high-level object-oriented languages, such as Java or C++, may be expressed using objects. We used \eolang{} as a destination programming language because of its minimalistic semantics: it doesn't have any language features aside from objects and their composition and decoration mechanisms.
1084+
We demonstrated how some language features often present in high-level object-oriented languages, such as Java or C++, may be expressed using objects.
1085+
We used \eolang{} as a destination programming language because of its minimalistic semantics: it doesn't have any language features aside from objects and their composition and decoration mechanisms.
10741086
10751087
\raggedright
10761088
\bibliographystyle{ACM-Reference-Format}

0 commit comments

Comments
 (0)