Skip to content

Commit

Permalink
Use rustfmt for Rust code, and switch to spaces rather than tabs for …
Browse files Browse the repository at this point in the history
…all code
  • Loading branch information
fleabitdev committed Jan 22, 2021
1 parent ca7186d commit 30a566e
Show file tree
Hide file tree
Showing 101 changed files with 51,346 additions and 49,562 deletions.
24 changes: 12 additions & 12 deletions CHANGELOG.md
Expand Up @@ -27,18 +27,18 @@
- There is no longer any restriction on variables captured or returned by `Runtime::run`
- `Root`, `RGlobalRef`, `RGlobalRefMut`, `RRef` and `RRefMut` can now be stored in an `RData`
- `RFn`, `RData`, Rust globals, and the function-wrapping code have been overhauled
- The `min_specialization`, `rustc_attrs` and `unboxed_closures` nightly features are
now required
- The `RStore` trait and `rdata!` macro have been removed. `RData` may now store any
`'static` Rust type
- Associating an `RClass` with a Rust type is now a dynamic operation, using `RClassBuilder`
- The `Lib` trait has been renamed to `RGlobal`, and the `lib!` macro has been removed
- `RFn`s are now stored on the garbage-collected heap, as `Root<RFn>`
- The `rfn!` macro has been removed. Function pointers and closures can now be passed directly
to `glsp::rfn` and similar functions
- Capturing closures can now be passed to `glsp::rfn`, as long as they're `'static`
- Rest parameters are now captured using a wrapper type `Rest<T>`, rather than a slice `&[T]`
- Optional parameters will now be set to `None` when their argument is `#n`
- The `min_specialization`, `rustc_attrs` and `unboxed_closures` nightly features are
now required
- The `RStore` trait and `rdata!` macro have been removed. `RData` may now store any
`'static` Rust type
- Associating an `RClass` with a Rust type is now a dynamic operation, using `RClassBuilder`
- The `Lib` trait has been renamed to `RGlobal`, and the `lib!` macro has been removed
- `RFn`s are now stored on the garbage-collected heap, as `Root<RFn>`
- The `rfn!` macro has been removed. Function pointers and closures can now be passed directly
to `glsp::rfn` and similar functions
- Capturing closures can now be passed to `glsp::rfn`, as long as they're `'static`
- Rest parameters are now captured using a wrapper type `Rest<T>`, rather than a slice `&[T]`
- Optional parameters will now be set to `None` when their argument is `#n`
- `meth`, `has-meth?`, `meth-name` and `call-meth` have been renamed to `met`, `has-met?`,
`met-name` and `call-met` respectively
- Improved error message when glsp functions are called with no active `Runtime`
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
@@ -1,12 +1,12 @@
[workspace]
members = [
"glsp",
"glsp-proc-macros2",
"glsp-stdlib",
"glsp-proc-macros",
"glsp-engine"
"glsp",
"glsp-proc-macros2",
"glsp-stdlib",
"glsp-proc-macros",
"glsp-engine"
]
exclude = [
"benchmarks",
"website"
"benchmarks",
"website"
]
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -23,12 +23,12 @@ Short-term goals for the language, in descending order of priority:
- Syntax-highlighting for more text editors
- Reporting the location of mismatched parentheses when parsing
- Working off some recent technical debt
- Make gc timing more consistent when `"unsafe-internals"` is disabled
- Optimize `forn`, collections, objects, and the write-barrier
- Forbid names like `iter` from being bound as local variables
- Make gc timing more consistent when `"unsafe-internals"` is disabled
- Optimize `forn`, collections, objects, and the write-barrier
- Forbid names like `iter` from being bound as local variables
- Built-in functions for debugging
- Convenient functions for running a REPL in-game
- Some level of support for hotloading
- Convenient functions for running a REPL in-game
- Some level of support for hotloading
- Auditing the crate's integer conversions and overflow (e.g. `usize as u32` casts)
- Bindings to the `regex` and `chrono` crates, behind feature flags
- Generalizing `let-macro` - this will enable things like classmacros, patterns and struct
Expand Down
234 changes: 117 additions & 117 deletions benchmarks/src/benchmarks.glsp
Expand Up @@ -4,169 +4,169 @@ in an unrolled loop.
|#

(defmacro unroll (times : int?, ..body)
`(do ~..(take (* times (len body)) (repeat ..body))))
`(do ~..(take (* times (len body)) (repeat ..body))))

(defn primitive-inc ()
(let x 0)
(forn (i 1_000_000)
(unroll 100 (inc! x 1))))
(let x 0)
(forn (i 1_000_000)
(unroll 100 (inc! x 1))))

