diff options
author | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-02 17:50:51 +0000 |
---|---|---|
committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-02 17:50:51 +0000 |
commit | be26a1ce93e3ed24e57d2e0916f09252536994cb (patch) | |
tree | 296f7fa9ab3e5072158d50ac151d04120ba19d56 /builtins.c | |
parent | 2bfb79be604c68b7684b515f3be3388fecfcf1f4 (diff) |
Begin work on set_prolog_flag/2 and current_prolog_flag/2
Diffstat (limited to 'builtins.c')
-rw-r--r-- | builtins.c | 63 |
1 files changed, 31 insertions, 32 deletions
@@ -34,17 +34,10 @@ BuiltinProto(builtinuniv); BuiltinProto(builtinis); BuiltinProto(builtincatch); BuiltinProto(builtinthrow); +BuiltinProto(builtinsetprologflag); +BuiltinProto(builtincurrentprologflag); int compareterms(Term *, Term *); -Term *instantiationerror(void); -Term *typeerror(Rune *, Term *); -Term *domainerror(Rune *, Term *); -Term *existenceerror(Rune *, Term *); -Term *permissionerror(Rune *, Rune *, Term *); -Term *representationerror(Rune *); -Term *evaluationerror(Rune *); -Term *resourceerror(Rune *); -Term *syntaxerror(Rune *); Builtin findbuiltin(Term *goal) @@ -102,6 +95,10 @@ findbuiltin(Term *goal) return builtincatch; if(Match(L"throw", 1)) return builtinthrow; + if(Match(L"set_prolog_flag", 2)) + return builtinsetprologflag; + if(Match(L"current_prolog_flag", 2)) + return builtincurrentprologflag; return nil; } @@ -554,33 +551,35 @@ builtinthrow(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack return 0; } -/* Helpers to create error terms */ - -Term * -instantiationerror(void) +int +builtincurrentprologflag(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) { - return mkatom(L"instantiation_error"); + USED(database); + USED(goal); + USED(goals); + USED(choicestack); + USED(bindings); + return 0; } -Term * -typeerror(Rune *validtype, Term *culprit) +int +builtinsetprologflag(Term *database, Term *goal, Goal **goals, Choicepoint **choicestack, Binding **bindings) { - Term *valid = mkatom(validtype); - valid->next = copyterm(culprit, nil); - return mkcompound(L"type_error", 2, valid); -} + USED(database); + USED(choicestack); + USED(bindings); + Term *key = goal->children; + Term *value = key->next; -Term * -domainerror(Rune *validdomain, Term *culprit) -{ - Term *valid = mkatom(validdomain); - valid->next = copyterm(culprit, nil); - return mkcompound(L"domain_error", 2, valid); + if(key->tag == VariableTerm || value->tag == VariableTerm) + Throw(instantiationerror()); + + if(key->tag != AtomTerm) + Throw(typeerror(L"atom", key)); + + Term *error = setflag(key->text, value); + if(error) + Throw(error); + return 1; } -Term *existenceerror(Rune *, Term *); -Term *permissionerror(Rune *, Rune *, Term *); -Term *representationerror(Rune *); -Term *evaluationerror(Rune *); -Term *resourceerror(Rune *); -Term *syntaxerror(Rune *);
\ No newline at end of file |