git @ Cat's Eye Technologies SixtyPical / 612ae58
Add some tests, fix some bugs, show that one bug remains. Chris Pressey 3 years ago
2 changed file(s) with 83 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
5050 if self.scanner.consume('define'):
5151 name = self.scanner.token
5252 self.scanner.scan()
53 routine = self.routine(name)
5354 else:
5455 routine = self.legacy_routine()
5556 name = routine.name
6061 self.scanner.check_type('EOF')
6162
6263 # now backpatch the executable types.
64 #for type_name, type_ in self.typedefs.iteritems():
65 # type_.backpatch_constraint_labels(lambda w: self.lookup(w))
6366 for defn in defns:
6467 defn.location.type.backpatch_constraint_labels(lambda w: self.lookup(w))
6568 for routine in routines:
191194 location=location
192195 )
193196
194 def routine(self):
195 name = self.scanner.token
196 self.scanner.scan()
197 def routine(self, name):
197198 type_ = self.defn_type()
198199 # TODO assert that it's a routine
199200 if self.scanner.consume('@'):
19401940 | }
19411941 = ok
19421942
1943 ### Vector tables ###
1943 ### vector tables ###
19441944
19451945 A vector can be copied into a vector table.
19461946
20362036 | call many + x
20372037 | }
20382038 ? ValueError
2039
2040 ### typedef ###
2041
2042 A typedef is a more-readable alias for a type. "Alias" means
2043 that types have structural equivalence, not name equivalence.
2044
2045 | typedef routine
2046 | inputs x
2047 | outputs x
2048 | trashes z, n
2049 | routine_type
2050 |
2051 | vector routine_type vec
2052 |
2053 | routine foo
2054 | inputs x
2055 | outputs x
2056 | trashes z, n
2057 | {
2058 | inc x
2059 | }
2060 |
2061 | routine main
2062 | outputs vec
2063 | trashes a, z, n
2064 | {
2065 | copy foo, vec
2066 | }
2067 = ok
2068
2069 Routines can be defined in a new style.
2070
2071 | typedef routine
2072 | inputs x
2073 | outputs x
2074 | trashes z, n
2075 | routine_type
2076 |
2077 | vector routine_type vec
2078 |
2079 | define foo routine
2080 | inputs x
2081 | outputs x
2082 | trashes z, n
2083 | {
2084 | inc x
2085 | }
2086 |
2087 | routine main
2088 | outputs vec
2089 | trashes a, z, n
2090 | {
2091 | copy foo, vec
2092 | }
2093 = ok
2094
2095 The new style routine definitions support typedefs.
2096
2097 | typedef routine
2098 | inputs x
2099 | outputs x
2100 | trashes z, n
2101 | routine_type
2102 |
2103 | vector routine_type vec
2104 |
2105 | define foo routine_type
2106 | {
2107 | inc x
2108 | }
2109 |
2110 | routine main
2111 | outputs vec
2112 | trashes a, z, n
2113 | {
2114 | copy foo, vec
2115 | }
2116 = ok