diff options
author | dos-reis <gdr@axiomatics.org> | 2010-05-29 15:07:35 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2010-05-29 15:07:35 +0000 |
commit | acdae7bab43c4dca4ff03be1467b2fc86e7bbe1a (patch) | |
tree | 30ff3d5d44f46dd1521f1ca5ad9278a1e78a8734 /src/interp | |
parent | 5c205afa0596a29c6e8de395d3b2adbd89e02ae8 (diff) | |
download | open-axiom-acdae7bab43c4dca4ff03be1467b2fc86e7bbe1a.tar.gz |
Add more utility functions
Diffstat (limited to 'src/interp')
-rw-r--r-- | src/interp/g-util.boot | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/src/interp/g-util.boot b/src/interp/g-util.boot index 18af0463..7a93d95a 100644 --- a/src/interp/g-util.boot +++ b/src/interp/g-util.boot @@ -46,6 +46,51 @@ module g_-util where expandToVMForm: %Thing -> %Thing +--% VM forms + +++ Make the assumption named `prop' for all symbols +++ on the lis `syms'. +assumeProperty(syms,prop) == + for s in syms repeat + property(s,prop) := true + +assumeProperty('(%and %or),'%nary) + +++ We are about to construct a middle end expression +++ with operator `op, and aguments `form'. Try to +++ simplify the structure of the expression. +flattenVMForm(form,op) == main where + main() == + atom form => form + EQ(form.op,op) => [op,:flatten(form.args,op,nil)] + [flattenVMForm(form.op,op),:flattenVMForm(form.args,op)] + flatten(forms,op,acc) == + forms = nil => accu + x := flattenVMForm(first forms,op) + cons? x and EQ(x.op,op) => flatten(rest forms,op,[:accu,:x.args]) + flatten(rest forms,op,[:accu,x]) + +++ Build a midde end expression with given operator and arguments. +mkVMForm(op,args) == + if op has %nary then + args := flattenVMForm(args,op) + op = '%or => + args := REMOVE('%false,args) + args = nil => '%false + args is [arg] => arg + [op,:args] + op = '%and => + args := REMOVE('%true,args) + args = nil => '%true + args is [arg] => arg + [op,:args] + op = '%not => + [arg] := args + arg = '%false => '%true + arg = '%true => '%false + arg is ['%not,arg'] => arg' + ['%not,:args] + --% --% Opcode expansion to VM codes. --% @@ -568,13 +613,14 @@ getTypeOfSyntax t == bool: %Thing -> %Boolean bool x == null null x - + +++ Return true is the form `x' is a predicate known to always +++ evaluate to true. TruthP x == - --True if x is a predicate that's always true - x is nil => nil - x=true => true + x = nil or x = '%false => false + x = true or x = '%true => true x is ['QUOTE,:.] => true - nil + false --% Record and Union utils. |