Skip to content
239 changes: 229 additions & 10 deletions bootstrap.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,187 @@
* bootstrap script
*/

:-(module(prolog, [
/(true, 0),
/(fail, 0),
/(call, 1),
/(!, 0),
/((','), 2),
/((;), 2),
/((->), 2),
/(catch, 3),
/(throw, 1),

/((=), 2),
/(unify_with_occurs_check, 2),
/((\=), 2),
/(subsumes_term, 2),

/(var, 1),
/(atom, 1),
/(integer, 1),
/(float, 1),
/(atomic, 1),
/(compound, 1),
/(nonvar, 1),
/(number, 1),
/(callable, 1),
/(ground, 1),
/(acyclic_term, 1),

/((@=<), 2),
/((==), 2),
/((\==), 2),
/((@<), 2),
/((@>), 2),
/((@>=), 2),
/(compare, 3),
/(sort, 2),
/(keysort, 2),

/(functor, 3),
/(arg, 3),
/((=..), 2),
/(copy_term, 2),
/(term_variables, 2),

/((is), 2),

/((=:=), 2),
/((=\=), 2),
/((<), 2),
/((=<), 2),
/((>), 2),
/((>=), 2),

/(clause, 2),
/(current_predicate, 1),

/(asserta, 1),
/(assertz, 1),
/(retract, 1),
/(abolish, 1),
/(retractall, 1),

/(findall, 3),
/(bagof, 3),
/(setof, 3),

/(current_input, 1),
/(current_output, 1),
/(set_input, 1),
/(set_output, 1),
/(open, 4),
/(open, 3),
/(close, 2),
/(close, 1),
/(flush_output, 1),
/(flush_output, 0),
/(stream_property, 2),
/(at_end_of_stream, 0),
/(at_end_of_stream, 1),
/(set_stream_position, 2),

/(get_char, 2),
/(get_char, 1),
/(get_code, 1),
/(get_code, 2),
/(peek_char, 2),
/(peek_char, 1),
/(peek_code, 1),
/(peek_code, 2),
/(put_char, 2),
/(put_char, 1),
/(put_code, 1),
/(put_code, 2),
/(nl, 0),
/(nl, 1),

/(get_byte, 2),
/(get_byte, 1),
/(peek_byte, 2),
/(peek_byte, 1),
/(put_byte, 2),
/(put_byte, 1),

/(read_term, 3),
/(read_term, 2),
/(read, 1),
/(read, 2),
/(write_term, 3),
/(write_term, 2),
/(write, 1),
/(write, 2),
/(writeq, 1),
/(writeq, 2),
/(write_canonical, 1),
/(write_canonical, 2),
/(op, 3),
/(current_op, 3),
/(char_conversion, 2),
/(current_char_conversion, 2),

/((\+), 1),
/(once, 1),
/(repeat, 0),
/(call, 2),
/(call, 3),
/(call, 4),
/(call, 5),
/(call, 6),
/(call, 7),
/(call, 8),
/(false, 0),

/(atom_length, 2),
/(atom_concat, 3),
/(sub_atom, 5),
/(atom_chars, 2),
/(atom_codes, 2),
/(char_code, 2),
/(number_chars, 2),
/(number_codes, 2),

/(set_prolog_flag, 2),
/(current_prolog_flag, 2),
/(halt, 0),
/(halt, 1),

/(consult, 1),
/((.), 2),

/(phrase, 2),
/(phrase, 3),
/(expand_term, 2),

/(member, 2),
/(append, 3),
/(length, 2),
/(between, 3),
/(select, 3),
/(succ, 2),
/(maplist, 2),
/(maplist, 3),
/(maplist, 4),
/(maplist, 5),
/(maplist, 6),
/(maplist, 7),
/(maplist, 8),
/(nth0, 3),
/(nth1, 3),
/(call_nth, 2),

/(current_module, 1),
/(predicate_property, 2),
/(current_predicate, 1),
/(use_module, 2),
/(use_module, 1)
])).

% Dependencies

:-(use_module('/prolog/system', all)).

% Operators

:-(op(1200, xfx, [:-, -->])).
Expand All @@ -22,6 +203,22 @@
:-(op(200, xfy, ^)).
:-(op(200, fy, [+, -, \])).

% Meta predicates

:- meta_predicate([
clause(0, ?),
asserta(0),
assertz(0),
retract(0),
abolish(0),
predicate_property(0, ?),
once(0),
\+ 0,
setof(+, 0, -),
bagof(+, 0, -),
findall(+, 0, -)
]).

% Control constructs

true.
Expand Down Expand Up @@ -163,36 +360,48 @@
% Term input/output

read_term(Term, Options) :-
calling_context(M),
current_input(S),
read_term(S, Term, Options).
M:read_term(S, Term, Options).

read(Term) :-
calling_context(M),
current_input(S),
read(S, Term).
M:read(S, Term).

read(Stream, Term) :- read_term(Stream, Term, []).
read(Stream, Term) :-
calling_context(M),
M:read_term(Stream, Term, []).

write_term(Term, Options) :-
calling_context(M),
current_output(S),
write_term(S, Term, Options).
M:write_term(S, Term, Options).

write(Term) :-
calling_context(M),
current_output(S),
write(S, Term).
M:write(S, Term).

write(Stream, Term) :- write_term(Stream, Term, [numbervars(true)]).
write(Stream, Term) :-
calling_context(M),
M:write_term(Stream, Term, [numbervars(true)]).

writeq(Term) :-
calling_context(M),
current_output(S),
writeq(S, Term).
M:writeq(S, Term).

