1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
|
\documentclass{article}
\usepackage{axiom}
\author{Gabriel Dos~Reis}
\begin{document}
\begin{abstract}
\end{abstract}
\tableofcontents
\eject
\section{domain Syntax}
<<domain SYNTAX Syntax>>=
import UnionType
import SetCategory
import Boolean
import Integer
import DoubleFloat
import Symbol
import SExpression
)abbrev domain SYNTAX Syntax
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Updated: December 05, 2007
++ Description: This domain provides a simple domain, general enough for
++ building complete representation of Spad programs as objects
++ of a term algebra built from ground terms of type integers, foats,
++ symbols, and strings.
++ This domain differs from InputForm in that it represents
++ any entity in a Spad program, not just expressions.
++ Related Constructors: Boolean, Integer, Float, Symbol, String, SExpression.
++ See Also: SExpression, SetCategory.
++ The equality supported by this domain is structural.
++ Fixme: Provide direct support for boolean values, arbritrary
++ precision float point values.
Syntax(): Public == Private where
Public ==> Join(UnionType, SetCategory) with
convert: % -> SExpression
++ convert(s) returns the s-expression representation of a syntax.
convert: SExpression -> %
++ convert(s) converts an s-expression to Syntax. Note, when `s'
++ is not an atom, it is expected that it designates a proper list,
++ e.g. a sequence of cons cells ending with nil.
coerce: Integer -> %
++ coerce(i) injects the integer value `i' into the Syntax domain.
coerce: % -> Integer
++ coerce(s) extracts and integer value from the syntax `s'
autoCoerce: % -> Integer
++ autoCoerce(s) forcibly extracts an integer value from
++ the syntax `s'; no check performed. To be called only
++ at the discretion of the compiler.
coerce: DoubleFloat -> %
++ coerce(f) injects the float value `f' into the Syntax domain
coerce: % -> DoubleFloat
++ coerce(s) extracts a float value from the syntax `s'.
autoCoerce: % -> DoubleFloat
++ autoCoerce(s) forcibly extracts a float value from the syntax `s';
++ no check performed. To be called only at the discretion of
++ the compiler
coerce: Symbol -> %
++ coerce(s) injects the symbol `s' into the Syntax domain.
coerce: % -> Symbol
++ coerce(s) extracts a symbol from the syntax `s'.
autoCoerce: % -> Symbol
++ autoCoerce(s) forcibly extracts a symbo from the Syntax
++ domain `s'; no check performed. To be called only at
++ at the discretion of the compiler.
coerce: String -> %
++ coerce(s) injects the string value `s' into the syntax domain
coerce: % -> String
++ coerce(s) extracts a string value from the syntax `s'.
autoCoerce: % -> String
++ autoCoerce(s) forcibly extracts a string value from
++ the syntax `s'; no check performed. To be called only at
++ the discretion of the compiler.
buildSyntax: (Symbol, List %) -> %
++ buildSyntax(op, [a1, ..., an]) builds a syntax object
++ for op(a1,...,an).
buildSyntax: (%, List %) -> %
++ buildSyntax(op, [a1, ..., an]) builds a syntax object
++ for op(a1,...,an).
nil?: % -> Boolean
++ nil?(s) is true when `s' is a syntax for the constant nil.
getOperator: % -> Union(Integer, DoubleFloat, Symbol, String, %)
++ getOperator(x) returns the operator, or tag, of the syntax `x'.
++ The value returned is itself a syntax if `x' really is an
++ application of a function symbol as opposed to being an
++ atomic ground term.
getOperands: % -> List %
++ getOperands(x) returns the list of operands to the operator in `x'.
compound?: % -> Boolean
++ compound? x is true when `x' is not an atomic syntax.
_case: (%, [|Integer|]) -> Boolean
++ x case Integer is true if `x' really is an Integer
_case: (%, [|DoubleFloat|]) -> Boolean
++ x case DoubleFloat is true if `x' really is a DoubleFloat
_case: (%, [|Symbol|]) -> Boolean
++ x case Symbol is true if `x' really is a Symbol
_case: (%, [|String|]) -> Boolean
++ x case String is true if `x' really is a String
Private ==> SExpression add
rep(x: %): SExpression ==
x pretend SExpression
per(x: SExpression): % ==
x pretend %
x = y ==
EQUAL(x,y)$Lisp @ Boolean
s case Integer ==
integer? rep s
s case DoubleFloat ==
float? rep s
s case String ==
string? rep s
s case Symbol ==
symbol? rep s
convert(x: %): SExpression ==
rep x
convert(x: SExpression): % ==
per x
coerce(i: Integer): % ==
i pretend %
autoCoerce(i: %): Integer == -- used for hard coercion
i : Integer
coerce(i: %): Integer ==
i case Integer => i
userError "invalid conversion target type"
coerce(f: DoubleFloat): % ==
f pretend %
autoCoerce(f: %): DoubleFloat == -- used for hard coercion
f : DoubleFloat
coerce(f: %): DoubleFloat ==
f case DoubleFloat => f
userError "invalid conversion target type"
coerce(s: Symbol): % ==
s pretend %
autoCoerce(s: %): Symbol == -- used for hard coercion
s : Symbol
coerce(s: %): Symbol ==
s case Symbol => s
userError "invalid conversion target type"
coerce(s: String): % ==
s pretend %
autoCoerce(s: %): String == -- used for hard coercion
s : String
coerce(s: %): String ==
s case String => s
userError "invalid conversion target type"
buildSyntax(s: Symbol, l: List %): % ==
-- ??? ideally we should have overloaded operator `per' that convert
-- from list of syntax to syntax. But the compiler is at the
-- moment defective for non-exported overloaded operations.
-- Furthermore, this direct call to `CONS' is currently necessary
-- in order to have the Syntax domain compiled as early as possible
-- in algebra boostrapping process. It should be removed once
-- the bootstrap process is improved.
CONS(s,l)$Lisp @ %
buildSyntax(op: %, l: List %): % ==
CONS(op,l)$Lisp @ %
nil? x ==
null? rep x
getOperator x ==
atom? rep x => userError "atom as operand to getOperator"
op := car rep x
symbol? op => symbol op
integer? op => integer op
float? op => float op
string? op => string op
convert op
compound? x ==
pair? rep x
getOperands x ==
s := rep x
atom? s => []
[per t for t in destruct cdr s]
@
\section{domain ConstructorCall}
<<domain CTORCALL ConstructorCall>>=
import SetCategory
import Symbol
import List Syntax
)abbrev domain CTORCALL ConstructorCall
++ Author: Gabriel Dos Reis
++ Date Created: January 19, 2008
++ Date Last Updated: July 03, 2008
++ Description: This domains represents a syntax object that
++ designates a category, domain, or a package.
++ See Also: Syntax, Domain
ConstructorCall(): Public == Private where
Public == SetCategory with
constructorName: % -> Symbol
++ constructorName c returns the name of the constructor
arguments: % -> List Syntax
++ arguments returns the list of syntax objects for the
++ arguments used to invoke the constructor.
Private == add
Rep == List Syntax
constructorName x ==
(first rep x)::Symbol
arguments x ==
rest rep x
x = y ==
rep x = rep y
coerce x ==
outputDomainConstructor(x)$Lisp
@
\section{The Signature domain}
<<domain SIG Signature>>=
import SetCategory
import CoercibleTo
import List
import Syntax
)abbrev domain SIG Signature
++ Author: Gabriel Dos Reis
++ Date Created: January 10, 2008
++ Date Last Updated: August 30, 2008
++ Description: This is the datatype for operation signatures as
++ used by the compiler and the interpreter. Note that this domain
++ differs from SignatureAst.
++ See also: ConstructorCall, Domain.
Signature(): Public == Private where
Public == SetCategory with
signature: (List Syntax,Syntax) -> %
++ signature(s,t) constructs a Signature object with parameter
++ types indicaded by `s', and return type indicated by `t'.
target: % -> Syntax
++ target(s) returns the target type of the signature `s'.
source: % -> List Syntax
++ source(s) returns the list of parameter types of `s'.
Private == add
Rep == List Syntax
signature(s,t) == per cons(t,s)
target x == first rep x
source x == rest rep x
x = y == rep x = rep y
coerce(x: %): OutputForm ==
rarrow([s::OutputForm for s in source x]::OutputForm,
target(x)::OutputForm)$OutputForm
@
\section{domain ElaboratedExpression}
<<domain ELABEXPR ElaboratedExpression>>=
import Boolean
import Symbol
import ConstructorCall
import List
import SExpression
)abbrev domain ELABEXPR ElaboratedExpression
++ Author: Gabriel Dos Reis
++ Date Created: January 19, 2008
++ Date Last Updated: January 20, 2008
++ Description: This domains an expresion as elaborated by the interpreter.
++ See Also:
ElaboratedExpression(): Public == Private where
Public ==> CoercibleTo OutputForm with
type: % -> ConstructorCall
++ type(e) returns the type of the expression as computed by
++ the interpreter.
constant?: % -> Boolean
++ constant?(e) returns true if `e' is a constant.
getConstant: % -> Union(SExpression,"failed")
++ getConstant(e) retrieves the constant value of `e'e.
variable?: % -> Boolean
++ variable?(e) returns true if `e' is a variable.
getIdentifier: % -> Union(Symbol,"failed")
++ getIdentifier(e) retrieves the name of the variable `e'.
callForm?: % -> Boolean
++ callForm?(e) is true when `e' is a call expression.
getOperator: % -> Union(Symbol, "failed")
++ getOperator(e) retrieves the operator being invoked in `e',
++ when `e' is an expression.
getOperands: % -> Union(List %, "failed")
++ getOperands(e) returns the list of operands in `e', assuming it
++ is a call form.
Private ==> add
isAtomic(x: %): Boolean ==
ATOM(x)$Lisp @ Boolean
type x ==
getMode(x)$Lisp @ ConstructorCall
callForm? x ==
CONSP(x)$Lisp @ Boolean
getOperator x ==
op: SExpression := getUnnameIfCan(x)$Lisp
null? op => "failed"
op pretend Symbol
constant? x ==
isAtomic x and
EQ(getUnnameIfCan(x)$Lisp, _$immediateDataSymbol$Lisp)$Lisp : Boolean
getConstant x ==
constant? x => getValue(x)$Lisp @ SExpression
"failed"
variable? x ==
isAtomic x and not constant? x
getIdentifier x ==
variable? x => symbol (getUnname(x)$Lisp@SExpression)
"failed"
@
\section{SpadAbstractSyntaxCategory}
<<category ASTCAT AbstractSyntaxCategory>>=
import SetCategory
import CoercibleTo Syntax
)abbrev category ASTCAT AbstractSyntaxCategory
++ Author: Gabriel Dos Reis
++ Date Created: July 5, 2008
++ Date Last Modified: July 5, 2008
++ Description: This is the category of Spad abstract syntax trees.
AbstractSyntaxCategory(): Category ==
Join(SetCategory, CoercibleTo Syntax)
add
coerce(x: %): Syntax ==
x pretend Syntax
coerce(x: %): OutputForm ==
x::Syntax::OutputForm
@
\section{The SpadSyntaxCategory category}
<<category SASTCAT SpadSyntaxCategory>>=
)abbrev category SASTCAT SpadSyntaxCategory
++ Author: Gabriel Dos Reis
++ Date Created: July 5, 2008
++ Date Last Modified: September 3, 2008
++ Description: This is the category of Spad syntax objects.
SpadSyntaxCategory(): Category == AbstractSyntaxCategory
add
renderSyntax: Syntax -> OutputForm
renderMapping(x: List Syntax): OutputForm ==
src := [renderSyntax t for t in rest x]::List(OutputForm)::OutputForm
tar := renderSyntax first x
elt('MappingAst::OutputForm,
['source::OutputForm = src, 'target::OutputForm = tar])$OutputForm
renderAttribute(x: Syntax): OutputForm ==
elt('AttributeAst::OutputForm,
['name::OutputForm = renderSyntax x])$OutputForm
renderImport(x: List Syntax): OutputForm ==
ts := [renderSyntax t for t in x]::List(OutputForm)::OutputForm
elt('ImportAst::OutputForm, ['imports::OutputForm = ts])$OutputForm
renderSignature(x: List Syntax): OutputForm ==
n := renderSyntax first x
s := (last(x) : Signature)::OutputForm
elt('SignatureAst::OutputForm,
['name::OutputForm = n, 'signature::OutputForm = s])$OutputForm
renderIf(x: List Syntax): OutputForm ==
c := renderSyntax first x
t := renderSyntax second x
e := renderSyntax third x
elt('IfAst::OutputForm,
['condition::OutputForm = c, 'thenBranch::OutputForm = t,
'elseBranch::OutputForm = e])$OutputForm
renderRepeat(x: List Syntax): OutputForm ==
its := [renderSyntax(x.i) for i in 1..(#x-1)]
::List(OutputForm)::OutputForm
b := renderSyntax last x
elt('RepeatAst::OutputForm,
['iterators::OutputForm = its, 'body::OutputForm = b])$OutputForm
renderWhile(x: List Syntax): OutputForm ==
elt('WhileAst::OutputForm,
['condition::OutputForm = renderSyntax(x : Syntax)])$OutputForm
renderIn(x: List Syntax): OutputForm ==
elt('InAst::OutputForm,
['iterationVar::OutputForm = renderSyntax first x,
'sequence::OutputForm = renderSyntax last x])$OutputForm
renderCollect(x: List Syntax): OutputForm ==
its := [renderSyntax(x.i) for i in 1..(#x-1)]
::List(OutputForm)::OutputForm
elt('CollectAst::OutputForm,
['iterators::OutputForm = its,
'body::OutputForm = renderSyntax last x])$OutputForm
renderConstruct(x: List Syntax): OutputForm ==
es := [renderSyntax t for t in x]::List(OutputForm)::OutputForm
elt('ConstructAst::OutputForm,
['elements::OutputForm = es])$OutputForm
renderControl(tag: Symbol, x: List Syntax): OutputForm ==
elt(tag::OutputForm,
['expression::OutputForm = renderSyntax value x])$OutputForm
renderRestrictedExpr(tag: Symbol, x: List Syntax): OutputForm ==
elt(tag::OutputForm,
['expression::OutputForm = renderSyntax first x,
'target::OutputForm = renderSyntax second x])$OutputForm
renderSegment(x: List Syntax): OutputForm ==
es := [renderSyntax t for t in x]::List(OutputForm)::OutputForm
elt('SegmentAst::OutputForm, ['bounds::OutputForm = es])$OutputForm
renderSequence(x: List Syntax): OutputForm ==
elts := [renderSyntax t for t in x]
elt('SequenceAst::OutputForm,
['body::OutputForm = elts::OutputForm,
'last::OutputForm = last elts])$OutputForm
renderLet(x: List Syntax): OutputForm ==
elt('LetAst::OutputForm,
['lhs::OutputForm = renderSyntax first x,
'rhs::OutputForm = renderSyntax second x])$OutputForm
renderSyntax x ==
compound? x =>
op := getOperator x
args := getOperands x
op = 'Mapping => renderMapping args
op = 'ATTRIBUTE or op = '%Attribute => renderAttribute value args
op = 'IMPORT or op = '%Import => renderImport args
op = 'SIGNATURE or op = '%Signature => renderSignature args
op = 'IF => renderIf args
op = 'REPEAT => renderRepeat args
op = 'WHILE => renderWhile args
op = 'IN => renderIn args
op = 'COLLECT => renderCollect args
op = 'construct => renderConstruct args
op = '_exit => renderControl('ExitAst,args)
op = '_return => renderControl('ReturnAst,args)
op = '_:_: => renderRestrictedExpr('CoerceAst,args)
op = '_pretend => renderRestrictedExpr('PretendAst,args)
op = '_@ => renderRestrictedExpr('RestrictAst,args)
op = 'SEGMENT => renderSegment args
op = 'SEQ => renderSequence args
op = '%LET => renderLet args
x::OutputForm
x::OutputForm
coerce(x: %): OutputForm ==
renderSyntax(x::Syntax)
@
\subsection{The Literal domain}
<<domain LITERAL Literal>>=
)abbrev domain LITERAL Literal
++ Author: Gabriel Dos Reis
++ Date Created: July 5, 2008
++ Date Last Modified: September 1, 2008
++ Description: This domain represents AST for Spad literals.
Literal(T: SetCategory): Public == Private where
Public == Join(SpadSyntaxCategory, CoercibleTo T)
Private == add
Rep == T
coerce(x: %): T == rep x
coerce(x: %): OutputForm == x::T::OutputForm
@
\subsection{The Identifier domain}
<<domain IDENT Identifier>>=
++ Author: Gabriel Dos Reis
++ Date Created: July 5, 2008
++ Date Last Modified: September 1, 2008
++ Description: This domain represents identifer AST.
)abbrev domain IDENT Identifier
Identifier(): Public == Private where
Public == Join(SpadSyntaxCategory, CoercibleTo Symbol)
Private == add
Rep == Symbol
coerce(x: %): Symbol == rep x
coerce(x: %): OutputForm == x::Symbol::OutputForm
@
\subsection{The HeadAst domain}
<<domain HEADAST HeadAst>>=
import AbstractSyntaxCategory
import Symbol
import List Symbol
)abbrev domain HEADAST HeadAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: September 3, 2008
++ Description: This domain represents the header of a definition.
HeadAst(): Public == Private where
Public == SpadSyntaxCategory with
headAst: (Identifier,List Identifier) -> %
++ headAst(f,[x1,..,xn]) constructs a function definition header.
name: % -> Identifier
++ name(h) returns the name of the operation defined defined.
parameters: % -> List Identifier
++ parameters(h) gives the parameters specified in the
++ definition header `h'.
Private == add
Rep == List Identifier
headAst(op,args) == per cons(op,args)
name h == first rep h
parameters h == rest rep h
@
\subsection{The TypeAst domain}
<<domain TYPEAST TypeAst>>=
import AbstractSyntaxCategory
import Syntax
)abbrev domain TYPEAST TypeAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 28, 2008
++ Description: This domain represents a type AST.
TypeAst(): Public == Private where
Public == SpadSyntaxCategory with
coerce: Syntax -> %
++ s::TypeAst injects `s' into the TypeAst domain.
Private == add
Rep == Syntax
coerce(x: Syntax): % == per x
@
\subsection{The ImportAst domain}
<<domain IMPTAST ImportAst>>=
import List
import TypeAst
)abbrev domain IMPTAST ImportAst
)abbrev domain TYPEAST TypeAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 28, 2008
++ Description: This domain represents an `import' of types.
ImportAst(): Public == Private where
Public == SpadSyntaxCategory with
coerce: List TypeAst -> %
++ ts::ImportAst constructs an ImportAst for the list if types `ts'.
imports: % -> List TypeAst
++ imports(x) returns the list of imported types.
Private == add
import Pair
Rep == Pair(Symbol, List TypeAst)
coerce(ts: List TypeAst): % == per pair('import,ts)
imports x == second rep x
@
\subsection{The MappingAst domain}
<<domain MAPPAST MappingAst>>=
)abbrev domain MAPPAST MappingAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 28, 2008
++ Description: This domain represents a mapping type AST. A mapping AST
++ is a syntactic description of a function type, e.g. its result
++ type and the list of its argument types.
MappingAst(): Public == Private where
Public == Join(SpadSyntaxCategory, CoercibleTo TypeAst) with
coerce: Signature -> %
++ sig::MappingAst builds a MappingAst from the Signature `sig'.
mappingAst: (List TypeAst, TypeAst) -> %
++ mappingAst(s,t) builds the mapping AST s -> t
source: % -> List TypeAst
++ source(s) returns the parameter type AST list of `s'.
target: % -> TypeAst
++ target(s) returns the result type AST for `s'.
Private == add
import Pair
Rep == Pair(Symbol,Signature)
coerce(sig: Signature): % == per pair('Mapping,sig)
mappingAst(s,t) ==
per pair('Mapping,cons(t,s) : Signature)
source x == source(second rep x)$Signature : List(TypeAst)
target x == target(second rep x)$Signature : TypeAst
coerce(x: %): TypeAst == x : TypeAst
@
\subsection{The SignatureAst domain}
<<domain SIGAST SignatureAst>>=
)abbrev domain SIGAST SignatureAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 28, 2008
++ Description: This domain represents a signature AST. A signature AST
++ is a description of an exported operation, e.g. its name, result
++ type, and the list of its argument types.
SignatureAst(): Public == Private where
Public == SpadSyntaxCategory with
signatureAst: (Identifier, Signature) -> %
++ signatureAst(n,s,t) builds the signature AST n: s -> t
name: % -> Symbol
++ name(s) returns the name of the signature `s'.
signature: % -> Signature
++ signature(s) returns AST of the declared signature for `s'.
Private == add
import List
Rep == Pair(Symbol, Pair(Symbol,List Signature))
signatureAst(n,sig) ==
per pair('SIGNATURE,pair(n,[sig]))
name x == first second rep x
signature x == value second second rep x
@
\subsection{The AttributeAst domain}
<<domain ATTRAST AttributeAst>>=
)abbrev domain ATTRAST AttributeAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents the syntax of an attribute in
++ a category expression.
AttributeAst(): Public == Private where
Public == SpadSyntaxCategory with
name: % -> Syntax
++ name(a) returns the name of the attribute `a'. Note, this
++ name may be domain name, not just an identifier.
Private == add
Rep == Pair(Symbol,Syntax)
name x == second rep x
@
\subsection{The JoinAst domain}
<<domain JOINAST JoinAst>>=
)abbrev domain JOINAST JoinAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents the join of categories ASTs.
JoinAst(): Public == Private where
Public == Join(SpadSyntaxCategory, CoercibleTo TypeAst) with
coerce: List TypeAst -> %
++ ts::JoinAst construct the AST for a join of the types `ts'.
categories: % -> List TypeAst
++ catehories(x) returns the types in the join `x'.
Private == add
Rep == Pair(Symbol, List TypeAst)
categories x == second rep x
coerce(cats: List TypeAst): % == per pair('Join,cats)
coerce(x: %): TypeAst == x : TypeAst
@
\subsection{The IfAst domain}
<<domain IFAST IfAst>>=
)abbrev domain IFAST IfAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents AST for conditional expressions.
IfAst(): Public == Private where
Public == SpadSyntaxCategory with
condition: % -> Syntax
++ condition(e) returns the condition of the if-expression `e'.
thenBranch: % -> Syntax
++ thenBranch(e) returns the `then-branch' of `e'.
elseBranch: % -> Syntax
++ thenBranch(e) returns the `else-branch' of `e'.
Private == add
Rep == List Syntax
condition x == second rep x
thenBranch x == third rep x
elseBranch x == last rep x
@
\subsection{The RepeatAst domain}
<<domain RPTAST RepeatAst>>=
)abbrev domain RPTAST RepeatAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents the `repeat' iterator syntax.
RepeatAst(): Public == Private where
Public == SpadSyntaxCategory with
iterators: % -> List Syntax
++ iterators(e) returns the list of iterators controlling the loop `e'.
body: % -> Syntax
++ body(e) returns the body of the loop `e'.
Private == add
Rep == List Syntax
iterators x ==
s := rep x
s.(2..(#s - 1))
body x == last rep x
@
\subsection{The WhileAst domain}
<<domain WHILEAST WhileAst>>=
)abbrev domain WHILEAST WhileAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents the `while' iterator syntax.
WhileAst(): Public == Private where
Public == SpadSyntaxCategory with
condition: % -> Syntax
++ condition(i) returns the condition of the while iterator `i'.
Private == add
Rep == Pair(Symbol,Syntax)
condition x == second rep x
@
\subsection{The InAst domain}
<<domain INAST InAst>>=
)abbrev domain INAST InAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents the `in' iterator syntax.
InAst(): Public == Private where
Public == SpadSyntaxCategory with
iterationVar: % -> Symbol
++ iterationVar(i) returns the name of the iterating
++ variable of the `in' iterator 'i'
sequence: % -> Syntax
++ sequence(i) returns the sequence expression being
++ iterated over by `i'.
Private == add
Rep == List Syntax
iterationVar x == (second rep x)::Symbol
sequence x == last rep x
@
\subsection{The CollectAst domain}
<<domain CLLCTAST CollectAst>>=
)abbrev domain CLLCTAST CollectAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents list comprehension syntax.
CollectAst(): Public == Private where
Public == SpadSyntaxCategory with
iterators: % -> List Syntax
++ iterators(e) returns the list of the iterators of
++ the list comprehension `e'.
body: % -> Syntax
++ body(e) return the expression being
++ collected by the list comprehension `e'.
Private == add
Rep == List Syntax
body x == last rep x
iterators x ==
s := rep x
s.(2..(#s -1))
@
\subsection{The ConstructAst domain}
<<domain LSTAST ConstructAst>>=
)abbrev domain LSTAST ConstructAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents `literal sequence' syntax.
ConstructAst(): Public == Private where
Public == SpadSyntaxCategory with
elements: % -> List Syntax
++ elements(e) returns the list of expressions in the
++ `literal' list `e'.
Private == add
import Pair
Rep == Pair(Symbol, List Syntax)
elements x == second rep x
@
\subsection{The ExitAst domain}
<<domain EXITAST ExitAst>>=
)abbrev domain EXITAST ExitAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents exit expressions.
ExitAst(): Public == Private where
Public == SpadSyntaxCategory with
expression: % -> Syntax
++ expression(e) returns the exit expression of `e'.
Private == add
import Pair
Rep == Pair(Symbol,Syntax)
expression x == second rep x
@
\subsection{The ReturnAst domain}
<<domain RETAST ReturnAst>>=
)abbrev domain RETAST ReturnAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents `return' expressions.
ReturnAst(): Public == Private where
Public == SpadSyntaxCategory with
expression: % -> Syntax
++ expression(e) returns the expression returned by `e'.
Private == add
import Pair
Rep == Pair(Symbol,Syntax)
expression x == second rep x
@
\subsection{The SequenceAst domain}
<<domain SEQAST SequenceAst>>=
)abbrev domain SEQAST SequenceAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents a block of expressions.
SequenceAst(): Public == Private where
Public == SpadSyntaxCategory with
body: % -> List Syntax
++ body(e) returns the list of expressions in the sequence
++ of instruction `e'.
last: % -> Syntax
++ last(e) returns the last instruction in `e'.
Private == add
import Pair
Rep == Pair(Symbol,List Syntax)
body x == second rep x
last x == last(second rep x)$List(Syntax)
@
\subsection{The LetAst domain}
<<domain LETAST LetAst>>=
import Syntax
import List
)abbrev domain LETAST LetAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents assignment expressions.
LetAst(): Public == Private where
Public == SpadSyntaxCategory with
lhs: % -> Syntax
++ lhs(e) returns the left hand side of the assignment expression `e'.
rhs: % -> Syntax
++ rhs(e) returns the right hand side of the assignment expression `e'.
Private == add
Rep == List Syntax
lhs x == second rep x
rhs x == third rep x
@
\subsection{The PretendAst domain}
<<domain PRTDAST PretendAst>>=
)abbrev domain PRTDAST PretendAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents `pretend' expressions.
PretendAst(): Public == Private where
Public == SpadSyntaxCategory with
expression: % -> Syntax
++ expression(e) returns the expression being converted.
target: % -> TypeAst
++ target(e) returns the target type of the conversion..
Private == add
Rep == List Syntax
expression x == second rep x
target x == (third rep x) : TypeAst
@
\subsection{The CoerceAst domain}
<<domain CRCAST CoercedAst>>=
)abbrev domain CRCAST CoerceAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents `coerce' expressions.
CoerceAst(): Public == Private where
Public == SpadSyntaxCategory with
expression: % -> Syntax
++ expression(e) returns the expression being converted.
target: % -> TypeAst
++ target(e) returns the target type of the conversion..
Private == add
Rep == List Syntax
expression x == second rep x
target x == (third rep x) : TypeAst
@
\subsection{The RestrictAst domain}
<<domain RSTRCAST RestrictAst>>=
)abbrev domain RSTRCAST RestrictAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents `restrict' expressions.
RestrictAst(): Public == Private where
Public == SpadSyntaxCategory with
expression: % -> Syntax
++ expression(e) returns the expression being converted.
target: % -> TypeAst
++ target(e) returns the target type of the conversion..
Private == add
Rep == List Syntax
expression x == second rep x
target x == (third rep x) : TypeAst
@
\subsection{The CallAst domain}
<<domain CALLAST CallAst>>=
import Syntax
import List
)abbrev domain CALLAST CallAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents calls.
CallAst(): Public == Private where
Public == SpadSyntaxCategory with
operator: % -> Syntax
++ operation(e) returns the operation being called in `e'.
operands: % -> List Syntax
++ arguments(e) returns the argument list used in the call `e'.
Private == add
Rep == List Syntax
operator x == first rep x
operands x == rest rep x
@
\subsection{The SegmentAst domain}
<<domain SEGAST SegmentAst>>=
)abbrev domain SEGAST SegmentAst
++ Author: Gabriel Dos Reis
++ Date Created: November 10, 2007
++ Date Last Modified: August 30, 2008
++ Description: This domain represents segement expressions.
SegmentAst(): Public == Private where
Public == SpadSyntaxCategory with
bounds: % -> List Syntax
Private == add
Rep == List Syntax
bounds x == rest rep x
@
\section{License}
<<license>>=
--Copyright (C) 2007-2008, Gabriel Dos Reis.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
-- - Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
--
-- - Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in
-- the documentation and/or other materials provided with the
-- distribution.
--
-- - Neither the name of The Numerical Algorithms Group Ltd. nor the
-- names of its contributors may be used to endorse or promote products
-- derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@
<<*>>=
<<license>>
<<domain SYNTAX Syntax>>
<<domain CTORCALL ConstructorCall>>
<<domain ELABEXPR ElaboratedExpression>>
<<category ASTCAT AbstractSyntaxCategory>>
<<category SASTCAT SpadSyntaxCategory>>
<<domain LITERAL Literal>>
<<domain HEADAST HeadAst>>
<<domain TYPEAST TypeAst>>
<<domain ATTRAST AttributeAst>>
<<domain IMPTAST ImportAst>>
<<domain MAPPAST MappingAst>>
<<domain SIGAST SignatureAst>>
<<domain JOINAST JoinAst>>
<<domain IFAST IfAst>>
<<domain RPTAST RepeatAst>>
<<domain WHILEAST WhileAst>>
<<domain INAST InAst>>
<<domain CLLCTAST CollectAst>>
<<domain LSTAST ConstructAst>>
<<domain EXITAST ExitAst>>
<<domain RETAST ReturnAst>>
<<domain SEGAST SegmentAst>>
<<domain SEQAST SequenceAst>>
<<domain PRTDAST PretendAst>>
<<domain CRCAST CoercedAst>>
<<domain RSTRCAST RestrictAst>>
<<domain LETAST LetAst>>
@
\end{document}
|