From 4e70fdd67b48fcb81843cf99c8657746efe95fef Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Thu, 2 May 2019 08:38:15 -0700 Subject: [PATCH] Minor cleanup. Remove the pass0//2 DCG rule and unfold it in compile_program//2 rule. Move init//0 to be with the rest of the state DCG code. --- thun/compiler.pl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/thun/compiler.pl b/thun/compiler.pl index 87be186..3e052f5 100644 --- a/thun/compiler.pl +++ b/thun/compiler.pl @@ -1,6 +1,6 @@ /* -Copyright © 2018 Simon Forman +Copyright © 2018-2019 Simon Forman This file is part of Thun @@ -43,12 +43,6 @@ write_binary('joy_asm.bin', Binary). % 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]) --> @@ -142,6 +136,10 @@ init, [Context] --> ⦾(ナ, 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)}. @@ -284,7 +282,7 @@ high_half_word(I, HighHalf) :- HighHalf is I >> 16 /\ 0xFFFF. 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).