From e61cc05e9ebaf7f3f6a5c062ea1974b0c90e5605 Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Wed, 22 Sep 2021 11:49:12 -0700 Subject: [PATCH 1/8] get rid of peek, add PeekSeq, and rename empty? to done? --- compiler/stz-build-manager.stanza | 4 +- compiler/stz-call-records.stanza | 18 +- compiler/stz-core-macros.stanza | 2 +- compiler/stz-dispatch-dag.stanza | 6 +- compiler/stz-dl-ir.stanza | 2 +- compiler/stz-dyn-graph.stanza | 6 +- compiler/stz-el-ir.stanza | 2 +- compiler/stz-el-to-vm.stanza | 4 +- compiler/stz-el.stanza | 8 +- compiler/stz-front-end.stanza | 8 +- compiler/stz-hash.stanza | 4 +- compiler/stz-input.stanza | 4 +- compiler/stz-langs.stanza | 6 +- compiler/stz-proj.stanza | 6 +- compiler/stz-reg-alloc.stanza | 6 +- compiler/stz-repl.stanza | 6 +- compiler/stz-resolver.stanza | 6 +- compiler/stz-set-simplifier.stanza | 2 +- compiler/stz-set-utils.stanza | 10 +- compiler/stz-test-framework.stanza | 10 +- compiler/stz-type-calculus.stanza | 16 +- compiler/stz-type.stanza | 2 +- compiler/stz-utils.stanza | 2 +- compiler/stz-vm-encoder.stanza | 6 +- compiler/stz-vm-normalize.stanza | 16 +- compiler/stz-vm.stanza | 8 +- core/arg-parser.stanza | 8 +- core/core.stanza | 327 +++++++++++++---------------- core/parser.stanza | 4 +- core/reader.stanza | 18 +- 30 files changed, 244 insertions(+), 283 deletions(-) diff --git a/compiler/stz-build-manager.stanza b/compiler/stz-build-manager.stanza index da2f07414..2c60be459 100644 --- a/compiler/stz-build-manager.stanza +++ b/compiler/stz-build-manager.stanza @@ -102,7 +102,7 @@ defn colon-list (xs:Seqable) : new Printable : defmethod print (o:OutputStream, this) : val items = to-seq(xs) - if empty?(items) : + if done?(items) : print(o, ": ()") else : print(o, ":") @@ -117,4 +117,4 @@ public defstruct NoBuildTarget <: Exception : name: Symbol defmethod print (o:OutputStream, e:NoBuildTarget) : - print(o, "No build target named %~." % [name(e)]) \ No newline at end of file + print(o, "No build target named %~." % [name(e)]) diff --git a/compiler/stz-call-records.stanza b/compiler/stz-call-records.stanza index db0804cfe..45b09a555 100644 --- a/compiler/stz-call-records.stanza +++ b/compiler/stz-call-records.stanza @@ -57,9 +57,9 @@ public defn callc-records (a1:Tuple, a2:ArgType, backend:Backend) -> Ca add(records, CallRecord(l,ShadowArg(i))) ;Track registers - val reg-counter = to-seq(0 to length(callc-regs(backend))) - val freg-counter = to-seq(0 to length(callc-fregs(backend))) - val mem-counter = to-seq(0 to false) + val reg-counter = to-peek-seq(0 to length(callc-regs(backend))) + val freg-counter = to-peek-seq(0 to length(callc-fregs(backend))) + val mem-counter = to-peek-seq(0 to false) defn next-reg () : val index = next(reg-counter) val id = callc-regs(backend)[index] @@ -77,13 +77,13 @@ public defn callc-records (a1:Tuple, a2:ArgType, backend:Backend) -> Ca for (x in a1, i in 0 to false) do : match(x) : (x:IntArg) : - if empty?(reg-counter) : ;If no more integer registers + if done?(reg-counter) : ;If no more integer registers std-arg(i, next-mem()) ; place in mem argument else : std-arg(i, next-reg()) ;Otherwise place in integer register next(freg-counter) ; and eat real register (x:RealArg) : - if empty?(freg-counter) : ;If no more real registers + if done?(freg-counter) : ;If no more real registers std-arg(i, next-mem()) ; place in mem argument else : std-arg(i, next-freg()) ;Otherwise place in real register @@ -92,10 +92,10 @@ public defn callc-records (a1:Tuple, a2:ArgType, backend:Backend) -> Ca for (x in a1, i in 0 to false) do : match(x) : (x:IntArg) : - if empty?(reg-counter) : std-arg(i, next-mem()) + if done?(reg-counter) : std-arg(i, next-mem()) else : std-arg(i, next-reg()) (x:RealArg) : - if empty?(freg-counter) : std-arg(i, next-mem()) + if done?(freg-counter) : std-arg(i, next-mem()) else : std-arg(i, next-freg()) ;Classify return value @@ -104,10 +104,10 @@ public defn callc-records (a1:Tuple, a2:ArgType, backend:Backend) -> Ca (a2:RealArg) : FRegLoc(callc-fret(backend), 0) ;Count number of args used - defn peek? (xs:Seq, default:Int) : default when empty?(xs) else peek(xs) + defn peek? (xs:PeekSeq, default:Int) : default when done?(xs) else peek(xs) val num-int-args = peek?(reg-counter, length(callc-regs(backend))) val num-real-args = peek?(freg-counter, length(callc-fregs(backend))) val num-mem-args = peek(mem-counter) ;Return record - CallCRecords(to-tuple(records), return-loc, num-int-args, num-real-args, num-mem-args) \ No newline at end of file + CallCRecords(to-tuple(records), return-loc, num-int-args, num-real-args, num-mem-args) diff --git a/compiler/stz-core-macros.stanza b/compiler/stz-core-macros.stanza index b2c9407ba..fb67bc400 100644 --- a/compiler/stz-core-macros.stanza +++ b/compiler/stz-core-macros.stanza @@ -1135,7 +1135,7 @@ defsyntax core : defrule exp4 = (~ #for ?bs:#for-bindings #:! ?body) : val vals = map(to-seq{values(_)}, bs) val body* = to-list $ repeat-while $ fn () : - if all?(empty?, vals) : + if all?(done?, vals) : None() else : One{fill-template(body, _)} $ diff --git a/compiler/stz-dispatch-dag.stanza b/compiler/stz-dispatch-dag.stanza index f7c52c1e7..390ae1d63 100644 --- a/compiler/stz-dispatch-dag.stanza +++ b/compiler/stz-dispatch-dag.stanza @@ -141,7 +141,7 @@ public defn union (args:Seqable) -> Arg : val nums = for arg in args seq : match(arg:Top) : return(arg) else : values(arg as Nums) - if empty?(nums) : Nums([]) + if done?(nums) : Nums([]) else : Nums $ to-tuple $ union(nums) public defn subarg-of-union? (x:Arg, ys:Seqable) : @@ -154,7 +154,7 @@ public defn subarg-of-union? (x:Arg, ys:Seqable) : public defn intersect (args:Seqable) -> Arg : val nums = seq(values, filter-by(args)) - if empty?(nums) : Top() + if done?(nums) : Top() else : Nums $ to-tuple $ intersect(nums) ;============================================================ @@ -294,7 +294,7 @@ defn topo-soln (input-solns:Tuple, btable:BranchTable) -> Soln : ;branches only amongst instance methods. val instance-solns = for s in input-solns filter : instance-branches(btable)[index(s as UniqueSoln)] - val solns = input-solns when empty?(instance-solns) + val solns = input-solns when done?(instance-solns) else to-tuple(instance-solns) ;Get the ids from the soln ids diff --git a/compiler/stz-dl-ir.stanza b/compiler/stz-dl-ir.stanza index fb23f9bbf..79c5e5e43 100644 --- a/compiler/stz-dl-ir.stanza +++ b/compiler/stz-dl-ir.stanza @@ -517,7 +517,7 @@ defmethod print (o:OutputStream, x:PackageExports) : defn bprint (o:OutputStream, xs:Seqable) : val xs-seq = to-seq(xs) - if empty?(xs-seq) : print(o, " ()") + if done?(xs-seq) : print(o, " ()") else : lnprints(IndentedStream(o), xs-seq) ;============================================================ diff --git a/compiler/stz-dyn-graph.stanza b/compiler/stz-dyn-graph.stanza index 9aa1e9ee5..d71f7e04f 100644 --- a/compiler/stz-dyn-graph.stanza +++ b/compiler/stz-dyn-graph.stanza @@ -179,11 +179,11 @@ defmulti yield-right (m:Merger, y:Y) -> False defmulti yield-merged (m:Merger, x:X, y:Y) -> False defn merge (merger:Merger, xs:Seqable, ys:Seqable) : - val xs-seq = to-seq(xs) - val ys-seq = to-seq(ys) + val xs-seq = to-peek-seq(xs) + val ys-seq = to-peek-seq(ys) let loop () : - match(empty?(xs-seq), empty?(ys-seq)) : + match(done?(xs-seq), done?(ys-seq)) : (ex:True, ey:True) : false (ex:True, ey:False) : diff --git a/compiler/stz-el-ir.stanza b/compiler/stz-el-ir.stanza index c6b5523d4..f389cb615 100644 --- a/compiler/stz-el-ir.stanza +++ b/compiler/stz-el-ir.stanza @@ -673,7 +673,7 @@ defmethod print (o:OutputStream, t:ETVarLoc) : defn bprint (o:OutputStream, xs:Seqable) : val xs-seq = to-seq(xs) - if empty?(xs-seq) : print(o, " ()") + if done?(xs-seq) : print(o, " ()") else : lnprints(IndentedStream(o), xs-seq) ;============================================================ diff --git a/compiler/stz-el-to-vm.stanza b/compiler/stz-el-to-vm.stanza index 77f1d8d40..cf3341e53 100644 --- a/compiler/stz-el-to-vm.stanza +++ b/compiler/stz-el-to-vm.stanza @@ -1328,7 +1328,7 @@ defn true-obj (iotable:IOTable) : ;============================================================ defn type-parts (t:EType, iotable:IOTable) -> Tuple : - val parts = generate : + val parts = PeekSeq $ generate : ;Break down type into parts defn level (t:EType) : match(t) : @@ -1364,7 +1364,7 @@ defn type-parts (t:EType, iotable:IOTable) -> Tuple : format(t, 0) to-tuple $ generate : - while not empty?(parts) : + while not done?(parts) : match(peek(parts)) : (v:ETVar): yield(next(parts)) diff --git a/compiler/stz-el.stanza b/compiler/stz-el.stanza index 14ee622bf..52380ecd4 100644 --- a/compiler/stz-el.stanza +++ b/compiler/stz-el.stanza @@ -556,7 +556,7 @@ defn create-closures (epackage:EPackage, gvt:VarTable) -> EPackage : if top? : do(emit{buffer, _}, uninitialized-trampolines()) val locs = seq(EVarLoc{n(_)}, uninitialized-trampolines()) - if not empty?(locs) : + if not done?(locs) : emit(buffer, EInitClosures(to-tuple(locs), false)) ;Emit instructions with added initializations for i in ins(body) do : @@ -1471,7 +1471,7 @@ defn simple-inline (epackage:EPackage) : emit(buffer, i) (i:EInitClosures) : val xs* = for x in xs(i) filter : not key?(inlined-functions, n(x)) - if not empty?(xs*) : + if not done?(xs*) : emit(buffer, EInitClosures(to-tuple(xs*), info(i))) (i) : emit(buffer, i) @@ -1868,7 +1868,7 @@ defn lambda-lift (epackage:EPackage, gvt:VarTable) : ;Add lifted type arguments to the given function immediate defn add-targs (e:EImm, free:Free) : defn curry (v:EVar, targs:Seq) : - if empty?(targs) : v + if done?(targs) : v else : ECurry(v, to-tuple(targs)) val free-targs = seq(ETVar, tvars(free)) match(e) : @@ -2804,7 +2804,7 @@ defn resolve-matches (epackage:EPackage, ehier:EHier, gvt:VarTable) -> EPackage defn union (input-ts:Seqable) : val ts = to-seq(input-ts) - if empty?(ts) : EBot() + if done?(ts) : EBot() else : reduce(EOr, ts) ;============================================================ diff --git a/compiler/stz-front-end.stanza b/compiler/stz-front-end.stanza index 38654eac9..191770924 100644 --- a/compiler/stz-front-end.stanza +++ b/compiler/stz-front-end.stanza @@ -411,16 +411,16 @@ defn FrontEnd (sys:FrontEndInputs) -> FrontEnd : throw(FrontEndErrors(errors)) when not empty?(errors) defn sub-ipackages (objs:Seqable, new-ipackages:Seqable) -> Tuple : - val pkg-seq = to-seq(new-ipackages) + val pkg-seq = to-peek-seq(new-ipackages) val result = to-tuple $ for obj in objs seq? : match(obj) : (obj:IPackage) : - if empty?(pkg-seq) : None() + if done?(pkg-seq) : None() else if name(obj) == name(peek(pkg-seq)) : One(next(pkg-seq)) else : None() (obj:Pkg) : One(obj) - fatal("Mismatched packages.") when not empty?(pkg-seq) + fatal("Mismatched packages.") when not done?(pkg-seq) result ;---------------------------------------------------------- @@ -739,4 +739,4 @@ defn MissingPackageInFile (filename:String, package-name:Symbol) : defn PackageAlreadyLoaded (package-name:Symbol) : new FrontEndError : defmethod print (o:OutputStream, this) : - print(o, "The package %~ has already been loaded." % [package-name]) \ No newline at end of file + print(o, "The package %~ has already been loaded." % [package-name]) diff --git a/compiler/stz-hash.stanza b/compiler/stz-hash.stanza index 9590a3360..1a4ee5968 100644 --- a/compiler/stz-hash.stanza +++ b/compiler/stz-hash.stanza @@ -117,7 +117,7 @@ public defn PerfectHashTable (entries0:Collection> & Length val dstamp = next(dcounter) val ks = to-seq(keys) let loop-k () : - if empty?(ks) : + if done?(ks) : d else : val k = next(ks) @@ -209,4 +209,4 @@ defn dhash (d:Int, x:Int, n:Int) : a = (a + 0xd3a2646c) ^ (a << 9) a = (a + 0xfd7046c5) + (a << 3) a = (a ^ 0xb55a4f09) ^ (a >> 16) - (a & 0x7FFFFFFF) % n \ No newline at end of file + (a & 0x7FFFFFFF) % n diff --git a/compiler/stz-input.stanza b/compiler/stz-input.stanza index e0be61536..488237ccf 100644 --- a/compiler/stz-input.stanza +++ b/compiler/stz-input.stanza @@ -295,7 +295,7 @@ defn ls-name-args (e:IExp) -> [IExp, List] : defn split-packages (e:IExp, default-imports:Tuple) : ;Flatten sequence of expressions defn flatten (e:IExp) : - generate : + PeekSeq $ generate : let loop (e:IExp = e) : match(e:IBegin) : do(loop, exps(e)) else : yield(e) @@ -303,7 +303,7 @@ defn split-packages (e:IExp, default-imports:Tuple) : ;Group packages val packages = Vector() - while not empty?(eseq) : + while not done?(eseq) : val pkg = match(peek(eseq)) : (e:IDefPackage) : next(eseq) diff --git a/compiler/stz-langs.stanza b/compiler/stz-langs.stanza index fa9379868..1f2a058d6 100644 --- a/compiler/stz-langs.stanza +++ b/compiler/stz-langs.stanza @@ -841,7 +841,7 @@ defsyntax stz-fast-print-lang : defn compile (info:False|FileInfo, format:String, args:List) : ;Break into parts - val parts = generate : + val parts = PeekSeq $ generate : val n = length(format) val args-seq = to-seq(args) let loop (i:Int = 0) : @@ -865,7 +865,7 @@ defn compile (info:False|FileInfo, format:String, args:List) : break('\n') ;Assemble into pieces val pieces = repeat-while $ fn () : - if empty?(parts) : + if done?(parts) : None() else : match(peek(parts)) : @@ -878,4 +878,4 @@ defn compile (info:False|FileInfo, format:String, args:List) : fill-template(`(print(x)), [`x => p]) - \ No newline at end of file + diff --git a/compiler/stz-proj.stanza b/compiler/stz-proj.stanza index beda4437b..556cdb58e 100644 --- a/compiler/stz-proj.stanza +++ b/compiler/stz-proj.stanza @@ -895,14 +895,14 @@ defn separate (s:SplicedString) -> ProjValue : ;Join all pieces in the buffer val joined-buffer = Vector() val buffer-seq = to-seq(buffer) - while not empty?(buffer-seq) : + while not done?(buffer-seq) : ;Take until next separator val values = to-tuple $ take-while({_ is ProjValue}, buffer-seq) ;Add to joined buffer if length(values) == 1 : add(joined-buffer, values[0] as ProjValue) else : add(joined-buffer, SplicedString(info(s), values as Tuple)) ;Eat separator - next(buffer-seq) when not empty?(buffer-seq) + next(buffer-seq) when not done?(buffer-seq) ;Return cases if length(joined-buffer) == 1 : joined-buffer[0] @@ -1062,4 +1062,4 @@ defn tuple? (f:T -> Tuple, x:Maybe) -> Tuple : else : f(value!(x)) defn map-values (f:V1 -> ?V2, xs:Tuple>) : - for x in xs map : key(x) => f(value(x)) \ No newline at end of file + for x in xs map : key(x) => f(value(x)) diff --git a/compiler/stz-reg-alloc.stanza b/compiler/stz-reg-alloc.stanza index f041e5693..ec649b225 100644 --- a/compiler/stz-reg-alloc.stanza +++ b/compiler/stz-reg-alloc.stanza @@ -1595,10 +1595,10 @@ defn register-assignment (blk:Block, b:Int, backend:Backend) : match(t) : (t:VMType&IntegerT) : val rs = free(reg-list) - Reg(next(rs)) when not empty?(rs) + Reg(next(rs)) when not done?(rs) (t:VMType&RealT) : val rs = free(freg-list) - FReg(next(rs)) when not empty?(rs) + FReg(next(rs)) when not done?(rs) defn available-reg? (t:VMType, pref:List) : val pref-regs = seq(XReg{t, _}, pref) val r = find({slot(_) is False}, pref-regs) @@ -2759,4 +2759,4 @@ defn to-asm-op (op:VMOp) -> asm-Op : ;============================================================ defn keys (xs:Vector>) : to-list(seq(key,xs)) -defn values (xs:Vector>) : to-list(seq(value,xs)) \ No newline at end of file +defn values (xs:Vector>) : to-list(seq(value,xs)) diff --git a/compiler/stz-repl.stanza b/compiler/stz-repl.stanza index 88eb09fa6..ded7f0329 100644 --- a/compiler/stz-repl.stanza +++ b/compiler/stz-repl.stanza @@ -263,7 +263,7 @@ public defn REPL () : defn init-packages (input-names:Seqable) : val names = to-seq(input-names) let loop () : - if not empty?(names) : + if not done?(names) : val package-name = next(names) val success? = init-package(vm, package-name) throw(ReplHalt()) when not success? @@ -441,7 +441,7 @@ public defn REPL () : defmethod use-syntax (this, packages:Tuple, add-to-existing?:True|False) : ;Throw NoSyntaxPackage if any of the mentioned packages do not exist. val missing-packages = filter({not syntax-package-exists?(_)}, packages) - if not empty?(missing-packages) : + if not done?(missing-packages) : val es = seq(NoSyntaxPackage, missing-packages) throw(ReplErrors(to-tuple(es))) ;Clear syntaxes when not add to existing syntaxes. @@ -847,4 +847,4 @@ defn make-load-exp (args:Tuple, go-inside?:True|False) : val inputs = for a in args map : if index-of-char(a, '.') is Int : a else : to-symbol(a) - Load(inputs, go-inside?) \ No newline at end of file + Load(inputs, go-inside?) diff --git a/compiler/stz-resolver.stanza b/compiler/stz-resolver.stanza index 4828886fe..a7b606399 100644 --- a/compiler/stz-resolver.stanza +++ b/compiler/stz-resolver.stanza @@ -221,7 +221,7 @@ defn check-exported-types (symtables:SymbolTables, pkgs:Collection, pe type(e) is TypeE|LTypeE and package(e) == package(symtable) val entries = filter(exported-type?, base(symtable, name(e))) - add(error-accum, MissingType(package(pex), e)) when empty?(entries) + add(error-accum, MissingType(package(pex), e)) when done?(entries) ;Recursively scan DItem for typeid defn scan-for-type (e:DItem) : do(scan-for-type, e) @@ -487,7 +487,7 @@ defn Engine (current-symtable:SymbolTable, ;Return type-appropriate entries defn return-pruned (es:Seqable) : val es* = filter(pred?, es) - if empty?(es*) : throw(NoResolve(name(e), info(e))) + if done?(es*) : throw(NoResolve(name(e), info(e))) else : to-list(prune-low-priority(es*)) ;Qualified form: /mysymbol @@ -508,7 +508,7 @@ defn Engine (current-symtable:SymbolTable, else : val es = for layer in current-symtable[name] first : val es* = filter(pred?, layer) - if empty?(es*) : None() + if done?(es*) : None() else : One(es*) if empty?(es) : throw(NoResolve(/name(e), info(e))) else : to-list(prune-low-priority(value!(es))) diff --git a/compiler/stz-set-simplifier.stanza b/compiler/stz-set-simplifier.stanza index 5467a9a9b..9a847d3e8 100644 --- a/compiler/stz-set-simplifier.stanza +++ b/compiler/stz-set-simplifier.stanza @@ -265,7 +265,7 @@ defn union-grouping-simplification (dnf:Union) -> Term|False : for v in conj-vars(term) do : var-counts[v] = var-counts[v] + 1 val vars = keys(var-counts) - if not empty?(vars) : + if not done?(vars) : val v = maximum({var-counts[_]}, vars) v when var-counts[v] > 1 diff --git a/compiler/stz-set-utils.stanza b/compiler/stz-set-utils.stanza index 8fd34818a..d69fe9233 100644 --- a/compiler/stz-set-utils.stanza +++ b/compiler/stz-set-utils.stanza @@ -49,8 +49,8 @@ public defn subset-of-union? (xs:Tuple, yss:Seqable>) -> True|Fa public defn union (a:Seqable, b:Seqable) -> Seq : generate : - val [sa, sb] = [to-seq(a), to-seq(b)] - while not empty?(sa) and not empty?(sb) : + val [sa, sb] = [to-peek-seq(a), to-peek-seq(b)] + while not done?(sa) and not done?(sb) : val [ai, bj] = [peek(sa), peek(sb)] if ai < bj : yield(next(sa)) @@ -64,8 +64,8 @@ public defn union (a:Seqable, b:Seqable) -> Seq : public defn intersect (a:Seqable, b:Seqable) -> Seq : generate : - val [sa, sb] = [to-seq(a), to-seq(b)] - while not empty?(sa) and not empty?(sb) : + val [sa, sb] = [to-peek-seq(a), to-peek-seq(b)] + while not done?(sa) and not done?(sb) : val [ai, bj] = [peek(sa), peek(sb)] if ai < bj : next(sa) @@ -92,4 +92,4 @@ defn bsearch (xs:Tuple, start:Int, end:Int, v:Int) -> Int : else : val m = i + (j - i) / 2 if xs[m] < v : loop(m + 1, j) - else : loop(i, m) \ No newline at end of file + else : loop(i, m) diff --git a/compiler/stz-test-framework.stanza b/compiler/stz-test-framework.stanza index 30ba9c488..d3f14594c 100644 --- a/compiler/stz-test-framework.stanza +++ b/compiler/stz-test-framework.stanza @@ -430,9 +430,9 @@ protected defn print-test-report (exit-on-fail?:True|False) : val s = testing-state() ;Count statistics - val skip-counter = to-seq(0 to false) - val pass-counter = to-seq(0 to false) - val fail-counter = to-seq(0 to false) + val skip-counter = to-peek-seq(0 to false) + val pass-counter = to-peek-seq(0 to false) + val fail-counter = to-peek-seq(0 to false) for r in records(s) do : match(r) : (r:SkippedTest) : next(skip-counter) @@ -444,7 +444,7 @@ protected defn print-test-report (exit-on-fail?:True|False) : ;First print failed tests val failed-tests = for t in records(s) filter : match(t:RanTest) : not passed?(t) - if not empty?(failed-tests) : + if not done?(failed-tests) : println(STANDARD-OUTPUT-STREAM, "\nFailed Tests:") do(println{STANDARD-OUTPUT-STREAM, _}, failed-tests) @@ -466,4 +466,4 @@ protected defn print-test-report (exit-on-fail?:True|False) : ;Exit with proper exit code when requested if exit-on-fail? and peek(fail-counter) > 0 : - exit(-1) \ No newline at end of file + exit(-1) diff --git a/compiler/stz-type-calculus.stanza b/compiler/stz-type-calculus.stanza index e3a6387e3..d8b5491e9 100644 --- a/compiler/stz-type-calculus.stanza +++ b/compiler/stz-type-calculus.stanza @@ -235,7 +235,7 @@ public defn or4 (x: True|Unknown|False|Possibly, y: True|Unknown|False|Possibly) public defn all4? (pred?: (T) -> True|Unknown|False|Possibly, xs:Seqable) : val s = to-seq(xs) defn loop () : - if empty?(s) : true + if done?(s) : true else : and4(pred?(next(s)), loop()) loop() @@ -243,14 +243,14 @@ public defn all4? (pred?: (S,T) -> True|Unknown|False|Possibly, xs:Seqabl val s = to-seq(xs) val t = to-seq(ys) defn loop () : - if empty?(s) or empty?(t) : true + if done?(s) or done?(t) : true else : and4(pred?(next(s), next(t)), loop()) loop() public defn any4? (pred?: (T) -> True|Unknown|False|Possibly, xs:Seqable) : val s = to-seq(xs) defn loop () : - if empty?(s) : false + if done?(s) : false else : or4(pred?(next(s)), loop()) loop() @@ -258,7 +258,7 @@ public defn any4? (pred?: (S,T) -> True|Unknown|False|Possibly, xs:Seqabl val s = to-seq(xs) val t = to-seq(ys) defn loop () : - if empty?(s) or empty?(t) : false + if done?(s) or done?(t) : false else : or4(pred?(next(s), next(t)), loop()) loop() @@ -447,7 +447,7 @@ defn flow-result (cn:Int, x:Type, y:Type) -> FlowResult : fl(type(x), type(y)) else : val rs = fl(parents(x, n(y)), y) - if empty?(rs) : FFalse() + if done?(rs) : FFalse() else : reduce(FOr, rs) (x:TTuple, y:TTuple) : if length(types(x)) == length(types(y)) : @@ -519,7 +519,7 @@ defn flow-result (cn:Int, defn ex (ts:List, r:LSType) : cat(ts, repeat(r)) defn ap (ts:List, r:LSType) : cat(ts, [r]) defn fand (fs:Seq) : - if empty?(fs) : FFalse() + if done?(fs) : FFalse() else : reduce(FAnd, fs) defn fall (xs:Seqable, ys:Seqable) : fand(seq(flow-result{cn, _, _}, xs, ys)) @@ -818,7 +818,7 @@ public defn mix (sel:List, ts:List) -> False| (s:Possibly) : combine!(remove-ret(t as TArrow)) (s:False) : false val fs = to-seq(values(funcs)) - reduce(TAnd, fs) when not empty?(fs) + reduce(TAnd, fs) when not done?(fs) ;In order for two LoStanza functions to be mixed, ;all arguments must be compatible. @@ -1051,4 +1051,4 @@ public defn callable? (x:FnT, a2:List) : val n2 = length(a2) match(r(x)) : (rx:False) : all3?(assignable?, a2, a1) when n1 == n2 - (rx:LSType) : all3?(assignable?, a2, ex(a1, rx)) when n1 <= n2 \ No newline at end of file + (rx:LSType) : all3?(assignable?, a2, ex(a1, rx)) when n1 <= n2 diff --git a/compiler/stz-type.stanza b/compiler/stz-type.stanza index 91566dd14..b76a6cead 100644 --- a/compiler/stz-type.stanza +++ b/compiler/stz-type.stanza @@ -2686,7 +2686,7 @@ defn report-errors (nm:NameMap, ;Filter out low priority errors val filtered-errors = let : val hp = filter(high-priority{_, env, ls-env}, errors) - errors when empty?(hp) else hp + errors when done?(hp) else hp ;Throw Errors throw $ TypeErrors $ to-tuple $ for e in filtered-errors seq : diff --git a/compiler/stz-utils.stanza b/compiler/stz-utils.stanza index 9cde365c8..ee41c168f 100644 --- a/compiler/stz-utils.stanza +++ b/compiler/stz-utils.stanza @@ -153,7 +153,7 @@ public defn to-bitmask (xs:Seqable) -> List : defn loop (accum:Long, len:Int) : if len == 64 : cons(accum, loop(0L, 0)) - else if not empty?(sxs) : + else if not done?(sxs) : val mark = bit(next(sxs)) << to-long(len) loop(accum + mark, len + 1) else if len > 0 : List(accum) diff --git a/compiler/stz-vm-encoder.stanza b/compiler/stz-vm-encoder.stanza index 70e179ec7..f06682e9d 100644 --- a/compiler/stz-vm-encoder.stanza +++ b/compiler/stz-vm-encoder.stanza @@ -319,8 +319,8 @@ public defn encode (func:VMFunction, v => value(e) let loop () : val e = next(es) - f(e, empty?(es)) - loop() when not empty?(es) + f(e, done?(es)) + loop() when not done?(es) ;Launch emit-dag(compute-dag()) @@ -1242,4 +1242,4 @@ defn delay-actions (f:() -> ?T) : val result = let-var delay = delay-action : f() for d in delays do : d() clear(delays) - result \ No newline at end of file + result diff --git a/compiler/stz-vm-normalize.stanza b/compiler/stz-vm-normalize.stanza index c49caa84b..590fd35d3 100644 --- a/compiler/stz-vm-normalize.stanza +++ b/compiler/stz-vm-normalize.stanza @@ -1062,10 +1062,10 @@ defn ret-records (b:InsBuffer, xs:Seqable, backend:Backend) -> Ret else : x as VMType val loc = if integral?(t) : - if empty?(regs) : next(mems) + if done?(regs) : next(mems) else : next(regs) else : - if empty?(fregs) : next(mems) + if done?(fregs) : next(mems) else : next(fregs) match(x:Local) : add(records, RetRecord(x, loc)) @@ -1074,13 +1074,13 @@ defn ret-records (b:InsBuffer, xs:Seqable, backend:Backend) -> Ret defn retc-records (b:InsBuffer, xs0:Seqable, backend:Backend) -> RetRecords : val records = Vector() val xs = to-seq(xs0) - if not empty?(xs) : + if not done?(xs) : val x = next(xs) match(x:Local) : val t = type(b,x) if integral?(t) : add(records, RetRecord(x, CallReg(0))) else : add(records, RetRecord(x, CallFReg(0))) - if not empty?(xs) : + if not done?(xs) : fatal("More than a single C return value!") RetRecords(to-tuple(records)) @@ -1093,10 +1093,10 @@ defn call-records (b:InsBuffer, xs:Seqable, backend:Backend) -> CallRecor val t = type(b,x) val loc = if integral?(t) : - if empty?(regs) : next(mems) + if done?(regs) : next(mems) else : next(regs) else : - if empty?(fregs) : next(mems) + if done?(fregs) : next(mems) else : next(fregs) add(records,CallRecord(x, loc)) CallRecords(to-tuple(records)) @@ -1125,7 +1125,7 @@ defn match-records (xs:Seqable, backend:Backend) -> CallRecords : val regs = seq(CallReg, call-regs(backend)) val mems = seq(CallMemArg, 0 to false) for x in xs do : - if empty?(regs) : rec(x, next(mems)) + if done?(regs) : rec(x, next(mems)) else : rec(x, next(regs)) CallRecords(to-tuple(records)) @@ -1409,4 +1409,4 @@ defn InsBuffer (function:VMFunction) : else : i def-table[n] = VMDef(n, t) Local(n) - \ No newline at end of file + diff --git a/compiler/stz-vm.stanza b/compiler/stz-vm.stanza index c9496b62d..8689b817c 100644 --- a/compiler/stz-vm.stanza +++ b/compiler/stz-vm.stanza @@ -617,7 +617,7 @@ lostanza defn collect-garbage (vm:ref) -> long : ;Scan global roots val globals:ptr = vm.vmtable.globals.mem val roots = to-seq(roots(vm.vmtable.global-table)) - while empty?(roots) == false : + while done?(roots) == false : val i = next(roots).value globals[i] = post-gc-object(globals[i], vm) @@ -910,7 +910,7 @@ public lostanza defn compute-live (vm:ref, exclude:ref = vm.vmtable.globals.mem val roots = to-seq(roots(vm.vmtable.global-table, exclude)) - while empty?(roots) == false : + while done?(roots) == false : val i = next(roots).value mark-ref(globals[i]) @@ -1106,7 +1106,7 @@ defn class-names (cs:Seqable, ids:VMIds) -> Seqable, keep-existing-globals?:True|False) : - if not empty?(to-seq(vmps)) : + if not done?(to-seq(vmps)) : ;Precondition ensure-core-loaded-first!(vm, vmps) @@ -1194,7 +1194,7 @@ public lostanza defn clear-globals (vm:ref) -> ref : ;Scan global roots val globals:ptr = vm.vmtable.globals.mem val roots = to-seq(roots(vm.vmtable.global-table)) - while empty?(roots) == false : + while done?(roots) == false : val i = next(roots).value globals[i] = void-marker() return false diff --git a/core/arg-parser.stanza b/core/arg-parser.stanza index 9793ff338..228ede59e 100644 --- a/core/arg-parser.stanza +++ b/core/arg-parser.stanza @@ -156,7 +156,7 @@ defn parse-args-and-flags (flags:Tuple, arguments:Tuple) -> name(f) => f ;Sequence of arguments - val argseq = to-seq(arguments) + val argseq = to-peek-seq(arguments) ;Returns true if the given argument is a flag. defn flag? (arg:String) : @@ -165,7 +165,7 @@ defn parse-args-and-flags (flags:Tuple, arguments:Tuple) -> ;Read algorithm defn* eat-args () -> Tuple : val args = Vector() - while not empty?(argseq) and + while not done?(argseq) and not flag?(peek(argseq)) : add(args, next(argseq)) to-tuple(args) @@ -173,7 +173,7 @@ defn parse-args-and-flags (flags:Tuple, arguments:Tuple) -> ;Return all parsed flags defn eat-flags () -> Tuple : val flags = Vector() - while not empty?(argseq) : + while not done?(argseq) : val flagstr = next(argseq) fatal("Not a flag") when not flag?(flagstr) val flagname = flagstr[1 to false] @@ -201,7 +201,7 @@ defn parse-args-and-flags (flags:Tuple, arguments:Tuple) -> defn* eat-args-until-next-flag (first-arg-greedy?:True|False) -> Tuple : val args = Vector() let loop (greedy?:True|False = first-arg-greedy?) : - if not empty?(argseq) : + if not done?(argseq) : if greedy? or not flag?(peek(argseq)) : add(args, next(argseq)) loop(false) diff --git a/core/core.stanza b/core/core.stanza index 87a3336a1..c0a3f1167 100644 --- a/core/core.stanza +++ b/core/core.stanza @@ -3162,6 +3162,10 @@ protected defn range-bound (s:Lengthable, r:Range) -> [Int, Int] : (e:Int, i:False) : [start(r), e] (e:False, i) : [start(r), length(s)] +protected defn ensure-not-done (xs:Seq) : + #if-defined(OPTIMIZE) : + fatal("Next on done seq %_" % [xs]) when done?(xs) + ;============================================================ ;===================== Hashable ============================= ;============================================================ @@ -5166,7 +5170,7 @@ public lostanza defn append-all (xs:ref>) -> ref : val ret = String(len.value) val xs-seq = to-seq(xs) var accum : long = 0 - while empty?(xs-seq) == false : + while done?(xs-seq) == false : val s = next(xs-seq) copy(ret, s, accum) accum = accum + strlen(s) @@ -5390,7 +5394,7 @@ public defn append (xs:Seqable, ys:List) -> List : public defn append-all (xs:Seqable>) -> List : val xs-seq = to-seq(xs) defn loop () : - if empty?(xs-seq) : List() + if done?(xs-seq) : List() else : append(next(xs-seq), loop()) loop() @@ -5494,7 +5498,7 @@ public defn modulo (format:String, args:Seqable) -> Printable : print(o, c) loop(i + 1) else : - if not empty?(seq) : + if not done?(seq) : fatal("Unexpected end of format string %~. More arguments remaining." % [format]) loop(0) @@ -5601,10 +5605,7 @@ public defn Generator (thunk : (T -> False, (T -> Void) & (() -> Void)) -> ?) defmethod next (this) : fill() empty() - defmethod peek (this) : - fill() - peek() - defmethod empty? (this) : + defmethod done? (this) : fill() defmethod free (this) : close(co) when open?(co) @@ -7077,8 +7078,7 @@ public defmulti to-seq (s:Seqable) -> Seq defmethod to-seq (s:Seq) : s public defmulti next (s:Seq) -> T -public defmulti peek (s:Seq) -> T -public defmulti empty? (s:Seq) -> True|False +public defmulti done? (s:Seq) -> True|False public defmulti free (s:Seq) -> False defmethod free (s:Seq) : false @@ -7103,15 +7103,13 @@ defmethod to-seq (s:String) : defmethod to-seq (x:List) : var l = x new Seq : - defmethod empty? (this) : + defmethod done? (this) : empty?(l) defmethod next (this) : - val x = peek(this) + ensure-not-done(this) + val x = head(l) l = tail(l) x - defmethod peek (this) : - fatal("Empty Sequence") when empty?(this) - head(l) defmethod to-seq (xs:IndexedCollection) -> Seq : seq({xs[_]}, 0 to length(xs)) @@ -7123,14 +7121,11 @@ defmethod to-seq (r:Range) : var n = length(r) new Seq & Lengthable : defmethod next (this) : - val i* = peek(this) + val i* = i i = i + step(r) n = n - 1 i* - defmethod peek (this) : - fatal("Empty Sequence") when empty?(this) - i - defmethod empty? (this) : + defmethod done? (this) : n == 0 defmethod length (this) : n @@ -7141,9 +7136,7 @@ defmethod to-seq (r:Range) : val i* = i i = i + step(r) i* - defmethod peek (this) : - i - defmethod empty? (this) : + defmethod done? (this) : false ;===== Conversion from Sequence ===== @@ -7207,20 +7200,20 @@ public defmulti do (f:(T,S,U) -> ?, xs:Seqable, ys:Seqable, zs defmethod do (f:T -> ?, xs:Seqable) -> False : for xs-seq in xs do-seq : - while not empty?(xs-seq) : + while not done?(xs-seq) : f(next(xs-seq)) defmethod do (f:(T,S) -> ?, xs:Seqable, ys:Seqable) -> False : for xs-seq in xs do-seq : for ys-seq in ys do-seq : - while (not empty?(xs-seq)) and (not empty?(ys-seq)) : + while (not done?(xs-seq)) and (not done?(ys-seq)) : f(next(xs-seq), next(ys-seq)) defmethod do (f:(T,S,U) -> ?, xs:Seqable, ys:Seqable, zs:Seqable) -> False : for xs-seq in xs do-seq : for ys-seq in ys do-seq : for zs-seq in zs do-seq : - while (not empty?(xs-seq)) and (not empty?(ys-seq)) and (not empty?(zs-seq)) : + while (not done?(xs-seq)) and (not done?(ys-seq)) and (not done?(zs-seq)) : f(next(xs-seq), next(ys-seq), next(zs-seq)) ;Specialization @@ -7263,46 +7256,47 @@ defmethod do (f:T -> ?, xs:List) -> False : defn wrap-length (xs:Seq, length:() -> Int) : new Seq & Lengthable : defmethod next (this) : next(xs) - defmethod peek (this) : peek(xs) - defmethod empty? (this) : empty?(xs) + defmethod done? (this) : done?(xs) defmethod length (this) : length() public defn to-collection (f:() -> Seq) -> Collection : new Collection : defmethod to-seq (this) : f() -public defn seq (f:T -> ?S, xs:Seqable) -> Seq : +public defn seq (f:T -> ?R, xs:Seqable) -> Seq : val xs-seq = to-seq(xs) - val rs = repeat-while $ fn () : - if empty?(xs-seq) : None() - else : One(f(next(xs-seq))) - match(xs-seq) : - (xs:Seq&Lengthable) : - wrap-length(rs, {cached(rs) + length(xs)}) - (xs) : rs + val rs = new Seq : + defmethod next (this) : + f(next(xs-seq)) + defmethod done? (this) : + done?(xs-seq) + match(xs-seq:Seq&Lengthable) : wrap-length(rs, { length(xs-seq) }) + else : rs public defn seq (f:(T,S) -> ?R, xs:Seqable, ys:Seqable) -> Seq : val xs-seq = to-seq(xs) val ys-seq = to-seq(ys) - val rs = repeat-while $ fn () : - if empty?(xs-seq) or empty?(ys-seq) : None() - else : One(f(next(xs-seq), next(ys-seq))) - match(xs-seq, ys-seq) : - (xs:Seq&Lengthable, ys:Seq&Lengthable) : - wrap-length(rs, {cached(rs) + min(length(xs), length(ys))}) - (xs, ys) : rs + val rs = new Seq : + defmethod next (this) : + f(next(xs-seq), next(ys-seq)) + defmethod done? (this) : + done?(xs-seq) or done?(ys-seq) + match(xs-seq:Seq&Lengthable, ys-seq:Seq&Lengthable) : + wrap-length(rs, { min(length(xs-seq), length(ys-seq)) }) + else : rs public defn seq (f:(T,S,U) -> ?R, xs:Seqable, ys:Seqable, zs:Seqable) -> Seq : val xs-seq = to-seq(xs) val ys-seq = to-seq(ys) val zs-seq = to-seq(zs) - val rs = repeat-while $ fn () : - if empty?(xs-seq) or empty?(ys-seq) or empty?(zs-seq) : None() - else : One(f(next(xs-seq), next(ys-seq), next(zs-seq))) - match(xs-seq, ys-seq, zs-seq) : - (xs:Seq&Lengthable, ys:Seq&Lengthable, zs:Seq&Lengthable) : - wrap-length(rs, {cached(rs) + min(length(xs), min(length(ys), length(zs)))}) - (xs, ys, zs) : rs + val rs = new Seq : + defmethod next (this) : + f(next(xs-seq), next(ys-seq), next(zs-seq)) + defmethod done? (this) : + done?(xs-seq) or done?(ys-seq) or done?(zs-seq) + match(xs-seq:Seq&Lengthable, ys-seq:Seq&Lengthable, zs-seq:Seq&Lengthable) : + wrap-length(rs, { min(length(xs-seq), min(length(ys-seq), length(zs-seq))) }) + else: rs public defmulti in-reverse (xs:Seqable) -> Seq defmethod in-reverse (xs:Seqable) : @@ -7443,8 +7437,29 @@ public defn split! (xs:Seqable, ss:Seqable) -> [Collection <: Seq +public defmulti peek (s:PeekSeq) -> T + +public defn PeekSeq (xs-seq:Seq) -> PeekSeq : + var item:Sentinel|T = sentinel + defn fill () : (item = next(xs-seq)) when item is Sentinel + new PeekSeq : + defmethod next (this) : + val x = peek(this) + item = sentinel + x + defmethod peek (this) : + fill() + item as T + defmethod done? (this) : + done?(xs-seq) and item is Sentinel + +public defn to-peek-seq (xs:Seqable) -> PeekSeq : + match(xs:PeekSeq) : xs + else: PeekSeq $ to-seq $ xs + public defn split (f:T -> True|False, xs-items:Seqable) -> [Seq, Seq] : - val xs = to-seq(xs-items) + val xs = to-peek-seq(xs-items) val a-items = Queue() val b-items = Queue() @@ -7457,7 +7472,7 @@ public defn split (f:T -> True|False, xs-items:Seqable) -> [Seq, Seq< ;Try to fill a queue, returns true if filled defn* fill (items:Queue) -> True|False : if empty?(items) : - if not empty?(xs) : + if not done?(xs) : pull() fill(items) else : @@ -7467,12 +7482,9 @@ public defn split (f:T -> True|False, xs-items:Seqable) -> [Seq, Seq< defn queue-seq (items:Queue) : new Seq : defmethod next (this) : - if fill(items) : pop(items) - else : fatal("No more items") - defmethod peek (this) : - if fill(items) : peek(items) - else : fatal("No more items") - defmethod empty? (this) : + fill(items) + pop(items) + defmethod done? (this) : not fill(items) [queue-seq(a-items), queue-seq(b-items)] @@ -7491,11 +7503,8 @@ public defn fork (xs-items:Seqable) -> [Seq, Seq] : x else : pop(items) - defmethod peek (this) : - if empty?(items) : peek(xs) - else : peek(items) - defmethod empty? (this) : - empty?(items) and empty?(xs) + defmethod done? (this) : + empty?(items) and done?(xs) [queue-seq(a-items, b-items), queue-seq(b-items, a-items)] @@ -7517,33 +7526,29 @@ public defn fork (xs-items:Seqable, n:Int) -> Tuple> : defmethod next (this) : if empty?(items) : pull(i) else : pop(items) - defmethod peek (this) : - if empty?(items) : peek(xs) - else : peek(items) - defmethod empty? (this) : - empty?(items) and empty?(xs) + defmethod done? (this) : + empty?(items) and done?(xs) public defn take-while (f: T -> True|False, xs:Seqable) : - generate : - for xs-seq in xs do-seq : - defn* loop () : - if not empty?(xs-seq) : - val x = peek(xs-seq) - if f(x) : - next(xs-seq) - yield(x) - loop() - loop() - + generate : + val xs-seq = to-peek-seq(xs) + let loop () : + if not done?(xs-seq) : + val x = peek(xs-seq) + if f(x) : + next(xs-seq) + yield(x) + loop() + public defn take-until (f: T -> True|False, xs:Seqable) : generate : - for xs-seq in xs do-seq : - defn* loop () : - if not empty?(xs-seq) : - val x = next(xs-seq) - yield(x) - loop() when not f(x) - loop() + val xs-seq = to-seq(xs) + for xs-seq in xs do-seq : + let loop () : + if not done?(xs-seq) : + val x = next(xs-seq) + yield(x) + loop() when not f(x) public defn take-n (n:Int, xs:Seqable) : ensure-non-negative("length", n) @@ -7551,14 +7556,10 @@ public defn take-n (n:Int, xs:Seqable) : val xs-seq = to-seq(xs) new Seq & Lengthable : defmethod next (this) : - val v = peek(this) - next(xs-seq) + val v = next(xs-seq) len = len - 1 v - defmethod peek (this) : - fatal("Empty Sequence") when len == 0 - peek(xs-seq) - defmethod empty? (this) : + defmethod done? (this) : len == 0 defmethod length (this) : len @@ -7570,47 +7571,37 @@ public defn take-up-to-n (n:Int, xs:Seqable) : var len = n val xs-seq = to-seq(xs) new Seq : - defmethod next (this) : - val v = peek(this) - next(xs-seq) - len = len - 1 - v - defmethod peek (this) : - fatal("Empty Sequence") when empty?(this) - peek(xs-seq) - defmethod empty? (this) : - (len == 0) or empty?(xs-seq) - defmethod free (this) : - free(xs-seq) + defmethod next (this) : + len = len - 1 + next(xs-seq) + defmethod done? (this) : + (len == 0) or done?(xs-seq) + defmethod free (this) : + free(xs-seq) public defn cat (a:Seqable, b:Seqable) -> Seq : cat-all([a, b]) public defn cat-all (input-xss:Seqable>) -> Seq : val xss = to-seq(input-xss) - var xs:Seq|False|Sentinel = sentinel - defn* load-next-seq () : - if empty?(xss) : - xs = false - else : - xs = to-seq(next(xss)) - fill() - defn* fill () -> Seq|False : - match(xs) : - (xs:False) : false - (xs:Seq) : load-next-seq() when empty?(xs) else xs - (xs:Sentinel) : load-next-seq() - defn fill! () : - match(fill()) : - (xs:Seq) : xs - (xs:False) : fatal("Empty Sequence") + var xs:Seq|False = false + ;Advance to first non done? seq and return if any available + defn ready? () : + let loop () : + if xs is False or done?(xs as Seq) : + if done?(xss) : + false + else : + xs = to-seq(next(xss)) + loop() + else : + true new Seq : defmethod next (this) : - next(fill!()) - defmethod peek (this) : - peek(fill!()) - defmethod empty? (this) : - fill() is False + ready?() + next(xs as Seq) + defmethod done? (this) : + not ready?() defmethod free (this) : match(xs:Seq) : free(xs) free(xss) @@ -7627,27 +7618,24 @@ public defn seq-cat (f:(T,S,U) -> Seqable, xs:Seqable, ys:S public defn all? (pred?: T -> True|False, xs:Seqable) -> True|False : for xs-seq in xs do-seq : - defn* loop () : - if empty?(xs-seq) : true + let loop () : + if done?(xs-seq) : true else : pred?(next(xs-seq)) and loop() - loop() public defn all? (pred?: (T,S) -> True|False, xs:Seqable, ys:Seqable) -> True|False : for xs-seq in xs do-seq : for ys-seq in ys do-seq : - defn* loop () : - if empty?(xs-seq) or empty?(ys-seq) : true + let loop () : + if done?(xs-seq) or done?(ys-seq) : true else : pred?(next(xs-seq), next(ys-seq)) and loop() - loop() public defn all? (pred?: (T,S,U) -> True|False, xs:Seqable, ys:Seqable, zs:Seqable) -> True|False : for xs-seq in xs do-seq : for ys-seq in ys do-seq : for zs-seq in zs do-seq : - defn* loop () : - if empty?(xs-seq) or empty?(ys-seq) or empty?(zs-seq) : true + let loop () : + if done?(xs-seq) or done?(ys-seq) or done?(zs-seq) : true else : pred?(next(xs-seq), next(ys-seq), next(zs-seq)) and loop() - loop() public defn none? (pred?: T -> True|False, xs:Seqable) -> True|False : defn notp (x) : not pred?(x) @@ -7691,15 +7679,11 @@ public defn join (xs0:Seqable, y:?S) -> Seq : var join? = false val rs = new Seq : defmethod next (this) : - fatal("Empty Sequence") when empty?(xs) val result = y when join? else next(xs) join? = not join? result - defmethod peek (this) : - fatal("Empty Sequence") when empty?(xs) - y when join? else peek(xs) - defmethod empty? (this) : - empty?(xs) + defmethod done? (this) : + done?(xs) match(xs) : (xs:Seq & Lengthable) : defn rs-length () : @@ -7714,15 +7698,12 @@ public defn interleave (xs0:Seqable, ys0:Seqable) -> Seq : var yield-x? = true val rs = new Seq : defmethod next (this) : - fatal("Empty Sequence") when empty?(this) + ensure-not-done(this) val result = next(xs) when yield-x? else next(ys) yield-x? = not yield-x? result - defmethod peek (this) : - fatal("Empty Sequence") when empty?(this) - peek(xs) when yield-x? else peek(ys) - defmethod empty? (this) : - empty?(xs) when yield-x? else empty?(ys) + defmethod done? (this) : + done?(xs) when yield-x? else done?(ys) match(xs, ys) : (xs:Seq & Lengthable, ys:Seq & Lengthable) : defn rs-length () : @@ -7744,35 +7725,31 @@ public defn reduce (f: (T|S, T) -> ?S, xs:Seqable) -> T|S : public defn reduce-right (f: (S, T) -> ?T, xs:Seqable, xn:?T) -> T : for xs-seq in xs do-seq : defn loop () : - if empty?(xs-seq) : xn + if done?(xs-seq) : xn else : f(next(xs-seq), loop()) loop() public defn reduce-right (f: (T, T|S) -> ?S, xs:Seqable) -> T|S : for xs-seq in xs do-seq : defn loop (x:T) : - if empty?(xs-seq) : x + if done?(xs-seq) : x else : f(x, loop(next(xs-seq))) loop(next(xs-seq)) public defn repeat (x:?T) -> Seq : new Seq : defmethod next (this) : x - defmethod peek (this) : x - defmethod empty? (this) : false + defmethod done? (this) : false public defn repeat (x:?T, n:Int) : ensure-non-negative("length", n) var len = n new Seq & Lengthable : defmethod next (this) : - fatal("Empty Sequence") when len == 0 + ensure-not-done(this) len = len - 1 x - defmethod peek (this) : - fatal("Empty Sequence") when len == 0 - x - defmethod empty? (this) : + defmethod done? (this) : len == 0 defmethod length (this) : len @@ -7786,35 +7763,21 @@ public defn repeat-while (f: () -> Maybe) -> RepeatWhileSeq : new RepeatWhileSeq : defmethod next (this) : - val x = peek(this) + fill() + val x = item item = sentinel - x - defmethod peek (this) : - fatal("Empty Sequence") when empty?(this) - value(item as One) - defmethod empty? (this) : + value(x as One) + defmethod done? (this) : fill() item is None defmethod cached (this) : 1 when item is One else 0 public defn repeatedly (f:() -> ?T) -> Seq : - var item = sentinel - defn fill () : (item = f()) when item is Sentinel - - defn empty () : - val x = item as T - item = sentinel - x - new Seq : defmethod next (this) : - fill() - empty() - defmethod peek (this) : - fill() - item as T - defmethod empty? (this) : + f() + defmethod done? (this) : false public defn repeatedly (f:() -> ?T, n:Int) : @@ -7832,10 +7795,8 @@ public defn zip-all (xs:Seqable>) : val ret-seq = new Seq> : defmethod next (this) : map(next, seqs) - defmethod peek (this) : - map(peek, seqs) - defmethod empty? (this) : - any?(empty?, seqs) + defmethod done? (this) : + any?(done?, seqs) if all?({_ is Lengthable&Seq}, seqs) : val len = minimum{seq(length{_ as Lengthable&Seq}, seqs)} wrap-length(ret-seq, len) @@ -7901,7 +7862,7 @@ public defn fork-on-seq (xs:Seqable, f:Seq -> ?X, g:Seq -> ? gresult = resume(gco, v) (fresult is None) or (gresult is None) - if empty?(seq-xs) : + if done?(seq-xs) : run-fns(None()) else if run-fns(One(next(seq-xs))) : loop() @@ -7940,7 +7901,7 @@ public defn fork-on-seq (xs:Seqable, f:Seq -> ?X, g:Seq - (fresult is None) or (gresult is None) or (hresult is None) - if empty?(seq-xs) : + if done?(seq-xs) : run-fns(None()) else if run-fns(One(next(seq-xs))) : loop() @@ -7975,7 +7936,7 @@ public defn fork-on-seq (xs:Seqable, fs:Seqable<(Seq -> ?S)>) -> T more? = more? or (r is None) more? - if empty?(seq-xs) : + if done?(seq-xs) : run-fns(None()) else if run-fns(One(next(seq-xs))) : loop() @@ -8648,9 +8609,9 @@ defmethod write (o:OutputStream, x) : public defn write-all (o:OutputStream, xs:Seqable) -> False : val xs-seq = to-seq(xs) - if not empty?(xs-seq) : + if not done?(xs-seq) : write(o, next(xs-seq)) - while not empty?(xs-seq) : + while not done?(xs-seq) : print(o, " ") write(o, next(xs-seq)) diff --git a/core/parser.stanza b/core/parser.stanza index 76d5acd16..b50d1325d 100644 --- a/core/parser.stanza +++ b/core/parser.stanza @@ -1111,7 +1111,7 @@ defmulti num-indices (i:IndexPool) -> Int defmulti get (i:IndexPool, name:Symbol) -> Int defn IndexPool () : - val indices = to-seq(0 to false) + val indices = PeekSeq $ to-seq(0 to false) val binders = HashTable() new IndexPool : defmethod next (this, name:Symbol) : @@ -2062,4 +2062,4 @@ defmethod print (o:OutputStream, e:NoMatchException) : public defstruct NoSyntaxPackage <: PatternException : name: Symbol defmethod print (o:OutputStream, e:NoSyntaxPackage) : - print(o, "Could not resolve syntax package %~." % [name(e)]) \ No newline at end of file + print(o, "Could not resolve syntax package %~." % [name(e)]) diff --git a/core/reader.stanza b/core/reader.stanza index fe8b6b5cd..978ebd000 100644 --- a/core/reader.stanza +++ b/core/reader.stanza @@ -38,10 +38,10 @@ public defn read-lines (text:String) -> List : val lines = split(text, "\n") val prompter = new Prompter : defmethod get-line (this) : - if empty?(lines) : throw(ExpectingMoreInput()) + if done?(lines) : throw(ExpectingMoreInput()) else : next(lines) defmethod input-will-block? (this) : - empty?(lines) + done?(lines) read-line(prompter) as List defn input-stream-parser (s:ParseStream) : @@ -344,7 +344,7 @@ defn eat-escaped-chars (s:ParseStream, buf:StringBuffer) -> String|False : defn tokenize (s:ParseStream) : ;Generate tokens - generate : + PeekSeq $ generate : ;Eat until next non-ignored character. ;Whitespace and comments are ignored. ;Returns true if line contains comments. @@ -644,8 +644,8 @@ with: defstruct StackBottom <: StackCtxt -defn convert-indentations-to-structural-tokens (tokens:Seq) -> Seq : - generate : +defn convert-indentations-to-structural-tokens (tokens:PeekSeq) -> PeekSeq : + PeekSeq $ generate : ;Initialize stack val stack = Vector() add(stack, Token(StackBottom(), FileInfo("NoFile", 0, 0))) @@ -810,7 +810,7 @@ defn convert-indentations-to-structural-tokens (tokens:Seq) -> Seq ;Process all tokens in stream let loop () : - if not empty?(tokens) : + if not done?(tokens) : val done? = process(next(tokens)) loop() when not done? @@ -822,7 +822,7 @@ deftype Parser defmulti parse-list (p:Parser) -> List defmulti parse-1 (p:Parser) -> False|Token -defn Parser (s:Seq) -> Parser : +defn Parser (s:PeekSeq) -> Parser : ;Create shorthands defn shorthand (t:Token, v:List) : val item = item(t) as OpenToken @@ -843,7 +843,7 @@ defn Parser (s:Seq) -> Parser : ;Parse the next item in the sequence defn parse-next () -> Token|False : - if not empty?(s) : + if not done?(s) : val t = peek(s) match(item(t)) : (item:OpenToken) : @@ -1039,4 +1039,4 @@ defmethod print (o:OutputStream, e:ExpectingMoreInput) : public defn caused-by-incomplete-input? (e:LexerException) -> True|False : e is NoForm|NoEndTagFound|UnclosedCharString|UnclosedString|UnclosedSymbol| - NoClosingToken|ExpectingIndentedBlock|ExpectingMoreInput \ No newline at end of file + NoClosingToken|ExpectingIndentedBlock|ExpectingMoreInput From 7b478daea4c5df09a9a00b9e8d3507d8494f2c5f Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Wed, 22 Sep 2021 14:06:55 -0700 Subject: [PATCH 2/8] empty to done --- compiler/stz-arg-parser.stanza | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/stz-arg-parser.stanza b/compiler/stz-arg-parser.stanza index 21817cddb..78bfdc1f6 100644 --- a/compiler/stz-arg-parser.stanza +++ b/compiler/stz-arg-parser.stanza @@ -95,9 +95,9 @@ defn single? (f:Flag) : public defn parse-args (comms:Collection, default-comm:False|Command, args:Seqable) -> False : ;Get sequence of arguments - val args-seq = to-seq(args) + val args-seq = to-peek-seq(args) if default-comm is False : - throw(NoCommand()) when empty?(args-seq) + throw(NoCommand()) when done?(args-seq) ;Parse command name defn parse-command () : @@ -105,7 +105,7 @@ public defn parse-args (comms:Collection, default-comm:False|Command, a match(default-comm) : (c:Command) : c (c:False) : throw(NoCommand()) - if empty?(args-seq) : + if done?(args-seq) : use-default-comm() else : val cname = peek(args-seq) @@ -129,7 +129,7 @@ public defn parse-args (comms:Collection, default-comm:False|Command, a else : None() defn* parse-args () : - if not empty?(args-seq) : + if not done?(args-seq) : val arg = peek(args-seq) if flag?(arg) : parse-flag-args("") @@ -138,13 +138,13 @@ public defn parse-args (comms:Collection, default-comm:False|Command, a parse-args() defn* parse-flag-args (flag:String) : - if not empty?(args-seq) : + if not done?(args-seq) : val arg = next(args-seq) if flag?(arg) : val flag = arg[1 to false] throw(DuplicateFlag(flag)) when key?(flag-args, flag) if flag-eats-next?(flag) : - if not empty?(args-seq) : + if not done?(args-seq) : flag-args[flag] = List(next(args-seq)) parse-flag-args(flag) else : @@ -240,4 +240,4 @@ defmethod print (o:OutputStream, e:WrongArityFlag) : defmethod print (o:OutputStream, e:MissingFlag) : print(o, "Command %_ requires flag -%_." % [name(command(e)), name(flag(e))]) defmethod print (o:OutputStream, e:NoSuchFlag) : - print(o, "Command %_ does not recognize flag -%_." % [name(command(e)), flag(e)]) \ No newline at end of file + print(o, "Command %_ does not recognize flag -%_." % [name(command(e)), flag(e)]) From 9b542ee9ffd2de1da4f2b7bcc1c8680c86badc78 Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Wed, 22 Sep 2021 17:00:50 -0700 Subject: [PATCH 3/8] change done? back to empty? --- compiler/stz-build-manager.stanza | 2 +- compiler/stz-call-records.stanza | 10 +-- compiler/stz-core-macros.stanza | 2 +- compiler/stz-dispatch-dag.stanza | 6 +- compiler/stz-dl-ir.stanza | 2 +- compiler/stz-dyn-graph.stanza | 2 +- compiler/stz-el-ir.stanza | 2 +- compiler/stz-el-to-vm.stanza | 2 +- compiler/stz-el.stanza | 8 +- compiler/stz-front-end.stanza | 4 +- compiler/stz-hash.stanza | 2 +- compiler/stz-input.stanza | 2 +- compiler/stz-langs.stanza | 2 +- compiler/stz-proj.stanza | 4 +- compiler/stz-reg-alloc.stanza | 4 +- compiler/stz-repl.stanza | 4 +- compiler/stz-resolver.stanza | 6 +- compiler/stz-set-simplifier.stanza | 2 +- compiler/stz-set-utils.stanza | 4 +- compiler/stz-test-framework.stanza | 2 +- compiler/stz-type-calculus.stanza | 14 ++-- compiler/stz-type.stanza | 2 +- compiler/stz-utils.stanza | 2 +- compiler/stz-vm-encoder.stanza | 4 +- compiler/stz-vm-normalize.stanza | 14 ++-- compiler/stz-vm.stanza | 8 +- core/arg-parser.stanza | 6 +- core/core.stanza | 121 +++++++++++++++-------------- core/reader.stanza | 8 +- 29 files changed, 126 insertions(+), 125 deletions(-) diff --git a/compiler/stz-build-manager.stanza b/compiler/stz-build-manager.stanza index 2c60be459..cf283721d 100644 --- a/compiler/stz-build-manager.stanza +++ b/compiler/stz-build-manager.stanza @@ -102,7 +102,7 @@ defn colon-list (xs:Seqable) : new Printable : defmethod print (o:OutputStream, this) : val items = to-seq(xs) - if done?(items) : + if empty?(items) : print(o, ": ()") else : print(o, ":") diff --git a/compiler/stz-call-records.stanza b/compiler/stz-call-records.stanza index 45b09a555..a5b1777b7 100644 --- a/compiler/stz-call-records.stanza +++ b/compiler/stz-call-records.stanza @@ -77,13 +77,13 @@ public defn callc-records (a1:Tuple, a2:ArgType, backend:Backend) -> Ca for (x in a1, i in 0 to false) do : match(x) : (x:IntArg) : - if done?(reg-counter) : ;If no more integer registers + if empty?(reg-counter) : ;If no more integer registers std-arg(i, next-mem()) ; place in mem argument else : std-arg(i, next-reg()) ;Otherwise place in integer register next(freg-counter) ; and eat real register (x:RealArg) : - if done?(freg-counter) : ;If no more real registers + if empty?(freg-counter) : ;If no more real registers std-arg(i, next-mem()) ; place in mem argument else : std-arg(i, next-freg()) ;Otherwise place in real register @@ -92,10 +92,10 @@ public defn callc-records (a1:Tuple, a2:ArgType, backend:Backend) -> Ca for (x in a1, i in 0 to false) do : match(x) : (x:IntArg) : - if done?(reg-counter) : std-arg(i, next-mem()) + if empty?(reg-counter) : std-arg(i, next-mem()) else : std-arg(i, next-reg()) (x:RealArg) : - if done?(freg-counter) : std-arg(i, next-mem()) + if empty?(freg-counter) : std-arg(i, next-mem()) else : std-arg(i, next-freg()) ;Classify return value @@ -104,7 +104,7 @@ public defn callc-records (a1:Tuple, a2:ArgType, backend:Backend) -> Ca (a2:RealArg) : FRegLoc(callc-fret(backend), 0) ;Count number of args used - defn peek? (xs:PeekSeq, default:Int) : default when done?(xs) else peek(xs) + defn peek? (xs:PeekSeq, default:Int) : default when empty?(xs) else peek(xs) val num-int-args = peek?(reg-counter, length(callc-regs(backend))) val num-real-args = peek?(freg-counter, length(callc-fregs(backend))) val num-mem-args = peek(mem-counter) diff --git a/compiler/stz-core-macros.stanza b/compiler/stz-core-macros.stanza index fb67bc400..b2c9407ba 100644 --- a/compiler/stz-core-macros.stanza +++ b/compiler/stz-core-macros.stanza @@ -1135,7 +1135,7 @@ defsyntax core : defrule exp4 = (~ #for ?bs:#for-bindings #:! ?body) : val vals = map(to-seq{values(_)}, bs) val body* = to-list $ repeat-while $ fn () : - if all?(done?, vals) : + if all?(empty?, vals) : None() else : One{fill-template(body, _)} $ diff --git a/compiler/stz-dispatch-dag.stanza b/compiler/stz-dispatch-dag.stanza index 390ae1d63..f7c52c1e7 100644 --- a/compiler/stz-dispatch-dag.stanza +++ b/compiler/stz-dispatch-dag.stanza @@ -141,7 +141,7 @@ public defn union (args:Seqable) -> Arg : val nums = for arg in args seq : match(arg:Top) : return(arg) else : values(arg as Nums) - if done?(nums) : Nums([]) + if empty?(nums) : Nums([]) else : Nums $ to-tuple $ union(nums) public defn subarg-of-union? (x:Arg, ys:Seqable) : @@ -154,7 +154,7 @@ public defn subarg-of-union? (x:Arg, ys:Seqable) : public defn intersect (args:Seqable) -> Arg : val nums = seq(values, filter-by(args)) - if done?(nums) : Top() + if empty?(nums) : Top() else : Nums $ to-tuple $ intersect(nums) ;============================================================ @@ -294,7 +294,7 @@ defn topo-soln (input-solns:Tuple, btable:BranchTable) -> Soln : ;branches only amongst instance methods. val instance-solns = for s in input-solns filter : instance-branches(btable)[index(s as UniqueSoln)] - val solns = input-solns when done?(instance-solns) + val solns = input-solns when empty?(instance-solns) else to-tuple(instance-solns) ;Get the ids from the soln ids diff --git a/compiler/stz-dl-ir.stanza b/compiler/stz-dl-ir.stanza index 79c5e5e43..fb23f9bbf 100644 --- a/compiler/stz-dl-ir.stanza +++ b/compiler/stz-dl-ir.stanza @@ -517,7 +517,7 @@ defmethod print (o:OutputStream, x:PackageExports) : defn bprint (o:OutputStream, xs:Seqable) : val xs-seq = to-seq(xs) - if done?(xs-seq) : print(o, " ()") + if empty?(xs-seq) : print(o, " ()") else : lnprints(IndentedStream(o), xs-seq) ;============================================================ diff --git a/compiler/stz-dyn-graph.stanza b/compiler/stz-dyn-graph.stanza index d71f7e04f..d155160dc 100644 --- a/compiler/stz-dyn-graph.stanza +++ b/compiler/stz-dyn-graph.stanza @@ -183,7 +183,7 @@ defn merge (merger:Merger, xs:Seqable, ys:Seqable) : val ys-seq = to-peek-seq(ys) let loop () : - match(done?(xs-seq), done?(ys-seq)) : + match(empty?(xs-seq), empty?(ys-seq)) : (ex:True, ey:True) : false (ex:True, ey:False) : diff --git a/compiler/stz-el-ir.stanza b/compiler/stz-el-ir.stanza index f389cb615..c6b5523d4 100644 --- a/compiler/stz-el-ir.stanza +++ b/compiler/stz-el-ir.stanza @@ -673,7 +673,7 @@ defmethod print (o:OutputStream, t:ETVarLoc) : defn bprint (o:OutputStream, xs:Seqable) : val xs-seq = to-seq(xs) - if done?(xs-seq) : print(o, " ()") + if empty?(xs-seq) : print(o, " ()") else : lnprints(IndentedStream(o), xs-seq) ;============================================================ diff --git a/compiler/stz-el-to-vm.stanza b/compiler/stz-el-to-vm.stanza index cf3341e53..f609daf68 100644 --- a/compiler/stz-el-to-vm.stanza +++ b/compiler/stz-el-to-vm.stanza @@ -1364,7 +1364,7 @@ defn type-parts (t:EType, iotable:IOTable) -> Tuple : format(t, 0) to-tuple $ generate : - while not done?(parts) : + while not empty?(parts) : match(peek(parts)) : (v:ETVar): yield(next(parts)) diff --git a/compiler/stz-el.stanza b/compiler/stz-el.stanza index 52380ecd4..14ee622bf 100644 --- a/compiler/stz-el.stanza +++ b/compiler/stz-el.stanza @@ -556,7 +556,7 @@ defn create-closures (epackage:EPackage, gvt:VarTable) -> EPackage : if top? : do(emit{buffer, _}, uninitialized-trampolines()) val locs = seq(EVarLoc{n(_)}, uninitialized-trampolines()) - if not done?(locs) : + if not empty?(locs) : emit(buffer, EInitClosures(to-tuple(locs), false)) ;Emit instructions with added initializations for i in ins(body) do : @@ -1471,7 +1471,7 @@ defn simple-inline (epackage:EPackage) : emit(buffer, i) (i:EInitClosures) : val xs* = for x in xs(i) filter : not key?(inlined-functions, n(x)) - if not done?(xs*) : + if not empty?(xs*) : emit(buffer, EInitClosures(to-tuple(xs*), info(i))) (i) : emit(buffer, i) @@ -1868,7 +1868,7 @@ defn lambda-lift (epackage:EPackage, gvt:VarTable) : ;Add lifted type arguments to the given function immediate defn add-targs (e:EImm, free:Free) : defn curry (v:EVar, targs:Seq) : - if done?(targs) : v + if empty?(targs) : v else : ECurry(v, to-tuple(targs)) val free-targs = seq(ETVar, tvars(free)) match(e) : @@ -2804,7 +2804,7 @@ defn resolve-matches (epackage:EPackage, ehier:EHier, gvt:VarTable) -> EPackage defn union (input-ts:Seqable) : val ts = to-seq(input-ts) - if done?(ts) : EBot() + if empty?(ts) : EBot() else : reduce(EOr, ts) ;============================================================ diff --git a/compiler/stz-front-end.stanza b/compiler/stz-front-end.stanza index 191770924..81ea78844 100644 --- a/compiler/stz-front-end.stanza +++ b/compiler/stz-front-end.stanza @@ -415,12 +415,12 @@ defn FrontEnd (sys:FrontEndInputs) -> FrontEnd : val result = to-tuple $ for obj in objs seq? : match(obj) : (obj:IPackage) : - if done?(pkg-seq) : None() + if empty?(pkg-seq) : None() else if name(obj) == name(peek(pkg-seq)) : One(next(pkg-seq)) else : None() (obj:Pkg) : One(obj) - fatal("Mismatched packages.") when not done?(pkg-seq) + fatal("Mismatched packages.") when not empty?(pkg-seq) result ;---------------------------------------------------------- diff --git a/compiler/stz-hash.stanza b/compiler/stz-hash.stanza index 1a4ee5968..aa7745f50 100644 --- a/compiler/stz-hash.stanza +++ b/compiler/stz-hash.stanza @@ -117,7 +117,7 @@ public defn PerfectHashTable (entries0:Collection> & Length val dstamp = next(dcounter) val ks = to-seq(keys) let loop-k () : - if done?(ks) : + if empty?(ks) : d else : val k = next(ks) diff --git a/compiler/stz-input.stanza b/compiler/stz-input.stanza index 488237ccf..2d96de87e 100644 --- a/compiler/stz-input.stanza +++ b/compiler/stz-input.stanza @@ -303,7 +303,7 @@ defn split-packages (e:IExp, default-imports:Tuple) : ;Group packages val packages = Vector() - while not done?(eseq) : + while not empty?(eseq) : val pkg = match(peek(eseq)) : (e:IDefPackage) : next(eseq) diff --git a/compiler/stz-langs.stanza b/compiler/stz-langs.stanza index 1f2a058d6..d991c505b 100644 --- a/compiler/stz-langs.stanza +++ b/compiler/stz-langs.stanza @@ -865,7 +865,7 @@ defn compile (info:False|FileInfo, format:String, args:List) : break('\n') ;Assemble into pieces val pieces = repeat-while $ fn () : - if done?(parts) : + if empty?(parts) : None() else : match(peek(parts)) : diff --git a/compiler/stz-proj.stanza b/compiler/stz-proj.stanza index 556cdb58e..ecdb72dd4 100644 --- a/compiler/stz-proj.stanza +++ b/compiler/stz-proj.stanza @@ -895,14 +895,14 @@ defn separate (s:SplicedString) -> ProjValue : ;Join all pieces in the buffer val joined-buffer = Vector() val buffer-seq = to-seq(buffer) - while not done?(buffer-seq) : + while not empty?(buffer-seq) : ;Take until next separator val values = to-tuple $ take-while({_ is ProjValue}, buffer-seq) ;Add to joined buffer if length(values) == 1 : add(joined-buffer, values[0] as ProjValue) else : add(joined-buffer, SplicedString(info(s), values as Tuple)) ;Eat separator - next(buffer-seq) when not done?(buffer-seq) + next(buffer-seq) when not empty?(buffer-seq) ;Return cases if length(joined-buffer) == 1 : joined-buffer[0] diff --git a/compiler/stz-reg-alloc.stanza b/compiler/stz-reg-alloc.stanza index ec649b225..689c06b5f 100644 --- a/compiler/stz-reg-alloc.stanza +++ b/compiler/stz-reg-alloc.stanza @@ -1595,10 +1595,10 @@ defn register-assignment (blk:Block, b:Int, backend:Backend) : match(t) : (t:VMType&IntegerT) : val rs = free(reg-list) - Reg(next(rs)) when not done?(rs) + Reg(next(rs)) when not empty?(rs) (t:VMType&RealT) : val rs = free(freg-list) - FReg(next(rs)) when not done?(rs) + FReg(next(rs)) when not empty?(rs) defn available-reg? (t:VMType, pref:List) : val pref-regs = seq(XReg{t, _}, pref) val r = find({slot(_) is False}, pref-regs) diff --git a/compiler/stz-repl.stanza b/compiler/stz-repl.stanza index ded7f0329..d17f4e790 100644 --- a/compiler/stz-repl.stanza +++ b/compiler/stz-repl.stanza @@ -263,7 +263,7 @@ public defn REPL () : defn init-packages (input-names:Seqable) : val names = to-seq(input-names) let loop () : - if not done?(names) : + if not empty?(names) : val package-name = next(names) val success? = init-package(vm, package-name) throw(ReplHalt()) when not success? @@ -441,7 +441,7 @@ public defn REPL () : defmethod use-syntax (this, packages:Tuple, add-to-existing?:True|False) : ;Throw NoSyntaxPackage if any of the mentioned packages do not exist. val missing-packages = filter({not syntax-package-exists?(_)}, packages) - if not done?(missing-packages) : + if not empty?(missing-packages) : val es = seq(NoSyntaxPackage, missing-packages) throw(ReplErrors(to-tuple(es))) ;Clear syntaxes when not add to existing syntaxes. diff --git a/compiler/stz-resolver.stanza b/compiler/stz-resolver.stanza index a7b606399..4828886fe 100644 --- a/compiler/stz-resolver.stanza +++ b/compiler/stz-resolver.stanza @@ -221,7 +221,7 @@ defn check-exported-types (symtables:SymbolTables, pkgs:Collection, pe type(e) is TypeE|LTypeE and package(e) == package(symtable) val entries = filter(exported-type?, base(symtable, name(e))) - add(error-accum, MissingType(package(pex), e)) when done?(entries) + add(error-accum, MissingType(package(pex), e)) when empty?(entries) ;Recursively scan DItem for typeid defn scan-for-type (e:DItem) : do(scan-for-type, e) @@ -487,7 +487,7 @@ defn Engine (current-symtable:SymbolTable, ;Return type-appropriate entries defn return-pruned (es:Seqable) : val es* = filter(pred?, es) - if done?(es*) : throw(NoResolve(name(e), info(e))) + if empty?(es*) : throw(NoResolve(name(e), info(e))) else : to-list(prune-low-priority(es*)) ;Qualified form: /mysymbol @@ -508,7 +508,7 @@ defn Engine (current-symtable:SymbolTable, else : val es = for layer in current-symtable[name] first : val es* = filter(pred?, layer) - if done?(es*) : None() + if empty?(es*) : None() else : One(es*) if empty?(es) : throw(NoResolve(/name(e), info(e))) else : to-list(prune-low-priority(value!(es))) diff --git a/compiler/stz-set-simplifier.stanza b/compiler/stz-set-simplifier.stanza index 9a847d3e8..5467a9a9b 100644 --- a/compiler/stz-set-simplifier.stanza +++ b/compiler/stz-set-simplifier.stanza @@ -265,7 +265,7 @@ defn union-grouping-simplification (dnf:Union) -> Term|False : for v in conj-vars(term) do : var-counts[v] = var-counts[v] + 1 val vars = keys(var-counts) - if not done?(vars) : + if not empty?(vars) : val v = maximum({var-counts[_]}, vars) v when var-counts[v] > 1 diff --git a/compiler/stz-set-utils.stanza b/compiler/stz-set-utils.stanza index d69fe9233..69ec19002 100644 --- a/compiler/stz-set-utils.stanza +++ b/compiler/stz-set-utils.stanza @@ -50,7 +50,7 @@ public defn subset-of-union? (xs:Tuple, yss:Seqable>) -> True|Fa public defn union (a:Seqable, b:Seqable) -> Seq : generate : val [sa, sb] = [to-peek-seq(a), to-peek-seq(b)] - while not done?(sa) and not done?(sb) : + while not empty?(sa) and not empty?(sb) : val [ai, bj] = [peek(sa), peek(sb)] if ai < bj : yield(next(sa)) @@ -65,7 +65,7 @@ public defn union (a:Seqable, b:Seqable) -> Seq : public defn intersect (a:Seqable, b:Seqable) -> Seq : generate : val [sa, sb] = [to-peek-seq(a), to-peek-seq(b)] - while not done?(sa) and not done?(sb) : + while not empty?(sa) and not empty?(sb) : val [ai, bj] = [peek(sa), peek(sb)] if ai < bj : next(sa) diff --git a/compiler/stz-test-framework.stanza b/compiler/stz-test-framework.stanza index d3f14594c..bc9c0f449 100644 --- a/compiler/stz-test-framework.stanza +++ b/compiler/stz-test-framework.stanza @@ -444,7 +444,7 @@ protected defn print-test-report (exit-on-fail?:True|False) : ;First print failed tests val failed-tests = for t in records(s) filter : match(t:RanTest) : not passed?(t) - if not done?(failed-tests) : + if not empty?(failed-tests) : println(STANDARD-OUTPUT-STREAM, "\nFailed Tests:") do(println{STANDARD-OUTPUT-STREAM, _}, failed-tests) diff --git a/compiler/stz-type-calculus.stanza b/compiler/stz-type-calculus.stanza index d8b5491e9..a082dce7e 100644 --- a/compiler/stz-type-calculus.stanza +++ b/compiler/stz-type-calculus.stanza @@ -235,7 +235,7 @@ public defn or4 (x: True|Unknown|False|Possibly, y: True|Unknown|False|Possibly) public defn all4? (pred?: (T) -> True|Unknown|False|Possibly, xs:Seqable) : val s = to-seq(xs) defn loop () : - if done?(s) : true + if empty?(s) : true else : and4(pred?(next(s)), loop()) loop() @@ -243,14 +243,14 @@ public defn all4? (pred?: (S,T) -> True|Unknown|False|Possibly, xs:Seqabl val s = to-seq(xs) val t = to-seq(ys) defn loop () : - if done?(s) or done?(t) : true + if empty?(s) or empty?(t) : true else : and4(pred?(next(s), next(t)), loop()) loop() public defn any4? (pred?: (T) -> True|Unknown|False|Possibly, xs:Seqable) : val s = to-seq(xs) defn loop () : - if done?(s) : false + if empty?(s) : false else : or4(pred?(next(s)), loop()) loop() @@ -258,7 +258,7 @@ public defn any4? (pred?: (S,T) -> True|Unknown|False|Possibly, xs:Seqabl val s = to-seq(xs) val t = to-seq(ys) defn loop () : - if done?(s) or done?(t) : false + if empty?(s) or empty?(t) : false else : or4(pred?(next(s), next(t)), loop()) loop() @@ -447,7 +447,7 @@ defn flow-result (cn:Int, x:Type, y:Type) -> FlowResult : fl(type(x), type(y)) else : val rs = fl(parents(x, n(y)), y) - if done?(rs) : FFalse() + if empty?(rs) : FFalse() else : reduce(FOr, rs) (x:TTuple, y:TTuple) : if length(types(x)) == length(types(y)) : @@ -519,7 +519,7 @@ defn flow-result (cn:Int, defn ex (ts:List, r:LSType) : cat(ts, repeat(r)) defn ap (ts:List, r:LSType) : cat(ts, [r]) defn fand (fs:Seq) : - if done?(fs) : FFalse() + if empty?(fs) : FFalse() else : reduce(FAnd, fs) defn fall (xs:Seqable, ys:Seqable) : fand(seq(flow-result{cn, _, _}, xs, ys)) @@ -818,7 +818,7 @@ public defn mix (sel:List, ts:List) -> False| (s:Possibly) : combine!(remove-ret(t as TArrow)) (s:False) : false val fs = to-seq(values(funcs)) - reduce(TAnd, fs) when not done?(fs) + reduce(TAnd, fs) when not empty?(fs) ;In order for two LoStanza functions to be mixed, ;all arguments must be compatible. diff --git a/compiler/stz-type.stanza b/compiler/stz-type.stanza index b76a6cead..91566dd14 100644 --- a/compiler/stz-type.stanza +++ b/compiler/stz-type.stanza @@ -2686,7 +2686,7 @@ defn report-errors (nm:NameMap, ;Filter out low priority errors val filtered-errors = let : val hp = filter(high-priority{_, env, ls-env}, errors) - errors when done?(hp) else hp + errors when empty?(hp) else hp ;Throw Errors throw $ TypeErrors $ to-tuple $ for e in filtered-errors seq : diff --git a/compiler/stz-utils.stanza b/compiler/stz-utils.stanza index ee41c168f..9cde365c8 100644 --- a/compiler/stz-utils.stanza +++ b/compiler/stz-utils.stanza @@ -153,7 +153,7 @@ public defn to-bitmask (xs:Seqable) -> List : defn loop (accum:Long, len:Int) : if len == 64 : cons(accum, loop(0L, 0)) - else if not done?(sxs) : + else if not empty?(sxs) : val mark = bit(next(sxs)) << to-long(len) loop(accum + mark, len + 1) else if len > 0 : List(accum) diff --git a/compiler/stz-vm-encoder.stanza b/compiler/stz-vm-encoder.stanza index f06682e9d..b9615e0f5 100644 --- a/compiler/stz-vm-encoder.stanza +++ b/compiler/stz-vm-encoder.stanza @@ -319,8 +319,8 @@ public defn encode (func:VMFunction, v => value(e) let loop () : val e = next(es) - f(e, done?(es)) - loop() when not done?(es) + f(e, empty?(es)) + loop() when not empty?(es) ;Launch emit-dag(compute-dag()) diff --git a/compiler/stz-vm-normalize.stanza b/compiler/stz-vm-normalize.stanza index 590fd35d3..44d497ea1 100644 --- a/compiler/stz-vm-normalize.stanza +++ b/compiler/stz-vm-normalize.stanza @@ -1062,10 +1062,10 @@ defn ret-records (b:InsBuffer, xs:Seqable, backend:Backend) -> Ret else : x as VMType val loc = if integral?(t) : - if done?(regs) : next(mems) + if empty?(regs) : next(mems) else : next(regs) else : - if done?(fregs) : next(mems) + if empty?(fregs) : next(mems) else : next(fregs) match(x:Local) : add(records, RetRecord(x, loc)) @@ -1074,13 +1074,13 @@ defn ret-records (b:InsBuffer, xs:Seqable, backend:Backend) -> Ret defn retc-records (b:InsBuffer, xs0:Seqable, backend:Backend) -> RetRecords : val records = Vector() val xs = to-seq(xs0) - if not done?(xs) : + if not empty?(xs) : val x = next(xs) match(x:Local) : val t = type(b,x) if integral?(t) : add(records, RetRecord(x, CallReg(0))) else : add(records, RetRecord(x, CallFReg(0))) - if not done?(xs) : + if not empty?(xs) : fatal("More than a single C return value!") RetRecords(to-tuple(records)) @@ -1093,10 +1093,10 @@ defn call-records (b:InsBuffer, xs:Seqable, backend:Backend) -> CallRecor val t = type(b,x) val loc = if integral?(t) : - if done?(regs) : next(mems) + if empty?(regs) : next(mems) else : next(regs) else : - if done?(fregs) : next(mems) + if empty?(fregs) : next(mems) else : next(fregs) add(records,CallRecord(x, loc)) CallRecords(to-tuple(records)) @@ -1125,7 +1125,7 @@ defn match-records (xs:Seqable, backend:Backend) -> CallRecords : val regs = seq(CallReg, call-regs(backend)) val mems = seq(CallMemArg, 0 to false) for x in xs do : - if done?(regs) : rec(x, next(mems)) + if empty?(regs) : rec(x, next(mems)) else : rec(x, next(regs)) CallRecords(to-tuple(records)) diff --git a/compiler/stz-vm.stanza b/compiler/stz-vm.stanza index 8689b817c..c9496b62d 100644 --- a/compiler/stz-vm.stanza +++ b/compiler/stz-vm.stanza @@ -617,7 +617,7 @@ lostanza defn collect-garbage (vm:ref) -> long : ;Scan global roots val globals:ptr = vm.vmtable.globals.mem val roots = to-seq(roots(vm.vmtable.global-table)) - while done?(roots) == false : + while empty?(roots) == false : val i = next(roots).value globals[i] = post-gc-object(globals[i], vm) @@ -910,7 +910,7 @@ public lostanza defn compute-live (vm:ref, exclude:ref = vm.vmtable.globals.mem val roots = to-seq(roots(vm.vmtable.global-table, exclude)) - while done?(roots) == false : + while empty?(roots) == false : val i = next(roots).value mark-ref(globals[i]) @@ -1106,7 +1106,7 @@ defn class-names (cs:Seqable, ids:VMIds) -> Seqable, keep-existing-globals?:True|False) : - if not done?(to-seq(vmps)) : + if not empty?(to-seq(vmps)) : ;Precondition ensure-core-loaded-first!(vm, vmps) @@ -1194,7 +1194,7 @@ public lostanza defn clear-globals (vm:ref) -> ref : ;Scan global roots val globals:ptr = vm.vmtable.globals.mem val roots = to-seq(roots(vm.vmtable.global-table)) - while done?(roots) == false : + while empty?(roots) == false : val i = next(roots).value globals[i] = void-marker() return false diff --git a/core/arg-parser.stanza b/core/arg-parser.stanza index 228ede59e..2188ee6c6 100644 --- a/core/arg-parser.stanza +++ b/core/arg-parser.stanza @@ -165,7 +165,7 @@ defn parse-args-and-flags (flags:Tuple, arguments:Tuple) -> ;Read algorithm defn* eat-args () -> Tuple : val args = Vector() - while not done?(argseq) and + while not empty?(argseq) and not flag?(peek(argseq)) : add(args, next(argseq)) to-tuple(args) @@ -173,7 +173,7 @@ defn parse-args-and-flags (flags:Tuple, arguments:Tuple) -> ;Return all parsed flags defn eat-flags () -> Tuple : val flags = Vector() - while not done?(argseq) : + while not empty?(argseq) : val flagstr = next(argseq) fatal("Not a flag") when not flag?(flagstr) val flagname = flagstr[1 to false] @@ -201,7 +201,7 @@ defn parse-args-and-flags (flags:Tuple, arguments:Tuple) -> defn* eat-args-until-next-flag (first-arg-greedy?:True|False) -> Tuple : val args = Vector() let loop (greedy?:True|False = first-arg-greedy?) : - if not done?(argseq) : + if not empty?(argseq) : if greedy? or not flag?(peek(argseq)) : add(args, next(argseq)) loop(false) diff --git a/core/core.stanza b/core/core.stanza index c0a3f1167..ac605fc35 100644 --- a/core/core.stanza +++ b/core/core.stanza @@ -3162,9 +3162,9 @@ protected defn range-bound (s:Lengthable, r:Range) -> [Int, Int] : (e:Int, i:False) : [start(r), e] (e:False, i) : [start(r), length(s)] -protected defn ensure-not-done (xs:Seq) : +protected defn ensure-not-empty (xs:Seq) : #if-defined(OPTIMIZE) : - fatal("Next on done seq %_" % [xs]) when done?(xs) + fatal("Next on done seq %_" % [xs]) when empty?(xs) ;============================================================ ;===================== Hashable ============================= @@ -5170,7 +5170,7 @@ public lostanza defn append-all (xs:ref>) -> ref : val ret = String(len.value) val xs-seq = to-seq(xs) var accum : long = 0 - while done?(xs-seq) == false : + while empty?(xs-seq) == false : val s = next(xs-seq) copy(ret, s, accum) accum = accum + strlen(s) @@ -5394,7 +5394,7 @@ public defn append (xs:Seqable, ys:List) -> List : public defn append-all (xs:Seqable>) -> List : val xs-seq = to-seq(xs) defn loop () : - if done?(xs-seq) : List() + if empty?(xs-seq) : List() else : append(next(xs-seq), loop()) loop() @@ -5498,7 +5498,7 @@ public defn modulo (format:String, args:Seqable) -> Printable : print(o, c) loop(i + 1) else : - if not done?(seq) : + if not empty?(seq) : fatal("Unexpected end of format string %~. More arguments remaining." % [format]) loop(0) @@ -5605,7 +5605,7 @@ public defn Generator (thunk : (T -> False, (T -> Void) & (() -> Void)) -> ?) defmethod next (this) : fill() empty() - defmethod done? (this) : + defmethod empty? (this) : fill() defmethod free (this) : close(co) when open?(co) @@ -7078,7 +7078,7 @@ public defmulti to-seq (s:Seqable) -> Seq defmethod to-seq (s:Seq) : s public defmulti next (s:Seq) -> T -public defmulti done? (s:Seq) -> True|False +public defmulti empty? (s:Seq) -> True|False public defmulti free (s:Seq) -> False defmethod free (s:Seq) : false @@ -7103,10 +7103,10 @@ defmethod to-seq (s:String) : defmethod to-seq (x:List) : var l = x new Seq : - defmethod done? (this) : + defmethod empty? (this) : empty?(l) defmethod next (this) : - ensure-not-done(this) + ensure-not-empty(this) val x = head(l) l = tail(l) x @@ -7121,11 +7121,12 @@ defmethod to-seq (r:Range) : var n = length(r) new Seq & Lengthable : defmethod next (this) : + ensure-not-empty(this) val i* = i i = i + step(r) n = n - 1 i* - defmethod done? (this) : + defmethod empty? (this) : n == 0 defmethod length (this) : n @@ -7136,7 +7137,7 @@ defmethod to-seq (r:Range) : val i* = i i = i + step(r) i* - defmethod done? (this) : + defmethod empty? (this) : false ;===== Conversion from Sequence ===== @@ -7200,20 +7201,20 @@ public defmulti do (f:(T,S,U) -> ?, xs:Seqable, ys:Seqable, zs defmethod do (f:T -> ?, xs:Seqable) -> False : for xs-seq in xs do-seq : - while not done?(xs-seq) : + while not empty?(xs-seq) : f(next(xs-seq)) defmethod do (f:(T,S) -> ?, xs:Seqable, ys:Seqable) -> False : for xs-seq in xs do-seq : for ys-seq in ys do-seq : - while (not done?(xs-seq)) and (not done?(ys-seq)) : + while (not empty?(xs-seq)) and (not empty?(ys-seq)) : f(next(xs-seq), next(ys-seq)) defmethod do (f:(T,S,U) -> ?, xs:Seqable, ys:Seqable, zs:Seqable) -> False : for xs-seq in xs do-seq : for ys-seq in ys do-seq : for zs-seq in zs do-seq : - while (not done?(xs-seq)) and (not done?(ys-seq)) and (not done?(zs-seq)) : + while (not empty?(xs-seq)) and (not empty?(ys-seq)) and (not empty?(zs-seq)) : f(next(xs-seq), next(ys-seq), next(zs-seq)) ;Specialization @@ -7256,7 +7257,7 @@ defmethod do (f:T -> ?, xs:List) -> False : defn wrap-length (xs:Seq, length:() -> Int) : new Seq & Lengthable : defmethod next (this) : next(xs) - defmethod done? (this) : done?(xs) + defmethod empty? (this) : empty?(xs) defmethod length (this) : length() public defn to-collection (f:() -> Seq) -> Collection : @@ -7268,8 +7269,8 @@ public defn seq (f:T -> ?R, xs:Seqable) -> Seq : val rs = new Seq : defmethod next (this) : f(next(xs-seq)) - defmethod done? (this) : - done?(xs-seq) + defmethod empty? (this) : + empty?(xs-seq) match(xs-seq:Seq&Lengthable) : wrap-length(rs, { length(xs-seq) }) else : rs @@ -7279,8 +7280,8 @@ public defn seq (f:(T,S) -> ?R, xs:Seqable, ys:Seqable) -> Seq val rs = new Seq : defmethod next (this) : f(next(xs-seq), next(ys-seq)) - defmethod done? (this) : - done?(xs-seq) or done?(ys-seq) + defmethod empty? (this) : + empty?(xs-seq) or empty?(ys-seq) match(xs-seq:Seq&Lengthable, ys-seq:Seq&Lengthable) : wrap-length(rs, { min(length(xs-seq), length(ys-seq)) }) else : rs @@ -7292,8 +7293,8 @@ public defn seq (f:(T,S,U) -> ?R, xs:Seqable, ys:Seqable, z val rs = new Seq : defmethod next (this) : f(next(xs-seq), next(ys-seq), next(zs-seq)) - defmethod done? (this) : - done?(xs-seq) or done?(ys-seq) or done?(zs-seq) + defmethod empty? (this) : + empty?(xs-seq) or empty?(ys-seq) or empty?(zs-seq) match(xs-seq:Seq&Lengthable, ys-seq:Seq&Lengthable, zs-seq:Seq&Lengthable) : wrap-length(rs, { min(length(xs-seq), min(length(ys-seq), length(zs-seq))) }) else: rs @@ -7451,8 +7452,8 @@ public defn PeekSeq (xs-seq:Seq) -> PeekSeq : defmethod peek (this) : fill() item as T - defmethod done? (this) : - done?(xs-seq) and item is Sentinel + defmethod empty? (this) : + empty?(xs-seq) and item is Sentinel public defn to-peek-seq (xs:Seqable) -> PeekSeq : match(xs:PeekSeq) : xs @@ -7472,7 +7473,7 @@ public defn split (f:T -> True|False, xs-items:Seqable) -> [Seq, Seq< ;Try to fill a queue, returns true if filled defn* fill (items:Queue) -> True|False : if empty?(items) : - if not done?(xs) : + if not empty?(xs) : pull() fill(items) else : @@ -7484,7 +7485,7 @@ public defn split (f:T -> True|False, xs-items:Seqable) -> [Seq, Seq< defmethod next (this) : fill(items) pop(items) - defmethod done? (this) : + defmethod empty? (this) : not fill(items) [queue-seq(a-items), queue-seq(b-items)] @@ -7503,8 +7504,8 @@ public defn fork (xs-items:Seqable) -> [Seq, Seq] : x else : pop(items) - defmethod done? (this) : - empty?(items) and done?(xs) + defmethod empty? (this) : + empty?(items) and empty?(xs) [queue-seq(a-items, b-items), queue-seq(b-items, a-items)] @@ -7526,14 +7527,14 @@ public defn fork (xs-items:Seqable, n:Int) -> Tuple> : defmethod next (this) : if empty?(items) : pull(i) else : pop(items) - defmethod done? (this) : - empty?(items) and done?(xs) + defmethod empty? (this) : + empty?(items) and empty?(xs) public defn take-while (f: T -> True|False, xs:Seqable) : generate : val xs-seq = to-peek-seq(xs) let loop () : - if not done?(xs-seq) : + if not empty?(xs-seq) : val x = peek(xs-seq) if f(x) : next(xs-seq) @@ -7545,7 +7546,7 @@ public defn take-until (f: T -> True|False, xs:Seqable) : val xs-seq = to-seq(xs) for xs-seq in xs do-seq : let loop () : - if not done?(xs-seq) : + if not empty?(xs-seq) : val x = next(xs-seq) yield(x) loop() when not f(x) @@ -7559,7 +7560,7 @@ public defn take-n (n:Int, xs:Seqable) : val v = next(xs-seq) len = len - 1 v - defmethod done? (this) : + defmethod empty? (this) : len == 0 defmethod length (this) : len @@ -7574,8 +7575,8 @@ public defn take-up-to-n (n:Int, xs:Seqable) : defmethod next (this) : len = len - 1 next(xs-seq) - defmethod done? (this) : - (len == 0) or done?(xs-seq) + defmethod empty? (this) : + (len == 0) or empty?(xs-seq) defmethod free (this) : free(xs-seq) @@ -7585,11 +7586,11 @@ public defn cat (a:Seqable, b:Seqable) -> Seq : public defn cat-all (input-xss:Seqable>) -> Seq : val xss = to-seq(input-xss) var xs:Seq|False = false - ;Advance to first non done? seq and return if any available + ;Advance to first non empty? seq and return if any available defn ready? () : let loop () : - if xs is False or done?(xs as Seq) : - if done?(xss) : + if xs is False or empty?(xs as Seq) : + if empty?(xss) : false else : xs = to-seq(next(xss)) @@ -7600,7 +7601,7 @@ public defn cat-all (input-xss:Seqable>) -> Seq : defmethod next (this) : ready?() next(xs as Seq) - defmethod done? (this) : + defmethod empty? (this) : not ready?() defmethod free (this) : match(xs:Seq) : free(xs) @@ -7619,14 +7620,14 @@ public defn seq-cat (f:(T,S,U) -> Seqable, xs:Seqable, ys:S public defn all? (pred?: T -> True|False, xs:Seqable) -> True|False : for xs-seq in xs do-seq : let loop () : - if done?(xs-seq) : true + if empty?(xs-seq) : true else : pred?(next(xs-seq)) and loop() public defn all? (pred?: (T,S) -> True|False, xs:Seqable, ys:Seqable) -> True|False : for xs-seq in xs do-seq : for ys-seq in ys do-seq : let loop () : - if done?(xs-seq) or done?(ys-seq) : true + if empty?(xs-seq) or empty?(ys-seq) : true else : pred?(next(xs-seq), next(ys-seq)) and loop() public defn all? (pred?: (T,S,U) -> True|False, xs:Seqable, ys:Seqable, zs:Seqable) -> True|False : @@ -7634,7 +7635,7 @@ public defn all? (pred?: (T,S,U) -> True|False, xs:Seqable, ys:Seq for ys-seq in ys do-seq : for zs-seq in zs do-seq : let loop () : - if done?(xs-seq) or done?(ys-seq) or done?(zs-seq) : true + if empty?(xs-seq) or empty?(ys-seq) or empty?(zs-seq) : true else : pred?(next(xs-seq), next(ys-seq), next(zs-seq)) and loop() public defn none? (pred?: T -> True|False, xs:Seqable) -> True|False : @@ -7682,8 +7683,8 @@ public defn join (xs0:Seqable, y:?S) -> Seq : val result = y when join? else next(xs) join? = not join? result - defmethod done? (this) : - done?(xs) + defmethod empty? (this) : + empty?(xs) match(xs) : (xs:Seq & Lengthable) : defn rs-length () : @@ -7698,12 +7699,12 @@ public defn interleave (xs0:Seqable, ys0:Seqable) -> Seq : var yield-x? = true val rs = new Seq : defmethod next (this) : - ensure-not-done(this) + ensure-not-empty(this) val result = next(xs) when yield-x? else next(ys) yield-x? = not yield-x? result - defmethod done? (this) : - done?(xs) when yield-x? else done?(ys) + defmethod empty? (this) : + empty?(xs) when yield-x? else empty?(ys) match(xs, ys) : (xs:Seq & Lengthable, ys:Seq & Lengthable) : defn rs-length () : @@ -7725,31 +7726,31 @@ public defn reduce (f: (T|S, T) -> ?S, xs:Seqable) -> T|S : public defn reduce-right (f: (S, T) -> ?T, xs:Seqable, xn:?T) -> T : for xs-seq in xs do-seq : defn loop () : - if done?(xs-seq) : xn + if empty?(xs-seq) : xn else : f(next(xs-seq), loop()) loop() public defn reduce-right (f: (T, T|S) -> ?S, xs:Seqable) -> T|S : for xs-seq in xs do-seq : defn loop (x:T) : - if done?(xs-seq) : x + if empty?(xs-seq) : x else : f(x, loop(next(xs-seq))) loop(next(xs-seq)) public defn repeat (x:?T) -> Seq : new Seq : defmethod next (this) : x - defmethod done? (this) : false + defmethod empty? (this) : false public defn repeat (x:?T, n:Int) : ensure-non-negative("length", n) var len = n new Seq & Lengthable : defmethod next (this) : - ensure-not-done(this) + ensure-not-empty(this) len = len - 1 x - defmethod done? (this) : + defmethod empty? (this) : len == 0 defmethod length (this) : len @@ -7767,7 +7768,7 @@ public defn repeat-while (f: () -> Maybe) -> RepeatWhileSeq : val x = item item = sentinel value(x as One) - defmethod done? (this) : + defmethod empty? (this) : fill() item is None defmethod cached (this) : @@ -7777,7 +7778,7 @@ public defn repeatedly (f:() -> ?T) -> Seq : new Seq : defmethod next (this) : f() - defmethod done? (this) : + defmethod empty? (this) : false public defn repeatedly (f:() -> ?T, n:Int) : @@ -7795,8 +7796,8 @@ public defn zip-all (xs:Seqable>) : val ret-seq = new Seq> : defmethod next (this) : map(next, seqs) - defmethod done? (this) : - any?(done?, seqs) + defmethod empty? (this) : + any?(empty?, seqs) if all?({_ is Lengthable&Seq}, seqs) : val len = minimum{seq(length{_ as Lengthable&Seq}, seqs)} wrap-length(ret-seq, len) @@ -7862,7 +7863,7 @@ public defn fork-on-seq (xs:Seqable, f:Seq -> ?X, g:Seq -> ? gresult = resume(gco, v) (fresult is None) or (gresult is None) - if done?(seq-xs) : + if empty?(seq-xs) : run-fns(None()) else if run-fns(One(next(seq-xs))) : loop() @@ -7901,7 +7902,7 @@ public defn fork-on-seq (xs:Seqable, f:Seq -> ?X, g:Seq - (fresult is None) or (gresult is None) or (hresult is None) - if done?(seq-xs) : + if empty?(seq-xs) : run-fns(None()) else if run-fns(One(next(seq-xs))) : loop() @@ -7936,7 +7937,7 @@ public defn fork-on-seq (xs:Seqable, fs:Seqable<(Seq -> ?S)>) -> T more? = more? or (r is None) more? - if done?(seq-xs) : + if empty?(seq-xs) : run-fns(None()) else if run-fns(One(next(seq-xs))) : loop() @@ -8609,9 +8610,9 @@ defmethod write (o:OutputStream, x) : public defn write-all (o:OutputStream, xs:Seqable) -> False : val xs-seq = to-seq(xs) - if not done?(xs-seq) : + if not empty?(xs-seq) : write(o, next(xs-seq)) - while not done?(xs-seq) : + while not empty?(xs-seq) : print(o, " ") write(o, next(xs-seq)) diff --git a/core/reader.stanza b/core/reader.stanza index 978ebd000..82267facf 100644 --- a/core/reader.stanza +++ b/core/reader.stanza @@ -38,10 +38,10 @@ public defn read-lines (text:String) -> List : val lines = split(text, "\n") val prompter = new Prompter : defmethod get-line (this) : - if done?(lines) : throw(ExpectingMoreInput()) + if empty?(lines) : throw(ExpectingMoreInput()) else : next(lines) defmethod input-will-block? (this) : - done?(lines) + empty?(lines) read-line(prompter) as List defn input-stream-parser (s:ParseStream) : @@ -810,7 +810,7 @@ defn convert-indentations-to-structural-tokens (tokens:PeekSeq) -> PeekSe ;Process all tokens in stream let loop () : - if not done?(tokens) : + if not empty?(tokens) : val done? = process(next(tokens)) loop() when not done? @@ -843,7 +843,7 @@ defn Parser (s:PeekSeq) -> Parser : ;Parse the next item in the sequence defn parse-next () -> Token|False : - if not done?(s) : + if not empty?(s) : val t = peek(s) match(item(t)) : (item:OpenToken) : From 466d767624586c09480c15b27a3b79786a42cd5e Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Wed, 22 Sep 2021 17:16:22 -0700 Subject: [PATCH 4/8] add tests for seqs and clean up fatal message --- core/core.stanza | 2 +- tests/test-seqs.stanza | 194 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 tests/test-seqs.stanza diff --git a/core/core.stanza b/core/core.stanza index ac605fc35..d4229b11f 100644 --- a/core/core.stanza +++ b/core/core.stanza @@ -3164,7 +3164,7 @@ protected defn range-bound (s:Lengthable, r:Range) -> [Int, Int] : protected defn ensure-not-empty (xs:Seq) : #if-defined(OPTIMIZE) : - fatal("Next on done seq %_" % [xs]) when empty?(xs) + fatal("Next on empty seq %_" % [xs]) when empty?(xs) ;============================================================ ;===================== Hashable ============================= diff --git a/tests/test-seqs.stanza b/tests/test-seqs.stanza new file mode 100644 index 000000000..e4f558db7 --- /dev/null +++ b/tests/test-seqs.stanza @@ -0,0 +1,194 @@ +defpackage stz/test-seqs : + import core + import collections + +defn same? (name:String, a:Equalable, b:Equalable) : + ; println(" %_: %_ =? %_" % [name, a, b]) + if a != b : + println(" %_: %_ != %_" % [name, a, b]) + +defstruct Check : + name: String + run: String -> True|False + +defstruct Test : + name: String + init: Test -> ? + checks: Vector with: (init => Vector()) + +val tests = Vector() + +defn install-test (test:Test) : + init(test)(test) + add(tests, test) + +install-test $ Test("TUPLE", fn (test:Test) : + val i = [1, 2, 3] + val r = to-tuple $ to-seq $ i + add(checks(test), Check("E", same?{_, r, i})) + ) + +install-test $ Test("LIST", fn (test:Test) : + val i = [1, 2, 3] + val r = to-tuple $ to-seq $ to-list $ i + add(checks(test), Check("E", same?{_, r, i})) + ) + +install-test $ Test("RANGE", fn (test:Test) : + val i = 0 to 3 + val o = [0, 1, 2] + val r = to-tuple $ i + add(checks(test), Check("E", same?{_, r, o})) + ) + +install-test $ Test("VECTOR", fn (test:Test) : + val i = Vector() + add(i, 0) + add(i, 1) + add(i, 2) + val o = [0, 1, 2] + val r = to-tuple $ i + add(checks(test), Check("E", same?{_, r, o})) + ) + +install-test $ Test("SEQ-1", fn (test:Test) : + val xs = seq({ _ + 1 }, [1, 2, 3]) + add(checks(test), Check("A", same?{_, next(xs), 2})) + add(checks(test), Check("B", same?{_, next(xs), 3})) + add(checks(test), Check("C", same?{_, next(xs), 4})) + add(checks(test), Check("D", same?{_, empty?(xs), true})) + ) + +install-test $ Test("SEQ-2", fn (test:Test) : + val xs = seq(plus, [1, 2, 3], [2, 3, 4]) + add(checks(test), Check("A", same?{_, next(xs), 3})) + add(checks(test), Check("B", same?{_, next(xs), 5})) + add(checks(test), Check("C", same?{_, next(xs), 7})) + add(checks(test), Check("D", same?{_, empty?(xs), true})) + ) + +install-test $ Test("SEQ-3", fn (test:Test) : + val xs = seq(fn (a, b, c): a + b + c, [1, 2, 3], [2, 3, 4], [3, 4, 5]) + add(checks(test), Check("A", same?{_, next(xs), 6})) + add(checks(test), Check("B", same?{_, next(xs), 9})) + add(checks(test), Check("C", same?{_, next(xs), 12})) + add(checks(test), Check("D", same?{_, empty?(xs), true})) + ) + +install-test $ Test("SEQ-TO-TUPLE", fn (test:Test) : + val xs = seq({ _ + 1 }, [1, 2, 3]) + add(checks(test), Check("A", same?{_, to-tuple(xs), [2, 3, 4]})) + add(checks(test), Check("B", same?{_, empty?(xs), true})) + ) + +install-test $ Test("PEEK-SEQ-1", fn (test:Test) : + val i = [1, 2, 3] + val xs = to-peek-seq $ i + add(checks(test), Check("A", same?{_, peek(xs), 1})) + add(checks(test), Check("B", same?{_, next(xs), 1})) + add(checks(test), Check("C", same?{_, next(xs), 2})) + add(checks(test), Check("D", same?{_, next(xs), 3})) + add(checks(test), Check("D", same?{_, empty?(xs), true})) + ) + +install-test $ Test("TAKE-WHILE", fn (test:Test) : + val i = [1, 2, 3] + val xs = to-peek-seq $ i + val os = take-while({ _ < 3 }, xs) + add(checks(test), Check("A", same?{_, to-tuple(os), [1, 2]})) + add(checks(test), Check("B", same?{_, to-tuple(xs), [3]})) + ) + +install-test $ Test("TAKE-UNTIL", fn (test:Test) : + val i = [1, 2, 3] + val xs = to-peek-seq $ i + val os = take-until({ _ > 2 }, xs) + add(checks(test), Check("A", same?{_, to-tuple(os), [1, 2]})) + add(checks(test), Check("B", same?{_, to-tuple(xs), [3]})) + ) + +install-test $ Test("TAKE-N", fn (test:Test) : + val i = [1, 2, 3] + val xs = (to-seq $ i) as Seq&Lengthable + val os = take-n(2, xs) + add(checks(test), Check("A", same?{_, to-tuple(os), [1, 2]})) + add(checks(test), Check("B", same?{_, to-tuple(xs), [3]})) + ) + +install-test $ Test("TAKE-UP-TO-N", fn (test:Test) : + val i = [1, 2, 3] + val xs = to-seq $ i + val os = take-up-to-n(2, xs) + add(checks(test), Check("A", same?{_, to-tuple(os), [1, 2]})) + add(checks(test), Check("B", same?{_, to-tuple(xs), [3]})) + ) + +install-test $ Test("CAT", fn (test:Test) : + val a = [1, 2, 3] + val b = [4, 5, 6] + val r = [1, 2, 3, 4, 5, 6] + val os = cat(a, b) + add(checks(test), Check("A", same?{_, to-tuple(os), r})) + ) + +install-test $ Test("CAT-ALL", fn (test:Test) : + val a1 = [1, 2, 3] + val b1 = [4, 5, 6] + val c1 = [7, 8, 9] + val r1 = [1, 2, 3, 4, 5, 6, 7, 8, 9] + val os1 = cat-all $ [a1, b1, c1] + add(checks(test), Check("A", same?{_, to-tuple(os1), r1})) + val a2 = [1, 2, 3] + val b2 = [] + val c2 = [4, 5, 6] + val r2 = [1, 2, 3, 4, 5, 6] + val os2 = cat-all $ [a2, b2, c2] + add(checks(test), Check("B", same?{_, to-tuple(os2), r2})) + val a3 = [] + val b3 = [] + val c3 = [1, 2, 3] + val r3 = [1, 2, 3] + val os3 = cat-all $ [a3, b3, c3] + add(checks(test), Check("C", same?{_, to-tuple(os3), r3})) + val a4 = [] + val b4 = [] + val c4 = [] + val r4 = [] + val os4 = cat-all $ [a4, b4, c4] + add(checks(test), Check("D", same?{_, to-tuple(os4), r4})) + ) + +install-test $ Test("JOIN", fn (test:Test) : + val a = [1, 2, 3] + val r = [1, 0, 2, 0, 3] + val os = join(a, 0) + add(checks(test), Check("A", same?{_, to-tuple(os), r})) + ) + +install-test $ Test("INTERLEAVE", fn (test:Test) : + val a1 = [1, 2, 3] + val b1 = [4, 5, 6] + val r1 = [1, 4, 2, 5, 3, 6] + val os1 = interleave(a1, b1) + add(checks(test), Check("A", same?{_, to-tuple(os1), r1})) + val a2 = [1, 2, 3] + val b2 = [4, 5] + val r2 = [1, 4, 2, 5] + val os2 = interleave(a2, b2) + add(checks(test), Check("B", same?{_, to-tuple(os2), r2})) + ) + +install-test $ Test("REPEAT", fn (test:Test) : + val r = [1, 1, 1] + val os = repeat(1, 3) + add(checks(test), Check("A", same?{_, to-tuple(os), r})) + ) + +defn run-all-tests () : + for test in tests do : + println("RUNNING %_ TEST" % [name(test)]) + for check in checks(test) do : + ; println(" RUNNING %_ CHECK" % [name(check)]) + run(check)(name(check)) + +run-all-tests() From daf43f2e5e5d16e016b5e11071dc1f963a89d26e Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Thu, 23 Sep 2021 06:27:14 -0700 Subject: [PATCH 5/8] change back to empty --- compiler/stz-arg-parser.stanza | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/stz-arg-parser.stanza b/compiler/stz-arg-parser.stanza index 78bfdc1f6..fb6a29397 100644 --- a/compiler/stz-arg-parser.stanza +++ b/compiler/stz-arg-parser.stanza @@ -97,7 +97,7 @@ public defn parse-args (comms:Collection, default-comm:False|Command, a ;Get sequence of arguments val args-seq = to-peek-seq(args) if default-comm is False : - throw(NoCommand()) when done?(args-seq) + throw(NoCommand()) when empty?(args-seq) ;Parse command name defn parse-command () : @@ -105,7 +105,7 @@ public defn parse-args (comms:Collection, default-comm:False|Command, a match(default-comm) : (c:Command) : c (c:False) : throw(NoCommand()) - if done?(args-seq) : + if empty?(args-seq) : use-default-comm() else : val cname = peek(args-seq) @@ -129,7 +129,7 @@ public defn parse-args (comms:Collection, default-comm:False|Command, a else : None() defn* parse-args () : - if not done?(args-seq) : + if not empty?(args-seq) : val arg = peek(args-seq) if flag?(arg) : parse-flag-args("") @@ -138,13 +138,13 @@ public defn parse-args (comms:Collection, default-comm:False|Command, a parse-args() defn* parse-flag-args (flag:String) : - if not done?(args-seq) : + if not empty?(args-seq) : val arg = next(args-seq) if flag?(arg) : val flag = arg[1 to false] throw(DuplicateFlag(flag)) when key?(flag-args, flag) if flag-eats-next?(flag) : - if not done?(args-seq) : + if not empty?(args-seq) : flag-args[flag] = List(next(args-seq)) parse-flag-args(flag) else : From 1412b22057b587cba894fc9b5238f1b622a52e8a Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Thu, 23 Sep 2021 06:49:52 -0700 Subject: [PATCH 6/8] remove extra newlines --- compiler/stz-build-manager.stanza | 2 +- compiler/stz-front-end.stanza | 2 +- compiler/stz-hash.stanza | 2 +- compiler/stz-langs.stanza | 5 +---- compiler/stz-proj.stanza | 2 +- compiler/stz-reg-alloc.stanza | 2 +- compiler/stz-repl.stanza | 2 +- compiler/stz-set-utils.stanza | 2 +- compiler/stz-test-framework.stanza | 2 +- compiler/stz-type-calculus.stanza | 2 +- compiler/stz-vm-encoder.stanza | 2 +- compiler/stz-vm-normalize.stanza | 3 +-- core/parser.stanza | 2 +- core/reader.stanza | 2 +- 14 files changed, 14 insertions(+), 18 deletions(-) diff --git a/compiler/stz-build-manager.stanza b/compiler/stz-build-manager.stanza index cf283721d..da2f07414 100644 --- a/compiler/stz-build-manager.stanza +++ b/compiler/stz-build-manager.stanza @@ -117,4 +117,4 @@ public defstruct NoBuildTarget <: Exception : name: Symbol defmethod print (o:OutputStream, e:NoBuildTarget) : - print(o, "No build target named %~." % [name(e)]) + print(o, "No build target named %~." % [name(e)]) \ No newline at end of file diff --git a/compiler/stz-front-end.stanza b/compiler/stz-front-end.stanza index 81ea78844..c93cb0fb8 100644 --- a/compiler/stz-front-end.stanza +++ b/compiler/stz-front-end.stanza @@ -739,4 +739,4 @@ defn MissingPackageInFile (filename:String, package-name:Symbol) : defn PackageAlreadyLoaded (package-name:Symbol) : new FrontEndError : defmethod print (o:OutputStream, this) : - print(o, "The package %~ has already been loaded." % [package-name]) + print(o, "The package %~ has already been loaded." % [package-name]) \ No newline at end of file diff --git a/compiler/stz-hash.stanza b/compiler/stz-hash.stanza index aa7745f50..9590a3360 100644 --- a/compiler/stz-hash.stanza +++ b/compiler/stz-hash.stanza @@ -209,4 +209,4 @@ defn dhash (d:Int, x:Int, n:Int) : a = (a + 0xd3a2646c) ^ (a << 9) a = (a + 0xfd7046c5) + (a << 3) a = (a ^ 0xb55a4f09) ^ (a >> 16) - (a & 0x7FFFFFFF) % n + (a & 0x7FFFFFFF) % n \ No newline at end of file diff --git a/compiler/stz-langs.stanza b/compiler/stz-langs.stanza index d991c505b..5be251ad7 100644 --- a/compiler/stz-langs.stanza +++ b/compiler/stz-langs.stanza @@ -875,7 +875,4 @@ defn compile (info:False|FileInfo, format:String, args:List) : next(parts) as One ;Compile into print statements List $ for p in pieces seq-append : - fill-template(`(print(x)), [`x => p]) - - - + fill-template(`(print(x)), [`x => p]) \ No newline at end of file diff --git a/compiler/stz-proj.stanza b/compiler/stz-proj.stanza index ecdb72dd4..beda4437b 100644 --- a/compiler/stz-proj.stanza +++ b/compiler/stz-proj.stanza @@ -1062,4 +1062,4 @@ defn tuple? (f:T -> Tuple, x:Maybe) -> Tuple : else : f(value!(x)) defn map-values (f:V1 -> ?V2, xs:Tuple>) : - for x in xs map : key(x) => f(value(x)) + for x in xs map : key(x) => f(value(x)) \ No newline at end of file diff --git a/compiler/stz-reg-alloc.stanza b/compiler/stz-reg-alloc.stanza index 689c06b5f..f041e5693 100644 --- a/compiler/stz-reg-alloc.stanza +++ b/compiler/stz-reg-alloc.stanza @@ -2759,4 +2759,4 @@ defn to-asm-op (op:VMOp) -> asm-Op : ;============================================================ defn keys (xs:Vector>) : to-list(seq(key,xs)) -defn values (xs:Vector>) : to-list(seq(value,xs)) +defn values (xs:Vector>) : to-list(seq(value,xs)) \ No newline at end of file diff --git a/compiler/stz-repl.stanza b/compiler/stz-repl.stanza index d17f4e790..88eb09fa6 100644 --- a/compiler/stz-repl.stanza +++ b/compiler/stz-repl.stanza @@ -847,4 +847,4 @@ defn make-load-exp (args:Tuple, go-inside?:True|False) : val inputs = for a in args map : if index-of-char(a, '.') is Int : a else : to-symbol(a) - Load(inputs, go-inside?) + Load(inputs, go-inside?) \ No newline at end of file diff --git a/compiler/stz-set-utils.stanza b/compiler/stz-set-utils.stanza index 69ec19002..6ef47a72d 100644 --- a/compiler/stz-set-utils.stanza +++ b/compiler/stz-set-utils.stanza @@ -92,4 +92,4 @@ defn bsearch (xs:Tuple, start:Int, end:Int, v:Int) -> Int : else : val m = i + (j - i) / 2 if xs[m] < v : loop(m + 1, j) - else : loop(i, m) + else : loop(i, m) \ No newline at end of file diff --git a/compiler/stz-test-framework.stanza b/compiler/stz-test-framework.stanza index bc9c0f449..dbb519ef3 100644 --- a/compiler/stz-test-framework.stanza +++ b/compiler/stz-test-framework.stanza @@ -466,4 +466,4 @@ protected defn print-test-report (exit-on-fail?:True|False) : ;Exit with proper exit code when requested if exit-on-fail? and peek(fail-counter) > 0 : - exit(-1) + exit(-1) \ No newline at end of file diff --git a/compiler/stz-type-calculus.stanza b/compiler/stz-type-calculus.stanza index a082dce7e..e3a6387e3 100644 --- a/compiler/stz-type-calculus.stanza +++ b/compiler/stz-type-calculus.stanza @@ -1051,4 +1051,4 @@ public defn callable? (x:FnT, a2:List) : val n2 = length(a2) match(r(x)) : (rx:False) : all3?(assignable?, a2, a1) when n1 == n2 - (rx:LSType) : all3?(assignable?, a2, ex(a1, rx)) when n1 <= n2 + (rx:LSType) : all3?(assignable?, a2, ex(a1, rx)) when n1 <= n2 \ No newline at end of file diff --git a/compiler/stz-vm-encoder.stanza b/compiler/stz-vm-encoder.stanza index b9615e0f5..70e179ec7 100644 --- a/compiler/stz-vm-encoder.stanza +++ b/compiler/stz-vm-encoder.stanza @@ -1242,4 +1242,4 @@ defn delay-actions (f:() -> ?T) : val result = let-var delay = delay-action : f() for d in delays do : d() clear(delays) - result + result \ No newline at end of file diff --git a/compiler/stz-vm-normalize.stanza b/compiler/stz-vm-normalize.stanza index 44d497ea1..bf68c1437 100644 --- a/compiler/stz-vm-normalize.stanza +++ b/compiler/stz-vm-normalize.stanza @@ -1408,5 +1408,4 @@ defn InsBuffer (function:VMFunction) : if key?(def-table, i) : loop() else : i def-table[n] = VMDef(n, t) - Local(n) - + Local(n) \ No newline at end of file diff --git a/core/parser.stanza b/core/parser.stanza index b50d1325d..8923e6b69 100644 --- a/core/parser.stanza +++ b/core/parser.stanza @@ -2062,4 +2062,4 @@ defmethod print (o:OutputStream, e:NoMatchException) : public defstruct NoSyntaxPackage <: PatternException : name: Symbol defmethod print (o:OutputStream, e:NoSyntaxPackage) : - print(o, "Could not resolve syntax package %~." % [name(e)]) + print(o, "Could not resolve syntax package %~." % [name(e)]) \ No newline at end of file diff --git a/core/reader.stanza b/core/reader.stanza index 82267facf..d62c923fb 100644 --- a/core/reader.stanza +++ b/core/reader.stanza @@ -1039,4 +1039,4 @@ defmethod print (o:OutputStream, e:ExpectingMoreInput) : public defn caused-by-incomplete-input? (e:LexerException) -> True|False : e is NoForm|NoEndTagFound|UnclosedCharString|UnclosedString|UnclosedSymbol| - NoClosingToken|ExpectingIndentedBlock|ExpectingMoreInput + NoClosingToken|ExpectingIndentedBlock|ExpectingMoreInput \ No newline at end of file From 60890d8ea3cc5cc0de42870979c0499e8b999323 Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Thu, 23 Sep 2021 06:54:15 -0700 Subject: [PATCH 7/8] clean up newlines --- compiler/stz-arg-parser.stanza | 2 +- compiler/stz-call-records.stanza | 2 +- compiler/stz-langs.stanza | 4 +++- compiler/stz-vm-normalize.stanza | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/stz-arg-parser.stanza b/compiler/stz-arg-parser.stanza index fb6a29397..ce2ebc240 100644 --- a/compiler/stz-arg-parser.stanza +++ b/compiler/stz-arg-parser.stanza @@ -240,4 +240,4 @@ defmethod print (o:OutputStream, e:WrongArityFlag) : defmethod print (o:OutputStream, e:MissingFlag) : print(o, "Command %_ requires flag -%_." % [name(command(e)), name(flag(e))]) defmethod print (o:OutputStream, e:NoSuchFlag) : - print(o, "Command %_ does not recognize flag -%_." % [name(command(e)), flag(e)]) + print(o, "Command %_ does not recognize flag -%_." % [name(command(e)), flag(e)]) \ No newline at end of file diff --git a/compiler/stz-call-records.stanza b/compiler/stz-call-records.stanza index a5b1777b7..c4bc9f5a8 100644 --- a/compiler/stz-call-records.stanza +++ b/compiler/stz-call-records.stanza @@ -110,4 +110,4 @@ public defn callc-records (a1:Tuple, a2:ArgType, backend:Backend) -> Ca val num-mem-args = peek(mem-counter) ;Return record - CallCRecords(to-tuple(records), return-loc, num-int-args, num-real-args, num-mem-args) + CallCRecords(to-tuple(records), return-loc, num-int-args, num-real-args, num-mem-args) \ No newline at end of file diff --git a/compiler/stz-langs.stanza b/compiler/stz-langs.stanza index 5be251ad7..31225c4c7 100644 --- a/compiler/stz-langs.stanza +++ b/compiler/stz-langs.stanza @@ -875,4 +875,6 @@ defn compile (info:False|FileInfo, format:String, args:List) : next(parts) as One ;Compile into print statements List $ for p in pieces seq-append : - fill-template(`(print(x)), [`x => p]) \ No newline at end of file + fill-template(`(print(x)), [`x => p]) + + diff --git a/compiler/stz-vm-normalize.stanza b/compiler/stz-vm-normalize.stanza index bf68c1437..cfedfd7df 100644 --- a/compiler/stz-vm-normalize.stanza +++ b/compiler/stz-vm-normalize.stanza @@ -1408,4 +1408,4 @@ defn InsBuffer (function:VMFunction) : if key?(def-table, i) : loop() else : i def-table[n] = VMDef(n, t) - Local(n) \ No newline at end of file + Local(n) From a52a7843d22dab7cb28212546dd3c8a42c630b3f Mon Sep 17 00:00:00 2001 From: jackbackrack Date: Thu, 23 Sep 2021 06:57:39 -0700 Subject: [PATCH 8/8] change to to-peek-seq --- core/parser.stanza | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/parser.stanza b/core/parser.stanza index 8923e6b69..8cafeb58b 100644 --- a/core/parser.stanza +++ b/core/parser.stanza @@ -1111,7 +1111,7 @@ defmulti num-indices (i:IndexPool) -> Int defmulti get (i:IndexPool, name:Symbol) -> Int defn IndexPool () : - val indices = PeekSeq $ to-seq(0 to false) + val indices = to-peek-seq(0 to false) val binders = HashTable() new IndexPool : defmethod next (this, name:Symbol) :