(defn primitive-arith ()
(let x 0.0)
(forn (i 1_000_000)
(unroll 10
(inc! x 500)
(dec! x 250)
(mul! x 1.5)
(div! x 42.0)
(rem! x 18.0)
(neg! x))))
(let x 0.0)
(forn (i 1_000_000)
(unroll 10
(inc! x 500)
(dec! x 250)
(mul! x 1.5)
(div! x 42.0)
(rem! x 18.0)
(neg! x))))

(defn primitive-call0 ()
(let-fn a () #n)
(let-fn a () #n)

(forn (i 100_000)
(unroll 100 (a))))
(forn (i 100_000)
(unroll 100 (a))))

(defn primitive-call3 ()
(let-fn a (b c d) #n)
(let-fn a (b c d) #n)

(forn (i 100_000)
(unroll 100 (a 1 2 3))))
(forn (i 100_000)
(unroll 100 (a 1 2 3))))

(defn primitive-array ()
(let a (arr 1 2 3 4 5 6 7 8 9 10))
(let a (arr 1 2 3 4 5 6 7 8 9 10))

(let x #n)
(forn (i 100_000)
(unroll 10
(= x [a 0]) (= x [a 1]) (= x [a 2]) (= x [a 3]) (= x [a 4])
(= x [a 5]) (= x [a 6]) (= x [a 7]) (= x [a 8]) (= x [a 9]))))
(let x #n)
(forn (i 100_000)
(unroll 10
(= x [a 0]) (= x [a 1]) (= x [a 2]) (= x [a 3]) (= x [a 4])
(= x [a 5]) (= x [a 6]) (= x [a 7]) (= x [a 8]) (= x [a 9]))))

(defn primitive-table ()
(let t (tab ('a 0) ('b 1) ('c 2) ('d 3) ('e 4)
('f 5) ('g 6) ('h 7) ('i 8) ('j 9)))
(let t (tab ('a 0) ('b 1) ('c 2) ('d 3) ('e 4)
('f 5) ('g 6) ('h 7) ('i 8) ('j 9)))

(let x #n)
(forn (i 100_000)
(unroll 10
(= x [t 'a]) (= x [t 'b]) (= x [t 'c]) (= x [t 'd]) (= x [t 'e])
(= x [t 'f]) (= x [t 'g]) (= x [t 'h]) (= x [t 'i]) (= x [t 'j]))))
(let x #n)
(forn (i 100_000)
(unroll 10
(= x [t 'a]) (= x [t 'b]) (= x [t 'c]) (= x [t 'd]) (= x [t 'e])
(= x [t 'f]) (= x [t 'g]) (= x [t 'h]) (= x [t 'i]) (= x [t 'j]))))

(defn primitive-field ()
(let-class C
(field (a b c d e f g h i j)))
(let-class C
(field (a b c d e f g h i j)))

(let o (C))
(let o (C))

(let x #n)
(forn (i 100_000)
(unroll 10
(= x [o 'a]) (= x [o 'b]) (= x [o 'c]) (= x [o 'd]) (= x [o 'e])
(= x [o 'f]) (= x [o 'g]) (= x [o 'h]) (= x [o 'i]) (= x [o 'j]))))
(let x #n)
(forn (i 100_000)
(unroll 10
(= x [o 'a]) (= x [o 'b]) (= x [o 'c]) (= x [o 'd]) (= x [o 'e])
(= x [o 'f]) (= x [o 'g]) (= x [o 'h]) (= x [o 'i]) (= x [o 'j]))))

(defn primitive-method ()
(let-class C
(met a ()))
(let-class C
(met a ()))

(let o (C))
(let o (C))

(forn (i 100_000)
(unroll 100 (.a o))))
(forn (i 100_000)
(unroll 100 (.a o))))

#|
the remaining benchmarks attempt to tax the language in a way which is vaguely similar
to real game source code.
|#

(defn rects ()
; randomly generate a number of rectangles, then count the number of distinct pairs
; of rectangles which overlap with one another. lots of numeric comparisons and field
; accesses. also stresses numeric iteration.
(defstruct Rect
x y w h

(met intersects? (other)
(and
(> (+ @x @w) [other 'x])
(< @x (+ [other 'x] [other 'w]))
(> (+ @y @h) [other 'y])
(< @y (+ [other 'y] [other 'h])))))

(let rng 75)
(let-fn rng-gen ()
(= rng (% (* rng 75) 65537))
rng)

(let rects (arr))
(forn (_ 2000)
(push! rects (Rect (rng-gen) (rng-gen) (rng-gen) (rng-gen))))

(let count 0)
(forn (i (len rects))
(forn (j (+ i 1) (len rects))
(when (.intersects? [rects i] [rects j])
(inc! count)))))
; randomly generate a number of rectangles, then count the number of distinct pairs
; of rectangles which overlap with one another. lots of numeric comparisons and field
; accesses. also stresses numeric iteration.
(defstruct Rect
x y w h

(met intersects? (other)
(and
(> (+ @x @w) [other 'x])
(< @x (+ [other 'x] [other 'w]))
(> (+ @y @h) [other 'y])
(< @y (+ [other 'y] [other 'h])))))

(let rng 75)
(let-fn rng-gen ()
(= rng (% (* rng 75) 65537))
rng)

(let rects (arr))
(forn (_ 2000)
(push! rects (Rect (rng-gen) (rng-gen) (rng-gen) (rng-gen))))

(let count 0)
(forn (i (len rects))
(forn (j (+ i 1) (len rects))
(when (.intersects? [rects i] [rects j])
(inc! count)))))

(defn flood-fill ()
; flood-fill a one-dimensional, 1-bit raster image. (we reduce this to one dimension so that
; we're testing collections, rather than testing the allocator.)
(let width 1_000_000)
(let pixels (arr-from-elem 0 width))
(let to-check (arr (/ (len pixels) 2)))
; flood-fill a one-dimensional, 1-bit raster image. (we reduce this to one dimension so that
; we're testing collections, rather than testing the allocator.)
(let width 1_000_000)
(let pixels (arr-from-elem 0 width))
(let to-check (arr (/ (len pixels) 2)))

(let painted 0)
(while (> (len to-check) 0)
(let x (pop! to-check))
(let painted 0)
(while (> (len to-check) 0)
(let x (pop! to-check))

(= [pixels x] 1)
(inc! painted)
(= [pixels x] 1)
(inc! painted)

(when (and (< x (- width 1)) (== [pixels (+ x 1)] 0))
(push! to-check (+ x 1)))
(when (and (< x (- width 1)) (== [pixels (+ x 1)] 0))
(push! to-check (+ x 1)))

(when (and (> x 0) (== [pixels (- x 1)] 0))
(push! to-check (- x 1))))
(when (and (> x 0) (== [pixels (- x 1)] 0))
(push! to-check (- x 1))))

(ensure (== painted width)))
(ensure (== painted width)))

(defn rotation ()
; take an array of 2d points, and rotate them 360 degrees around the origin by accumulating
; many smaller rotations. stresses basic maths, method calls, and self-field accesses.
(let rng 75)
(let-fn rng-gen ()
(= rng (% (* rng 75) 65537))
rng)

(defstruct Point
x y

(met rotate! (diff)
(let distance (sqrt (+ (* @x @x) (* @y @y))))
(let angle (atan @y @x))
(let new-angle (+ angle diff))
(= @x (* distance (cos new-angle)))
(= @y (* distance (sin new-angle)))))

(let points (arr))
(forn (_ 300)
(push! points (Point (flo (rng-gen)) (flo (rng-gen)))))

(let step (/ (* 0.1 3.14159) 180.0))
(forn (_ 3600)
(for point in points
(.rotate! point step))))
; take an array of 2d points, and rotate them 360 degrees around the origin by accumulating
; many smaller rotations. stresses basic maths, method calls, and self-field accesses.
(let rng 75)
(let-fn rng-gen ()
(= rng (% (* rng 75) 65537))
rng)

(defstruct Point
x y

(met rotate! (diff)
(let distance (sqrt (+ (* @x @x) (* @y @y))))
(let angle (atan @y @x))
(let new-angle (+ angle diff))
(= @x (* distance (cos new-angle)))
(= @y (* distance (sin new-angle)))))

(let points (arr))
(forn (_ 300)
(push! points (Point (flo (rng-gen)) (flo (rng-gen)))))

(let step (/ (* 0.1 3.14159) 180.0))
(forn (_ 3600)
(for point in points
(.rotate! point step))))

#|
run the benchmarks
|#

(defn bench (..names)
(for name in names
(let start (time))
((global name))
(let elapsed (- (time) start))
(prn "Glsp {name}: {(flo->str (* elapsed 1000.0) 1)}ms")))
(for name in names
(let start (time))
((global name))
(let elapsed (- (time) start))
(prn "Glsp {name}: {(flo->str (* elapsed 1000.0) 1)}ms")))

(bench 'primitive-inc 'primitive-arith 'primitive-call0 'primitive-call3
'primitive-array 'primitive-table 'primitive-field 'primitive-method
Expand Down

0 comments on commit 30a566e

Please sign in to comment.