writeq(Stream, Term) :- write_term(Stream, Term, [quoted(true), numbervars(true)]).
writeq(Stream, Term) :-
calling_context(M),
M:write_term(Stream, Term, [quoted(true), numbervars(true)]).

write_canonical(Term) :-
current_output(S),
write_canonical(S, Term).

write_canonical(Stream, Term) :- write_term(Stream, Term, [quoted(true), ignore_ops(true)]).
write_canonical(Stream, Term) :-
write_term(Stream, Term, [quoted(true), ignore_ops(true)]).

% Logic and control

Expand All @@ -212,7 +421,9 @@

% Definite clause grammar

phrase(GRBody, S0) :- phrase(GRBody, S0, []).
phrase(GRBody, S0) :-
calling_context(M),
M:phrase(GRBody, S0, []).

% Prolog prologue

Expand Down Expand Up @@ -257,3 +468,11 @@
maplist(Cont_7, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s]) :-
call(Cont_7, E1, E2, E3, E4, E5, E6, E7),
maplist(Cont_7, E1s, E2s, E3s, E4s, E5s, E6s, E7s).

use_module(File, Imports) :-
calling_context(M),
M:use_module(_, File, Imports).

use_module(File) :-
calling_context(M),
M:use_module(File, all).
15 changes: 15 additions & 0 deletions engine/atom.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
atomComma = NewAtom(",")
atomBar = NewAtom("|")
atomCut = NewAtom("!")
atomColon = NewAtom(":")
atomSemiColon = NewAtom(";")
atomNegation = NewAtom(`\+`)
atomThen = NewAtom("->")
Expand All @@ -58,6 +59,7 @@ var (
atomAccess = NewAtom("access")
atomAcos = NewAtom("acos")
atomAlias = NewAtom("alias")
atomAll = NewAtom("all")
atomAppend = NewAtom("append")
atomAsin = NewAtom("asin")
atomAt = NewAtom("at")
Expand All @@ -68,6 +70,7 @@ var (
atomBinary = NewAtom("binary")
atomBinaryStream = NewAtom("binary_stream")
atomBounded = NewAtom("bounded")
atomBuiltIn = NewAtom("built_in")
atomByte = NewAtom("byte")
atomCall = NewAtom("call")
atomCallable = NewAtom("callable")
Expand All @@ -83,6 +86,7 @@ var (
atomCos = NewAtom("cos")
atomCreate = NewAtom("create")
atomDebug = NewAtom("debug")
atomDefinedIn = NewAtom("defined_in")
atomDiscontiguous = NewAtom("discontiguous")
atomDiv = NewAtom("div")
atomDomainError = NewAtom("domain_error")
Expand All @@ -99,6 +103,7 @@ var (
atomEvaluationError = NewAtom("evaluation_error")
atomExistenceError = NewAtom("existence_error")
atomExp = NewAtom("exp")
atomExported = NewAtom("exported")
atomFX = NewAtom("fx")
atomFY = NewAtom("fy")
atomFail = NewAtom("fail")
Expand All @@ -113,6 +118,7 @@ var (
atomFloatOverflow = NewAtom("float_overflow")
atomFloor = NewAtom("floor")
atomForce = NewAtom("force")
atomImportedFrom = NewAtom("imported_from")
atomIOMode = NewAtom("io_mode")
atomIgnoreOps = NewAtom("ignore_ops")
atomInByte = NewAtom("in_byte")
Expand All @@ -132,11 +138,13 @@ var (
atomMaxDepth = NewAtom("max_depth")
atomMaxInteger = NewAtom("max_integer")
atomMemory = NewAtom("memory")
atomMetaPredicate = NewAtom("meta_predicate")
atomMin = NewAtom("min")
atomMinInteger = NewAtom("min_integer")
atomMod = NewAtom("mod")
atomMode = NewAtom("mode")
atomModify = NewAtom("modify")
atomModule = NewAtom("module")
atomMultifile = NewAtom("multifile")
atomNonEmptyList = NewAtom("non_empty_list")
atomNot = NewAtom("not")
Expand All @@ -145,6 +153,7 @@ var (
atomNumberVars = NewAtom("numbervars")
atomOff = NewAtom("off")
atomOn = NewAtom("on")
atomOp = NewAtom("op")
atomOpen = NewAtom("open")
atomOperator = NewAtom("operator")
atomOperatorPriority = NewAtom("operator_priority")
Expand All @@ -159,9 +168,12 @@ var (
atomPi = NewAtom("pi")
atomPosition = NewAtom("position")
atomPredicateIndicator = NewAtom("predicate_indicator")
atomPrivate = NewAtom("private")
atomPrivateProcedure = NewAtom("private_procedure")
atomProcedure = NewAtom("procedure")
atomProlog = NewAtom("prolog")
atomPrologFlag = NewAtom("prolog_flag")
atomPublic = NewAtom("public")
atomQuoted = NewAtom("quoted")
atomRead = NewAtom("read")
atomReadOption = NewAtom("read_option")
Expand All @@ -177,6 +189,7 @@ var (
atomSmallE = NewAtom("e")
atomSourceSink = NewAtom("source_sink")
atomSqrt = NewAtom("sqrt")
atomStatic = NewAtom("static")
atomStaticProcedure = NewAtom("static_procedure")
atomStream = NewAtom("stream")
atomStreamOption = NewAtom("stream_option")
Expand All @@ -197,6 +210,8 @@ var (
atomUndefined = NewAtom("undefined")
atomUnderflow = NewAtom("underflow")
atomUnknown = NewAtom("unknown")
atomUseModule = NewAtom("use_module")
atomUser = NewAtom("user")
atomUserInput = NewAtom("user_input")
atomUserOutput = NewAtom("user_output")
atomVar = NewAtom("$VAR")
Expand Down
Loading