Commits

ZyX_I committed 98b3fa8

@/fwc/compiler: Moved some functions into @/fwc/constructor

  • Participants
  • Parent commits c796586

Comments (0)

Files changed (8)

File plugin/frawor/fwc/compiler.vim

             \exists('g:frawor__donotload')
     finish
 endif
-execute frawor#Setup('0.0', {'@/fwc/parser': '0.0',
-            \                '@/os'        : '0.0'}, 1)
-let s:constructor={}
+execute frawor#Setup('0.0', {'@/fwc/parser'     : '0.0',
+            \                '@/os'             : '0.0',
+            \                '@/fwc/constructor': '0.0'}, 1)
+let s:compiler={}
 "▶1 Messages
 let s:_messages={
             \   'notypes': 'Expected at least one type specification',
         endif
     endif
 endfunction
-"▶1 add            :: item, ... + self → self + self
-function s:constructor.add(...)
-    let self.l+=a:000
-    return self
-endfunction
-"▶1 up             :: &self
-function s:constructor.up()
-    call remove(self.stack, -1)
-    let self.l=self.stack[-1]
-    return self
-endfunction
-"▶1 deeper         :: ()[, conelement1[, ...]] + self → self + self
-function s:constructor.deeper(...)
-    if type(get(self.l, -1))==type([])
-        let self.l[-1]+=a:000
-        call add(self.stack, self.l[-1])
-    else
-        let con=copy(a:000)
-        call self.add(con)
-        call add(self.stack, con)
-    endif
-    let self.l=self.stack[-1]
-    return self
-endfunction
-"▶1 close          :: &self
-let s:cmdends={
-            \    'if': 'endif',
-            \'elseif': 'endif',
-            \'else'  : 'endif',
-            \'try'    : 'endtry',
-            \'catch'  : 'endtry',
-            \'finally': 'endtry',
-            \'function': 'endfunction',
-            \     'for': 'endfor',
-            \   'while': 'endwhile',
-            \'augroup': 'augroup END',
-            \  'redir': 'redir END',
-        \}
-function s:constructor.close()
-    let command=matchstr(self.l[-2], '\S\+')
-    if has_key(s:cmdends, command)
-        return self.add(s:cmdends[command])
-    else
-        return self
-    endif
-endfunction
-"▶1 nextcond       :: [condition] + self → self + self
-function s:constructor.nextcond(...)
-    if !empty(self.l)
-        if type(self.l[-1])==type([])
-            let prevline=self.l[-2]
-        else
-            let prevline=self.l[-1]
-        endif
-        let command=prevline[:(stridx(prevline, ' ')-1)]
-    endif
-    if exists('command') && (command is 'if' || command is 'elseif')
-        if a:0
-            return self.add('elseif '.a:1).deeper()
-        else
-            return self.add('else').deeper()
-        endif
-    else
-        if a:0
-            return self.add('if '.a:1).deeper()
-        else
-            return self
-        endif
-    endif
-endfunction
 "▶1 substostr      :: [subscript] → String
 function s:F.substostr(subscripts)
     let r=''
     endif
 endfunction
 "▲2
-function s:constructor.argstr(...)
+function s:compiler.argstr(...)
     if get(a:000, 0, 0)
         let chunks=[self.argbase]
         for sub in get(a:000, 1, self.subs)
     endif
 endfunction
 "▶1 incsub         :: &self
-function s:constructor.incsub()
+function s:compiler.incsub()
     let self.subs[-1]+=1
     return self
 endfunction
 "▶1 addthrow       :: msg::String, msgarg, ... + self → self + self
-function s:constructor.addthrow(msg, ...)
+function s:compiler.addthrow(msg, ...)
     let args=copy(a:000)
     let curidx=index(args, '@#@')
     if curidx!=-1
                 \   'throw "CHECKFAILED"').up()
 endfunction
 "▶1 nextthrow      :: condition::expr, throwargs + self → self + self
-function s:constructor.nextthrow(cond, ...)
+function s:compiler.nextthrow(cond, ...)
     return call(self.nextcond(a:cond).addthrow, a:000, self)
 endfunction
 "▶1 getfunc        :: funccontext, split[, addarg, ...] + self → String
-function s:constructor.getfunc(func, split, ...)
+function s:compiler.getfunc(func, split, ...)
     if a:split
         let r=[self.getvar(a:func[1])]
     else
     return r
 endfunction
 "▶1 getmatcher     :: matchercontext, ldstr, strstr + self → String
