diff options
author | dos-reis <gdr@axiomatics.org> | 2011-10-27 00:04:28 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2011-10-27 00:04:28 +0000 |
commit | 4d4f05f71ab532ac95570bef18da5098965db723 (patch) | |
tree | b23ae44e7eb26bffb7070edf59e975de07d416b7 /src | |
parent | 903486e44d8cb2fd57e2df9515be4c3e0e4f5369 (diff) | |
download | open-axiom-4d4f05f71ab532ac95570bef18da5098965db723.tar.gz |
Support use of any natural number literal as constant name.
* interp/postpar.boot (postNormalizeName): Remove.
(postLhsOfDefinition): New.
(postDef): Use it.
(postMDef): Likewise.
(postForm): Remove dead code.
(postSignature): Internalize names of exported operators.
* interp/i-intern.boot (mkAtree2): For package call resolution,
use internal names.
* interp/compiler.boot (compAtomWithModemap): Use externalName for
name reported in diagnostic.
(compIntegerLiteral): New.
(compAtom): Use it.
(compElt): Look up modemaps for internal names.
(getModemapList): Likewise.
* interp/g-util.boot (normalizeName): New.
(internalName): Likewise.
(externalName): Likewise.
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 21 | ||||
-rw-r--r-- | src/input/sint.input.pamphlet | 2 | ||||
-rw-r--r-- | src/interp/compiler.boot | 24 | ||||
-rw-r--r-- | src/interp/g-util.boot | 21 | ||||
-rw-r--r-- | src/interp/i-intern.boot | 3 | ||||
-rw-r--r-- | src/interp/postpar.boot | 39 |
6 files changed, 75 insertions, 35 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 7d41139d..ae7612c9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,24 @@ +2011-10-26 Gabriel Dos Reis <gdr@cs.tamu.edu> + + Support use of any natural number literal as constant name. + * interp/postpar.boot (postNormalizeName): Remove. + (postLhsOfDefinition): New. + (postDef): Use it. + (postMDef): Likewise. + (postForm): Remove dead code. + (postSignature): Internalize names of exported operators. + * interp/i-intern.boot (mkAtree2): For package call resolution, + use internal names. + * interp/compiler.boot (compAtomWithModemap): Use externalName for + name reported in diagnostic. + (compIntegerLiteral): New. + (compAtom): Use it. + (compElt): Look up modemaps for internal names. + (getModemapList): Likewise. + * interp/g-util.boot (normalizeName): New. + (internalName): Likewise. + (externalName): Likewise. + 2011-10-25 Gabriel Dos Reis <gdr@cs.tamu.edu> * interp/postpar.boot (postSignature): Tidy. diff --git a/src/input/sint.input.pamphlet b/src/input/sint.input.pamphlet index d51fbb5d..927a4dca 100644 --- a/src/input/sint.input.pamphlet +++ b/src/input/sint.input.pamphlet @@ -17,7 +17,7 @@ min()$SingleInteger max()$SingleInteger a := 1234 :: SingleInteger -b := 124$SingleInteger +b := 124@SingleInteger gcd(a,b) lcm(a,b) mulmod(5,6,13)$SingleInteger diff --git a/src/interp/compiler.boot b/src/interp/compiler.boot index 25ab8c1a..cbae1bbe 100644 --- a/src/interp/compiler.boot +++ b/src/interp/compiler.boot @@ -380,10 +380,8 @@ compAtomWithModemap(x,m,e,mmList) == mmList := [mm for mm in mmList | mm.mmImplementation is ['CONST,:.]] mmList = nil => nil name := -- constant name displayed in diagnostics. - -- FIXME: Remove when the parser is fixed. - x is 'Zero => "0" - x is 'One => "1" - x + externalName x -- FIXME: Remove when the parser is fixed. + -- Try constants with exact type matches, first. Ts := [[['%call,first y],mm.mmTarget,e] for mm in mmList | mm.mmTarget = m and @@ -407,10 +405,17 @@ compAtomWithModemap(x,m,e,mmList) == formatConstantCandidates(op,Ts) == displayAmbiguousSignatures(op,[[T.mode,'constant] for T in Ts]) +++ Attempt to elaborate the integer literal `x' as an exported operator +++ in the type context `m' and assumption environment `e'. +compIntegerLiteral(x,m,e) == + x := internalName x + compAtomWithModemap(x,m,e,get(x,'modemap,e)) + compAtom(x,m,e) == x is "break" => compBreak(x,m,e) x is "iterate" => compIterate(x,m,e) T := ident? x and compAtomWithModemap(x,m,e,get(x,"modemap",e)) => T + T := integer? x and x > 1 and compIntegerLiteral(x,m,e) => T t := ident? x => compSymbol(x,m,e) or return nil listMember?(m,$IOFormDomains) and primitiveType x => [x,m,e] @@ -510,7 +515,6 @@ compForm1(form is [op,:argl],m,e) == [[op,:[([.,.,e]:=outputComp(x,e)).expr for x in argl]],m,e] op is ["elt",domain,op'] => domain="Lisp" => - --op'='QUOTE and null rest argl => [first argl,m,e] [[op',:[([.,.,e]:= compOrCroak(x,$EmptyMode,e)).expr for x in argl]],m,e] domain is ["Foreign",lang] => compForeignPackageCall(lang,op',argl,m,e) (op'="COLLECT") and coerceable(domain,m,e) => @@ -1214,8 +1218,8 @@ compElt(form,m,E) == op := get(anOp,"%Link",E) or anOp coerce([op,opMode,E],m) isDomainForm(aDomain,E) => - E:= addDomain(aDomain,E) - mmList:= getModemapListFromDomain(anOp,0,aDomain,E) + E := addDomain(aDomain,E) + mmList:= getModemapListFromDomain(internalName anOp,0,aDomain,E) modemap:= -- FIXME: do this only for constants. n:=#mmList @@ -1525,10 +1529,10 @@ compExclusiveOr(x,m,e) == compCase: (%Form,%Mode,%Env) -> %Maybe %Triple compCase1: (%Form,%Mode,%Env) -> %Maybe %Triple -getModemapList(op,numOfArgs,e) == - op is ['elt,D,op'] => getModemapListFromDomain(op',numOfArgs,D,e) +getModemapList(op,nargs,e) == + op is ['elt,D,op'] => getModemapListFromDomain(internalName op',nargs,D,e) [mm for - (mm:= [[.,.,:sigl],:.]) in get(op,'modemap,e) | numOfArgs=#sigl] + (mm:= [[.,.,:sigl],:.]) in get(op,'modemap,e) | nargs=#sigl] --Will the jerk who commented out these two functions please NOT do so --again. These functions ARE needed, and case can NOT be done by diff --git a/src/interp/g-util.boot b/src/interp/g-util.boot index de1ad58d..e0c587e7 100644 --- a/src/interp/g-util.boot +++ b/src/interp/g-util.boot @@ -921,6 +921,27 @@ defaultPackageForm? x == makeDefaultPackageName x == makeSymbol strconc(x,'"&") +normalizeName: %Symbol -> %Symbol +normalizeName x == + x = "T" => "T$" -- rename T in spad code to avoid clash with Lisp + x = "^" => "**" -- always use `**' internally for exponentiation + x + +++ Return the internal exported name of a potential operator `x'. +internalName x == + ident? x => normalizeName x + not integer? x or x < 0 => x + x = 0 => 'Zero + x = 1 => 'One + makeSymbol toString x + +++ Return the external exported name of th potential operator `x'. +externalName: %Symbol -> %Symbol +externalName x == + x is 'Zero => "0" + x is 'One => "1" + x + -- gensym utils charDigitVal c == diff --git a/src/interp/i-intern.boot b/src/interp/i-intern.boot index 61533d39..eefc2a55 100644 --- a/src/interp/i-intern.boot +++ b/src/interp/i-intern.boot @@ -174,8 +174,7 @@ mkAtree2(x,op,argl) == op='_$elt => argl is [D,a] => integer? a => - a = 0 => mkAtree1 [['_$elt,D,'Zero]] - a = 1 => mkAtree1 [['_$elt,D,'One]] + a >= 0 => mkAtree1 [['_$elt,D,internalName a]] t := evaluateType unabbrev [D] typeIsASmallInteger(t) and SINTP a => v := mkAtreeNode $immediateDataSymbol diff --git a/src/interp/postpar.boot b/src/interp/postpar.boot index 17a89fe8..1ed5778d 100644 --- a/src/interp/postpar.boot +++ b/src/interp/postpar.boot @@ -162,12 +162,6 @@ postMakeCons l == postTran a ["cons",postTran first l,postMakeCons rest l] -postNormalizeName: %Symbol -> %Symbol -postNormalizeName x == - x = "T" => "T$" -- rename T in spad code to avoid clash with Lisp - x = "^" => "**" -- always use `**' internally for exponentiation - x - postAtom: %Atom -> %ParseForm postAtom x == x is 0 => $Zero @@ -175,7 +169,7 @@ postAtom x == x is "," => "%Comma" ident? x => niladicConstructor? x => [x] - postNormalizeName x + normalizeName x x postBlock: %ParseTree -> %ParseForm @@ -210,6 +204,16 @@ postComma: %ParseTree -> %ParseForm postComma u == post%Comma ["%Comma",:postFlatten(u,",")] +++ post-parse `x' as the left hand side of a definition. +postLhsOfDefinition x == + x is [":",op,t] => [":",postLhsOfDefinition op,:postType t] + x is [op,:args] => + args := postTranList args + if args is [['%Comma,:args']] then + args := args' + [internalName op,:args] + internalName x + postDef: %ParseTree -> %ParseForm postDef t == t isnt [defOp,lhs,rhs] => systemErrorHere ["postDef",t] @@ -220,7 +224,7 @@ postDef t == $docList := [["constructor",:$headerDocumentation],:$docList] $maxSignatureLineNumber := 0 --reset this for next constructor; see recordDocumentation - lhs:= postTran lhs + lhs := postLhsOfDefinition lhs [form,targetType]:= lhs is [":",:.] => rest lhs [lhs,nil] @@ -251,9 +255,8 @@ postMDef: %ParseTree -> %ParseForm postMDef(t) == [.,lhs,rhs] := t lhs := - ident? lhs => postNormalizeName lhs - lhs is [.,:.] => [postNormalizeName x for x in lhs] - lhs + lhs is [.,:.] => [internalName x for x in lhs] + internalName lhs [form,targetType]:= lhs is [":",:.] => lhs.args [lhs,nil] @@ -289,15 +292,8 @@ postForm: %ParseTree -> %ParseForm postForm u == u isnt [op,:argl] => systemErrorHere ["postForm",u] x:= - op isnt [.,:.] => - argl':= postTranList argl - op':= - true=> op - GETL(op,'Led) or GETL(op,'Nud) or op = 'IN => op - numOfArgs:= (argl' is [["%Comma",:l]] => #l; 1) - INTERNL("*",STRINGIMAGE numOfArgs,PNAME op) - [op',:argl'] - u:= postTranList u + op isnt [.,:.] => [op,:postTranList argl] + u := postTranList u if u is [["%Comma",:.],:.] then postError ['" ",:bright u, '"is illegal because tuples cannot be applied!",'"%l", @@ -422,8 +418,7 @@ postSignature: %ParseTree -> %ParseForm postSignature t == t isnt ["%Signature",op,sig] => systemErrorHere ["postSignature",t] op := - op is 0 => 'Zero - op is 1 => 'One + integer? op => internalName op postAtom string? op => stackWarning('"String syntax for %1b in signature is deprecated.",[op]) |