/*
-Copyright © 2018 Simon Forman
+Copyright © 2018-2019 Simon Forman
This file is part of Thun
% phrase(linker(IR), ASM),
% write_canonical(ASM).
-pass0(Code, Program) --> init, ⦾(Code, Program).
-
-init, [Context] -->
- {empty_assoc(C), empty_assoc(Dictionary),
- put_assoc(dictionary, C, Dictionary, Context)}.
-
⦾([], []) --> [].
⦾([Body, ≡(NameAtom)|Terms], [defi(Name, B, Prev, I, SP, TOS)|Ts]) -->
⦾(ナ, low_half(TEMP0, TOS)) --> get(temp0, TEMP0), get(tos, TOS).
⦾(ヶ, low_half(TOS, SP)) --> get(sp, SP), get(tos, TOS).
+init, [Context] -->
+ {empty_assoc(C), empty_assoc(Dictionary),
+ put_assoc(dictionary, C, Dictionary, Context)}.
+
get(Key, Value) --> state(Context), {get_assoc(Key, Context, Value)}.
set(Key, Value) --> state(ContextIn, ContextOut),
{put_assoc(Key, ContextIn, Value, ContextOut)}.
low_half_word( I, LowHalf) :- LowHalf is I /\ 0xFFFF.
compile_program(Program, Binary) :-
- phrase(pass0(Program, IR), [], _),
+ phrase((init, ⦾(Program, IR)), [], _),
phrase(⟐(IR), ASM),
phrase(linker(ASM), EnumeratedASM),
phrase(asm(EnumeratedASM), Binary).