Skip to content

Commit

Permalink
upgrade trealla, add moon phase
Browse files Browse the repository at this point in the history
  • Loading branch information
guregu committed Nov 6, 2022
1 parent 65828b3 commit 65b1e99
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.0.0"
[[component]]
id = "prolog"
description = "PHP: Prolog Home Page"
source = "wapm_packages/guregu/trealla@0.7.2/tpl.wasm"
source = "wapm_packages/guregu/trealla@0.11.9/tpl.wasm"
files = [{ source = "www/", destination = "/"}]
[component.trigger]
route = "/..."
Expand Down
10 changes: 5 additions & 5 deletions wapm.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Lockfile v4
# This file is automatically generated by Wapm.
# It is not intended for manual editing. The schema of this file may change.
[modules."guregu/trealla"."0.7.2".tpl]
[modules."guregu/trealla"."0.11.9".tpl]
name = "tpl"
package_version = "0.7.2"
package_version = "0.11.9"
package_name = "guregu/trealla"
package_path = "guregu/trealla@0.7.2"
resolved = "https://registry-cdn.wapm.io/packages/guregu/trealla/trealla-0.7.2.tar.gz"
package_path = "guregu/trealla@0.11.9"
resolved = "https://registry-cdn.wapm.io/packages/guregu/trealla/trealla-0.11.9.tar.gz"
resolved_source = "registry+tpl"
abi = "wasi"
source = "tpl.wasm"
[commands.tpl]
name = "tpl"
package_name = "guregu/trealla"
package_version = "0.7.2"
package_version = "0.11.9"
module = "tpl"
is_top_level_dependency = true
9 changes: 2 additions & 7 deletions www/lib/php.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
php([]) --> [].

block(php(Head, Text)) --> "<?", seq(Head), whitespace, seq(Text), whitespace, "?>".
% block(php(Head, Text)) --> "<?", seq(Head), whitespace, seq(Text), whitespace, "?>".
block(text(Text)) --> text(Text), { Text \= [] }.

text(['<', X|T]) --> ['<', X], { dif(X, '?') }, text(T).
Expand All @@ -19,13 +18,10 @@
whitespace --> [X], { atom(X), char_type(X, white) }, (whitespace | []).
whitespace --> " " | "\n" | "\t".

% clauses(Cs) --> "%", seq(_), "\n", clauses(Cs). % ignore comments
clauses(Cs) --> "%", seq(_), "\n", clauses(Cs). % ignore comments
clauses([X|Xs]) --> term(X), { X \= end_of_file }, clauses(Xs).
clauses([]) --> term(end_of_file).
term(T) --> call(term_, T).

term_(T, Cs0, Cs) :-
'$read_term_from_chars'(T, [], Cs0, Cs).
term(T) --> read_term_from_chars_(T).

% <?- ... ?> (query)
% <?php ... ?>
Expand Down Expand Up @@ -75,7 +71,6 @@
read_file_to_string(File, Cs, []),
% write(Cs),
once(phrase(php(Program), Cs)),
trace,
% write(Program).
catch(maplist(exec, Program), Error, (
logf("Script error: ~w~nCode: ~w~n", [Error, Program]),
Expand Down
6 changes: 3 additions & 3 deletions www/public_html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ <h2>
<h3>examples</h3>
<nav>
<ul>
<li><a href="/test.html">phpinfo/0</a></li>
<li><a href="/oracle.html">ask the oracle</a></li>
<li><a href="/cgi-bin/hello world.pl">cgi-bin</a></li>
<li>๐Ÿ’ป <a href="/test.html">phpinfo/0</a></li>
<li>๐Ÿ”ฎ <a href="/oracle.html">ask the oracle</a></li>
<li>๐ŸŒ <a href="/moon.html">moon phases</a></li>
</ul>
</nav>

Expand Down
37 changes: 37 additions & 0 deletions www/public_html/moon.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<html>
<style>body { background-color: black; color: white; }</style>
<?
julian(Year, Month, Day, JulianDay) :-
( Month < 3 -> M = 12 ; M = Month ),
JulianDay is (1461 * (Year + 4800 + (M - 14)/12))/4 + (367 * (M - 2 - 12 * ((M - 14)/12)))/12 - (3 * ((Year + 4900 + (M - 14)/12)/100))/4 + Day - 32075.

moon_phase(X) :-
date_time(Y, M, D, _, _, _),
julian(Y, M, D, JD),
Moons is (JD - 2451549.5) / 29.53,
Point is Moons - floor(Moons),
X is Point.

emoji(X, ๐ŸŒ‘) :- X < 0.125.
emoji(X, ๐ŸŒ’) :- X >= 0.125, X < 0.25.
emoji(X, ๐ŸŒ“) :- X >= 0.25, X < 0.375.
emoji(X, ๐ŸŒ”) :- X >= 0.375, X < 0.5.
emoji(X, ๐ŸŒ•) :- X >= 0.5, X < 0.625.
emoji(X, ๐ŸŒ–) :- X >= 0.625, X < 0.75.
emoji(X, ๐ŸŒ—) :- X >= 0.75, X < 0.875.
emoji(X, ๐ŸŒ˜) :- X >= 0.875.
?>

Current moon phase: <br>
<span style="font-size: 72pt;">
<?=Emoji moon_phase(X), once(emoji(X, Emoji)). ?>
</span>

<br><br><hr><br>

<section>
<h2>Source Code</h2>
<pre><?=Source current_file(File), read_file_to_string(File, Source, []). ?></pre>
</section>

</html>

0 comments on commit 65b1e99

Please sign in to comment.