Commits

ZyX_I committed b922375

@/fwc: Moved list and tuple check/pipes creation in a separate functions, added type propagation (using check|pipe specification inside a tuple check will use check, not pipe, no matter what is self.type set to)

Comments (0)

Files changed (3)

plugin/frawor/fwc/compiler.vim

         return '@@@'.s:F.substostr(get(a:000, 1, self.subs))
     endif
 endfunction
+"▶1 addtuple       :: tupledesc, idx, defaultArgType + self → self + self
+function s:constructor.addtuple(tuple, idx, default)
+    let i=0
+    for arg in a:tuple[1]
+        call add(self.subs, i)
+        call self.compilearg(arg, a:idx.'.'.i, a:default)
+        call remove(self.subs, -1)
+        let i+=1
+    endfor
+    return self
+endfunction
+"▶1 addlist        :: listdesc, idx, defaultArgType + self → self + self
+function s:constructor.addlist(list, idx, default)
+    let conid=printf('%X', len(self.stack))
+    let largstr='@$@larg'.conid
+    let istr='@$@i'.conid
+    call self.add('let '.largstr.'=len('.self.argstr().')',
+                \ 'let '.istr.'=0',
+                \ 'while '.istr.'<'.largstr)
+                \.deeper()
+    call add(self.subs, [istr])
+    call self.compilearg(a:list[1], a:idx.'.list', a:default)
+    call self.add('let '.istr.'+=1')
+    call remove(self.subs, -1)
+    call self.up().close()
+endfunction
 "▶1 compilemsg     :: msgcontext, _ + self → self + self
 function s:constructor.compilemsg(msg, idx)
     let msg=[a:msg[1]]
             call self.nextthrow('len('.curargstr.')!='.len(desc[1]),
                         \       'invlstlen', a:idx, '@#@', len(desc[1]),
                         \                    'len('.curargstr.')').close()
-            let i=0
-            for arg in desc[1]
-                call add(self.subs, i)
-                call self.compilearg(arg, a:idx.'.'.i)
-                call remove(self.subs, -1)
-                let i+=1
-            endfor
+                        \.addtuple(desc, a:idx, 'pipe')
         "▶3 `list'
         elseif desc[0] is 'list'
-            let conid=printf('%X', len(self.stack))
-            let largstr='@$@larg'.conid
-            let istr='@$@i'.conid
-            call self.add('let '.largstr.'=len('.curargstr.')',
-                        \ 'let '.istr.'=0',
-                        \ 'while '.istr.'<'.largstr)
-                        \.deeper()
-            call add(self.subs, [istr])
-            call self.compilearg(desc[1], a:idx)
-            call self.add('let '.istr.'+=1')
-            call remove(self.subs, -1)
-            call self.up().close()
+            call self.addlist(desc, a:idx, 'pipe')
         "▶3 `dict'
         elseif desc[0] is 'dict'
             " TODO
             "▶3 `tuple'
             elseif desc[0] is 'tuple'
                 call self.addtypecond([type([])], idx)
-                call self.nextthrow('len('.curargstr.')!='.len(desc[1]),
-                            \       'invlstlen', idx, '@#@', len(desc[1]),
-                            \                    'len('.curargstr.')')
-                let i=0
-                for arg in desc[1]
-                    call add(self.subs,  i)
-                    call self.compilearg(arg, idx.'.'.i)
-                    call remove(self.subs, -1)
-                    let i+=1
-                endfor
+                            \.nextthrow('len('.curargstr.')!='.len(desc[1]),
+                            \           'invlstlen', idx, '@#@', len(desc[1]),
+                            \                        'len('.curargstr.')')
+                            \.addtuple(desc, idx, 'check')
             "▶3 `list'
             elseif desc[0] is 'list'
                 call self.addtypecond([type([])], idx).close()
                 let addedcond=0
-                let conid=printf('%X', len(self.stack))
-                let largstr='@$@larg'.conid
-                let istr='@$@i'.conid
-                call self.add('let '.largstr.'=len('.curargstr.')',
-                            \ 'let '.istr.'=0',
-                            \ 'while '.istr.'<'.largstr)
-                            \.deeper()
-                call add(self.subs, [istr])
-                call self.compilearg(desc[1], idx)
-                call self.add('let '.istr.'+=1')
-                call remove(self.subs, -1)
-                call self.up().close()
+                call self.addlist(desc, idx, 'check')
             "▶3 `dict'
             elseif desc[0] is 'dict'
                 " TODO
 plugin/frawor/fwc/compiler:nreg
 plugin/frawor/fwc/compiler:invlstlen
 plugin/frawor/fwc/compiler:typefail
+plugin/frawor/fwc/compiler:nbool
 ::: Section <Checks/Built-in checks/range>
 plugin/frawor/fwc/compiler:typefail
 plugin/frawor/fwc/compiler:nrange

test/fwctests.dat

 ['tuple isreg, isreg',        'check'], [['abc', '\(']],   0
 ['tuple isreg, isreg',        'check'], [['abc']],         0
 ['tuple isreg, isreg',        'check'], ['abc'],           0
+['tuple bool, bool, bool',    'check'], [[0, 1, 0]],       1
+['?tuple bool, bool, bool',  'filter'], [[0, 1, ""]],      0
 #▶3 range
 :let s:n1=-1
 :let s:n2=1
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.