3 ms·
I took an architecture course with Dr Kogge (author of the book the SECD machine is described in) and chose Erlang for building an SECD machine emulator, becaus
by philsnow 3y ago
I took an architecture course with Dr Kogge (author of the book the SECD machine is described in) and chose Erlang for building an SECD machine emulator, because Erlang's pattern-matching syntax for defining functions perfectly matched (if you'll excuse the pun) with "axiomatic semantics".
edit: correction, the SECD emulator was for another class, I had taken Dr Kogge's architecture class beforehand
for instance, the basic 0-ary operations are:
eval({S,E,[],D}) -> {S,E,[],D};
% Stack Operations:
%
% NIL s e (NIL.c) d -> (nil.s) e c d
% LDC s e (LDC x.c) d -> (x.s) e c d
% LD s e (LD (i.j).c) d -> (locate((i.j),e).s) e c d
eval({S,E,[nil | C],D}) ->
debug(enter,eval_nil,[{S,E,[nil|C],D}]),
Z = eval({[ [] | S ],E,C,D}),
debug(exit,[],Z), Z;
eval({S,E,[ldc, X | C],D}) ->
debug(enter,eval_ldc,[{S,E,[ldc,X|C],D}]),
Z = eval({ [X | S],E,C,D}),
debug(exit,[],Z), Z;
eval({S,E,[ld, [I|J] | C],D}) ->
debug(enter,eval_ld,[{S,E,[ld,[I|J]|C],D}]),
Z = eval({[locate([I|J],E)|S],E,C,D}),
debug(exit,[],Z), Z;