-function s:constructor.getmatcher(matcher, ldstr, strstr)
+function s:compiler.getmatcher(matcher, ldstr, strstr)
     let r='@%@.F.matchers.'.a:matcher[1][1].'('.a:ldstr.', '.a:strstr
     if len(a:matcher[1])>3
         for arg in a:matcher[1][2:-2]
     return r
 endfunction
 "▶1 getexpr        :: exprcontext[, curstr] + self → String
-function s:constructor.getexpr(expr, ...)
+function s:compiler.getexpr(expr, ...)
     let curargstr=self.argstr()
     let this=get(a:000, 0, curargstr)
     return substitute(substitute(a:expr[1],
                 \'\V@:@', escape(curargstr, '&~\'), 'g')
 endfunction
 "▶1 getvar         :: varcontext + self → String
-function s:constructor.getvar(var)
+function s:compiler.getvar(var)
     if a:var[0] is 'plugvar'
         return '@%@.p.'.a:var[1].s:F.substostr(a:var[2:])
     elseif a:var[0] is 'expr'
     endif
 endfunction
 "▶1 getlvarid      :: varname + self → varname
-function s:constructor.getlvarid(v)
+function s:compiler.getlvarid(v)
     return printf('@$@%s%X', a:v, len(self.stack))
 endfunction
 "▶1 addtuple       :: tupledesc, idx, defaultArgType + self → self + self
-function s:constructor.addtuple(tuple, idx, default)
+function s:compiler.addtuple(tuple, idx, default)
     call add(self.subs, 0)
     for arg in a:tuple[1]
         call self.compilearg(arg, a:idx.'(tuple).'.self.subs[-1], a:default)
     return self
 endfunction
 "▶1 addlist        :: listdesc, idx, defaultArgType + self → self + self
-function s:constructor.addlist(list, idx, default)
+function s:compiler.addlist(list, idx, default)
     let largstr=self.getlvarid('larg')
     let istr=self.getlvarid('i')
     call self.add('let '.largstr.'=len('.self.argstr().')',
     call self.up().close()
 endfunction
 "▶1 adddict        :: dicdesc, idx, defaultArgType + self → self + self
-function s:constructor.adddict(dic, idx, default)
+function s:compiler.adddict(dic, idx, default)
     if len(a:dic[1])==1
         let curargstr=self.argstr()
         return self.nextthrow('!empty('.curargstr.')',
     return self
 endfunction
 "▶1 compilemsg     :: msgcontext, _ + self → self + self
-function s:constructor.compilemsg(msg, idx)
+function s:compiler.compilemsg(msg, idx)
     let msg=[a:msg[1]]
     for msgarg in a:msg[2:]
         if msgarg[0] is 'curval'
         elseif msgarg[0] is 'curarg'
             call add(msg, self.subs[0])
         else
-            call add(msg, substitute(s:constructor.getvar(msgarg), '@#@',
+            call add(msg, substitute(s:compiler.getvar(msgarg), '@#@',
                         \            escape(self.argstr(), '\&~'), 'g'))
         endif
     endfor
     return self
 endfunction
 "▶1 compilestring  :: {string} + self → self + self
-function s:constructor.compilestring(str)
+function s:compiler.compilestring(str)
     if type(a:str)==type('')
         return s:F.string(a:str)
     endif
     return self.getvar(a:str)
 endfunction
 "▶1 compilepipe    :: pipecontext, idx + self → self + self
-function s:constructor.compilepipe(pipe, idx)
+function s:compiler.compilepipe(pipe, idx)
     let curargstr=self.argstr()
     "▶2 `func' pipe
     if a:pipe[1][0] is 'func'
     "▲2
     return self
 endfunction
-let s:constructor.compilefilter=s:constructor.compilepipe
+let s:compiler.compilefilter=s:compiler.compilepipe
 "▶1 addpathp       :: idx + self → self + self
-function s:constructor.addpathp(idx)
+function s:compiler.addpathp(idx)
     let curargstr=self.argstr()
     let dirnamestr=self.getlvarid('dirname')
     let prevdirstr=self.getlvarid('prevdir')
     return self
 endfunction
 "▶1 addtypecond    :: types, idx + self → self + self
-function s:constructor.addtypecond(types, idx)
+function s:compiler.addtypecond(types, idx)
     let curargstr=self.argstr()
     let typenames=map(copy(a:types), 's:_messages._types[v:val]')
     if len(a:types)>=2
     return join(subidxs, '.')
 endfunction
 "▶1 compilecheck   :: checkcontext, idx + self → self + self
-function s:constructor.compilecheck(check, idx)
+function s:compiler.compilecheck(check, idx)
     let curargstr=self.argstr()
     let addedcond=0
     let idx=a:idx
             \      'list': ['intfunc', 'type',   [type([])]],
             \      'dict': ['intfunc', 'type',   [type({})]],
         \}
-function s:constructor.compilearg(argcon, idx, ...)
+function s:compiler.compilearg(argcon, idx, ...)
     let type=get(a:000, 0, self.type)
     if a:argcon[0] is 'arg'
         let arg=a:argcon[1:]
     return [minimum, maximum]
 endfunction
 "▶1 addlencheck   :: minlen, maxlen + self → self + self
-function s:constructor.addlencheck(minimum, maximum)
+function s:compiler.addlencheck(minimum, maximum)
     let largsstr=self.getlvarid('largs')
     call self.add('let '.largsstr.'=len('.self.argstr(0, self.subs[:-2]).')')
     if a:maximum==a:minimum
 "▶1 compileadesc   :: adescr + self → self + self
 " XXX in order for this function to work self.argstr(self.subs[:-2]) should 
 " point to argument being checked and self.subs[-1] should be a number
-function s:constructor.compileadesc(adescr)
+function s:compiler.compileadesc(adescr)
     if !has_key(a:adescr, 'minimum')
         call s:F.getlenrange(a:adescr)
     endif
 "▶1 compilestr     :: String, type → [String]
 function s:F.compilestr(vars, string, type)
     "▶2 Setup self
-    let t   =   {   'tree': s:_r.fwc_parser(a:string, a:type)[1:],
+    let t=extend(s:_r.new_constructor(), {
+                \   'tree': s:_r.fwc_parser(a:string, a:type)[1:],
                 \   'type': a:type,
-                \  'ctree': [],
-                \  'stack': [],
                 \   'subs': [0],
-                \      'l': 0,
                 \   'vars': a:vars,
                 \   'vids': {},
-                \'argbase': '@@@'
-                \}
-    call extend(t, s:constructor, 'error')
+                \'argbase': '@@@',
+            \})
+    call extend(t, s:compiler, 'error')
     let t.throw=s:_f.throw
     call add(t.stack, t.ctree)
     let t.l=t.stack[-1]

File plugin/frawor/fwc/constructor.vim

+"▶1 Header
+scriptencoding utf-8
+if exists('s:_pluginloaded') || exists('g:fraworOptions._donotload') ||
+            \exists('g:frawor__donotload')
+    finish
+endif
+execute frawor#Setup('0.0', {'@/resources': '0.0'}, 1)
+let s:constructor={}
+"▶1 add            :: item, ... + self → self + self
+function s:constructor.add(...)
+    let self.l+=a:000
+    return self
+endfunction
+"▶1 up             :: &self
+function s:constructor.up()
+    call remove(self.stack, -1)
+    let self.l=self.stack[-1]
+    return self
+endfunction
+"▶1 deeper         :: ()[, conelement1[, ...]] + self → self + self
+function s:constructor.deeper(...)
+    if type(get(self.l, -1))==type([])
+        let self.l[-1]+=a:000
+        call add(self.stack, self.l[-1])
+    else
+        let con=copy(a:000)
+        call self.add(con)
+        call add(self.stack, con)
+    endif
+    let self.l=self.stack[-1]
+    return self
+endfunction
+"▶1 close          :: &self
+let s:cmdends={
+            \    'if': 'endif',
+            \'elseif': 'endif',
+            \'else'  : 'endif',
+            \'try'    : 'endtry',
+            \'catch'  : 'endtry',
+            \'finally': 'endtry',
+            \'function': 'endfunction',
+            \     'for': 'endfor',
+            \   'while': 'endwhile',
+            \'augroup': 'augroup END',
+            \  'redir': 'redir END',
+        \}
+function s:constructor.close()
+    let command=matchstr(self.l[-2], '\S\+')
+    if has_key(s:cmdends, command)
+        return self.add(s:cmdends[command])
+    else
+        return self
+    endif
+endfunction
+"▶1 nextcond       :: [condition] + self → self + self
+function s:constructor.nextcond(...)
+    if !empty(self.l)
+        if type(self.l[-1])==type([])
+            let prevline=self.l[-2]
+        else
+            let prevline=self.l[-1]
+        endif
+        let command=prevline[:(stridx(prevline, ' ')-1)]
+    endif
+    if exists('command') && (command is 'if' || command is 'elseif')
+        if a:0
+            return self.add('elseif '.a:1).deeper()
+        else
+            return self.add('else').deeper()
+        endif
+    else
+        if a:0
+            return self.add('if '.a:1).deeper()
+        else
+            return self
+        endif
+    endif
+endfunction
+"▶1 new
+call extend(s:constructor, {'ctree': [],
+            \               'stack': [],
+            \                   'l': [],})
+function s:F.new()
+    return deepcopy(s:constructor)
+endfunction
+call s:_f.postresource('new_constructor', s:F.new)
+"▶1
+call frawor#Lockvar(s:, '')
+" vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80

File test/global-functions-reload.ok

 1      echo 1
    endfunction
 
-   function <SNR>23_testFunction()
+   function <SNR>24_testFunction()
 1      echo 2
    endfunction
 
 1      echo 1
    endfunction
 
-   function <SNR>23_testFunction()
+   function <SNR>24_testFunction()
 1      echo 2
    endfunction

File test/ignoredeps-feature.ok

 load: plugin/ignoredeps-feature
 register: plugin/frawor/ruby
 load: plugin/frawor/ruby
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
 register: plugin/frawor/commands
 load: plugin/frawor/commands
 register: autoload/frawor

File test/reload-frawor.ok

 load: plugin/ignoredeps-feature
 register: plugin/frawor/ruby
 load: plugin/frawor/ruby
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
 register: plugin/frawor/commands
 load: plugin/frawor/commands
 register: autoload/frawor
 unloadpre: plugin/frawor/decorators
 unloadpre: plugin/frawor/fwc
 unloadpre: plugin/frawor/fwc/compiler
+unloadpre: plugin/frawor/fwc/constructor
 unloadpre: plugin/frawor/fwc/parser
 unloadpre: plugin/frawor/os
 unloadpre: plugin/frawor/resources
 unload: plugin/frawor/tcl
 unload: plugin/ignoredeps-feature
 _unload
-register: plugin/frawor/decorators
-load: plugin/frawor/decorators
-register: plugin/frawor/fwc
-load: plugin/frawor/fwc
-register: plugin/ignoredeps-feature
-load: plugin/ignoredeps-feature
+register: plugin/frawor/autocommands
+load: plugin/frawor/autocommands
 register: plugin/frawor/checks
 load: plugin/frawor/checks
-register: plugin/frawor/os
-load: plugin/frawor/os
-register: autoload/frawor
-load: autoload/frawor
-register: plugin/frawor/autocommands
-load: plugin/frawor/autocommands
-register: plugin/frawor/options
-load: plugin/frawor/options
 register: plugin/frawor/fwc/parser
 load: plugin/frawor/fwc/parser
 register: plugin/frawor
 load: plugin/frawor
+register: plugin/frawor/decorators
+load: plugin/frawor/decorators
+register: plugin/frawor/os
+load: plugin/frawor/os
+register: plugin/frawor/resources
+load: plugin/frawor/resources
+register: plugin/ignoredeps-feature
+load: plugin/ignoredeps-feature
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
+register: autoload/frawor
+load: autoload/frawor
+register: plugin/frawor/decorators/altervars
+load: plugin/frawor/decorators/altervars
+register: plugin/frawor/options
+load: plugin/frawor/options
+register: plugin/frawor/fwc
+load: plugin/frawor/fwc
 register: plugin/frawor/fwc/compiler
 load: plugin/frawor/fwc/compiler
-register: plugin/frawor/resources
-load: plugin/frawor/resources
 register: plugin/writefile-feature
 load: plugin/writefile-feature
-register: plugin/frawor/decorators/altervars
-load: plugin/frawor/decorators/altervars
 register: plugin/frawor/tcl
 load: plugin/frawor/tcl
 register: plugin/frawor/ruby

File test/reload-ignoredeps.ok

 load: plugin/ignoredeps-feature
 register: plugin/frawor/ruby
 load: plugin/frawor/ruby
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
 register: plugin/frawor/commands
 load: plugin/frawor/commands
 register: autoload/frawor
 load: plugin/ignoredeps-feature
 register: plugin/frawor/ruby
 load: plugin/frawor/ruby
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
 register: plugin/frawor/commands
 load: plugin/frawor/commands
 register: autoload/frawor

File test/reload-writefile.ok

 load: plugin/ignoredeps-feature
 register: plugin/frawor/ruby
 load: plugin/frawor/ruby
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
 register: plugin/frawor/commands
 load: plugin/frawor/commands
 register: autoload/frawor
 load: plugin/ignoredeps-feature
 register: plugin/frawor/ruby
 load: plugin/frawor/ruby
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
 register: plugin/frawor/commands
 load: plugin/frawor/commands
 register: autoload/frawor

File test/unload-self.ok

 load: plugin/ignoredeps-feature
 register: plugin/frawor/ruby
 load: plugin/frawor/ruby
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
 register: plugin/frawor/commands
 load: plugin/frawor/commands
 register: autoload/frawor