Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goal: Go augmented language #1229

Open
wants to merge 318 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
318 commits
Select commit Hold shift + click to select a range
759e279
goal: switch over to $ = shell, # = math
rcoreilly Sep 18, 2024
e715ba2
using our own parser now, deals with statements and exprs; now just n…
rcoreilly Sep 18, 2024
75ab7e1
moved all transpiling into separate package -- getting kinda big and …
rcoreilly Sep 18, 2024
2de0c6f
basic kind inference for array literal
rcoreilly Sep 19, 2024
4a3fe3c
numpy selectors and full math test that can be run to test actual fun…
rcoreilly Sep 19, 2024
9ef24f1
math table updated
rcoreilly Sep 19, 2024
19354cc
function calls
rcoreilly Sep 19, 2024
cf76580
table experiments
rcoreilly Sep 19, 2024
96ce9eb
numpy table update and organization
rcoreilly Sep 19, 2024
dd209b1
table fixes
rcoreilly Sep 19, 2024
5bfe896
table fixes
rcoreilly Sep 19, 2024
6262c00
table fixes
rcoreilly Sep 19, 2024
5b9c2a5
fixes from kai review
rcoreilly Sep 19, 2024
a2df8aa
update yaegicore
rcoreilly Sep 19, 2024
3eb94cf
Merge commit 'a2df8aa' into goal
rcoreilly Sep 19, 2024
39ab340
tensor Indexed implements tensor api with updated interface to suppor…
rcoreilly Sep 20, 2024
c102aa6
Indexed as Tensor mostly updated with tests working. need other view…
rcoreilly Sep 20, 2024
e71d11f
finally did my rtfm on numpy and have a solid plan for how everything…
rcoreilly Sep 20, 2024
44c3d27
replaced Indexed -> Rows
rcoreilly Sep 20, 2024
40d78b4
first pass impl of Sliced -- needs tests
rcoreilly Sep 21, 2024
acf823d
sliced test working; damn index clone issue again
rcoreilly Sep 21, 2024
11e9030
Slice type fully tested and debugged -- surprisingly tricky..
rcoreilly Sep 21, 2024
a876b8c
tensor: everything building and passing tests; sliced working in pca …
rcoreilly Sep 21, 2024
5013132
tensor: major reorganization into separate interfaces, with basic Ten…
rcoreilly Sep 22, 2024
bcb1a65
renamed RowCell -> RowMajor to better reflect its constraint.
rcoreilly Sep 22, 2024
e7f3ed5
Bits -> Bool
rcoreilly Sep 22, 2024
e4e781f
masked working
rcoreilly Sep 22, 2024
5b6c72d
remove redundant tensor version of ShapeSizes and rename Ints version…
rcoreilly Sep 22, 2024
72b2995
tensor Indexed fully implemented and tested; cleaned up docs and adde…
rcoreilly Sep 22, 2024
35e600b
more docs cleanup in README etc -- now ready for broadcast / alignment
rcoreilly Sep 22, 2024
549f35c
reshaped view added -- key for computation
rcoreilly Sep 22, 2024
c89aa9a
math ops working with new logic!
rcoreilly Sep 22, 2024
4d039c1
testing, etc
rcoreilly Sep 22, 2024
d32c608
finish docs
rcoreilly Sep 23, 2024
bfff608
some fixes from kai comments on tfunc pr.
rcoreilly Sep 23, 2024
ec34572
more fixes from kai comments on tfunc pr.
rcoreilly Sep 23, 2024
94b3b37
many fixes: funcs return errors, improved reshaping, Cells1D, etc fun…
rcoreilly Sep 23, 2024
ddcb8b8
metric building but getting one testing error
rcoreilly Sep 23, 2024
ac9ad17
use Call etc methods on metrics enum
rcoreilly Sep 23, 2024
ec0666b
everything building and testing in tensor.
rcoreilly Sep 23, 2024
1654dff
everything everywhere should now be building and passing tests..
rcoreilly Sep 23, 2024
d89abc2
SubSpace properly deals with 1D tensors (cells are a scalar), and doc…
rcoreilly Sep 23, 2024
579b53a
matrix readme update, and error checking for same tensor shape
rcoreilly Sep 23, 2024
213043a
add goal/testdata
rcoreilly Sep 23, 2024
21155c6
switched stats and metric func / enum so the enum has the prefix and …
rcoreilly Sep 23, 2024
a9fb916
add FilterOptions struct instead of named bool constants, rename Stab…
rcoreilly Sep 23, 2024
aa76c95
fixes from filtering etc
rcoreilly Sep 23, 2024
c68e5f0
correctly parsing a basic literal tensor indexing expression
rcoreilly Sep 24, 2024
c50733c
tensor sliced processes int, slice, elipses
rcoreilly Sep 24, 2024
3fb463e
full slice parsing working
rcoreilly Sep 24, 2024
56aa0cb
added NewAxis and FullAxis in NewSliced, which now auto-handles the r…
rcoreilly Sep 24, 2024
46a3587
yaegicore update
rcoreilly Sep 24, 2024
72e7b8b
goal: new function stack and appropriate contextualization of tensor …
rcoreilly Sep 24, 2024
976a678
tensor function calling working -- allows lowercase on non-package-qu…
rcoreilly Sep 25, 2024
b6acc9e
add Reshape (which now supports -1 args) and Reslice tensor functions…
rcoreilly Sep 25, 2024
09fb870
parsing alignment fixed -- full expressions work
rcoreilly Sep 25, 2024
604eb7c
assignment through slicing is working
rcoreilly Sep 25, 2024
48563a6
yaegi update
rcoreilly Sep 25, 2024
a7d95b9
## math mode toggling
rcoreilly Sep 25, 2024
2d80a83
reshape, ndim, copy etc working as methods and functions
rcoreilly Sep 25, 2024
547517c
reorganize table into separate sections
rcoreilly Sep 25, 2024
7e3e899
ones, full functions
rcoreilly Sep 25, 2024
9810245
squeeze
rcoreilly Sep 25, 2024
6ef2512
slicing docs
rcoreilly Sep 25, 2024
144c40b
full revamp of tensor function calling: remove call by string, just c…
rcoreilly Sep 26, 2024
fdcf574
update parsing to new function calling, yaegicore update
rcoreilly Sep 26, 2024
4602e4b
all tests working with new arg tracking: now knows when to make thing…
rcoreilly Sep 26, 2024
30288f0
use helper funcs in align for all ops -- key for more general computa…
rcoreilly Sep 26, 2024
121713f
bool masking with simple binary comparison expressions working
rcoreilly Sep 26, 2024
5a9c582
table updates
rcoreilly Sep 26, 2024
6d33c63
table updates
rcoreilly Sep 26, 2024
85626d9
better Mask return as plain tensor if no bools
rcoreilly Sep 27, 2024
7aa21ab
unary operators properly applied to tensor objects
rcoreilly Sep 27, 2024
7ce6e72
if statement working in math mode
rcoreilly Sep 27, 2024
865a4ef
for and for range statements working in math mode
rcoreilly Sep 27, 2024
437cd0c
update test.goal
rcoreilly Sep 27, 2024
9efcc50
table updates
rcoreilly Sep 27, 2024
e22364e
major improvement: goal uses yaegicore symbols to register functions …
rcoreilly Sep 27, 2024
feeaf91
tensor: use FloatFunc for math funcs, add binary calls
rcoreilly Sep 27, 2024
46d5974
add power operator as **
rcoreilly Sep 27, 2024
4f323bf
As*Tensor -> As* plain -- these are quite handy; fixed datafs
rcoreilly Sep 27, 2024
bca653a
much better Sprintf function that takes optional format and ensures r…
rcoreilly Sep 27, 2024
f23ce47
linspace makes 1d for scalar inputs; fix key bug in sprintf
rcoreilly Sep 27, 2024
732410e
table updates
rcoreilly Sep 27, 2024
86dbc6e
more runtime safety in range statement, re vars as idents
rcoreilly Sep 28, 2024
c5a5c0f
table
rcoreilly Sep 28, 2024
7feda22
table
rcoreilly Sep 28, 2024
36fd707
start on math datafs interface -- special limited command set for mat…
rcoreilly Sep 28, 2024
e273917
datafs integration with goal first pass working, planets example runs…
rcoreilly Sep 28, 2024
09c64b0
properly parses newaxis and ellipsis in reslice syntax
rcoreilly Sep 28, 2024
5f6c7f1
fix tensor tests with new output and renames
rcoreilly Sep 28, 2024
04084f4
fix extra goal/math_test
rcoreilly Sep 28, 2024
71e2445
add get and set aliases for datafs Get and Set, and add datafs docs t…
rcoreilly Sep 28, 2024
04a7224
add test for # # wrapping -- works. all good for now!
rcoreilly Sep 28, 2024
132514f
fix FloatFromValues -> Float64FromValues
rcoreilly Sep 30, 2024
786fde1
properly promote float types in binary expressions -- if either side …
rcoreilly Sep 30, 2024
5d61953
scalar values don't print shape.
rcoreilly Sep 30, 2024
5afcaf6
change default tensor format to %g, %s
rcoreilly Sep 30, 2024
a42f5c0
tmath.Div division operator always produces floating point, per python
rcoreilly Sep 30, 2024
07689b9
tensor print fix
rcoreilly Sep 30, 2024
d60a50d
add pi constant
rcoreilly Sep 30, 2024
c393a8e
start on vector package with basic vector functions: Inner, Sum, Dot,…
rcoreilly Sep 30, 2024
1b21ad1
vector: improved docs and tests
rcoreilly Sep 30, 2024
8a20759
remove debug print in sprintf and change params order with format fir…
rcoreilly Sep 30, 2024
b79ca78
fix += etc
rcoreilly Sep 30, 2024
d498db9
define always does a type conversion to tensor.Tensor so all variable…
rcoreilly Sep 30, 2024
263b262
rename vector.Inner -> vector.Mul
rcoreilly Sep 30, 2024
0c8d146
use consistent NormL1 and NormL2 throughout the stats, metric, vector…
rcoreilly Sep 30, 2024
45e35a2
Actually L1Norm and L2Norm are clearer -- use those throughout.
rcoreilly Sep 30, 2024
6d4d98c
Merge branch 'main' into goal
rcoreilly Sep 30, 2024
186fc34
matrix multiplication fully working -- need @ wrapper
rcoreilly Oct 1, 2024
ead8293
@ operator for matrix multiplication
rcoreilly Oct 1, 2024
9c7ab28
determinant functions
rcoreilly Oct 1, 2024
e3242bf
multidimensional array literals processed correctly
rcoreilly Oct 1, 2024
aac3037
readme update
rcoreilly Oct 1, 2024
bb9ec09
collapse extra dimension for vector @ matrix
rcoreilly Oct 1, 2024
b7427a3
matrix: annoying Tri indexing functions all working -- hard to get th…
rcoreilly Oct 1, 2024
1862a6c
all the triangle, diagonal, trace functions in matrix
rcoreilly Oct 2, 2024
fea4f00
move gosl into goal, and initial plans for GPU mode -- seems pretty good
rcoreilly Oct 2, 2024
2ea1375
reorganize gosl code with everything in parse, using cli config, leav…
rcoreilly Oct 3, 2024
d801343
gosl major reorganization for package based processing
rcoreilly Oct 3, 2024
3726761
rename parse -> gotosl
rcoreilly Oct 3, 2024
d8a6f55
document process, cleanup names -- basic translation phase good; now …
rcoreilly Oct 3, 2024
e9b5c4e
extracting args and kernels
rcoreilly Oct 3, 2024
2a36add
generating kernel code
rcoreilly Oct 3, 2024
7603f84
kernel gen working
rcoreilly Oct 4, 2024
92fb26d
add genkernel file!
rcoreilly Oct 4, 2024
3e33b22
gpu code generation mostly working; read sync not working due to miss…
rcoreilly Oct 4, 2024
fdb620f
gpu: major update to arrayn variable creation: actual array size is d…
rcoreilly Oct 4, 2024
62c272f
fix incorrect imports. type prefixing and add & to recv arg for metho…
rcoreilly Oct 4, 2024
1f916d5
break up Run and Done commands to allow sequencing.
rcoreilly Oct 4, 2024
a7b0e5a
actually parse read-only flag and use in generated code
rcoreilly Oct 4, 2024
cbd7d4d
start on auto-processing of global var exprs with tmp vars. one very …
rcoreilly Oct 5, 2024
0b3deae
calling functions with global vars now automatically creates tmp vars…
rcoreilly Oct 5, 2024
157954b
complete working mockup of how to do tensors in gosl. added Header of…
rcoreilly Oct 5, 2024
18a80d2
generating correct gosl.go code and parsing various tensor properties.
rcoreilly Oct 6, 2024
a28cb78
gosl tensor translation full working
rcoreilly Oct 6, 2024
e7f0783
rand updated to new gosl code
rcoreilly Oct 6, 2024
9109105
add wgsl
rcoreilly Oct 6, 2024
03ca327
move gosl back up to main gosl dir -- don't need other things in gosl…
rcoreilly Oct 6, 2024
f8e6083
matrix.Inverse function, and return errors instead of panic in matrix…
rcoreilly Oct 6, 2024
6891c5e
gotosl test now working with new paradigm
rcoreilly Oct 6, 2024
90c1ff5
updated docs for gosl and GPU
rcoreilly Oct 6, 2024
b1eb7d2
tensor n-dim indexing in goal mode; translates to Value, Set* functions
rcoreilly Oct 7, 2024
e176319
split out yaegicore into nogui and gui components, goal only includes…
rcoreilly Oct 7, 2024
d520baa
goal build runs gosl and go build
rcoreilly Oct 7, 2024
293bb2c
verbose fixes etc
rcoreilly Oct 7, 2024
087225c
goal: fix parsing of Go assignment expressions, including now getting…
rcoreilly Oct 7, 2024
562463c
core.Filename is alias for fs.Filename
rcoreilly Oct 7, 2024
fb30eee
fix goal build final code composition -- generate code first then wra…
rcoreilly Oct 7, 2024
636a2d6
get the scripts functionality and helper functions from numbers/datab…
rcoreilly Oct 7, 2024
6e81601
fileinfo detects generated files using standard Go regex, and filetre…
rcoreilly Oct 7, 2024
73e8663
use go format.Source on generated full goal build files (but not impo…
rcoreilly Oct 8, 2024
35825cc
textedtitor readonly uses SurfaceContainer (not Low) background for r…
rcoreilly Oct 8, 2024
a7ed4e8
exclude generated files from search results in filetree
rcoreilly Oct 8, 2024
a978019
moved PCA (EigSym) over to matrix, along with SVD, where they belong..
rcoreilly Oct 8, 2024
972bb9f
use parallel threading for N>2 dim matrix ops which are very expensiv…
rcoreilly Oct 8, 2024
2dd807b
wrap ndim index exprs in int() so they always work
rcoreilly Oct 8, 2024
83fbb1b
gosl: remove int() wrapper for tensor indexing calls
rcoreilly Oct 8, 2024
732b831
use %.10g for default tensor sprintf format -- removes tiny residual …
rcoreilly Oct 8, 2024
980319f
add bool Value, Set functions
rcoreilly Oct 8, 2024
052427e
goal: key fix to decl parsing -- only if brack and paren depth 0
rcoreilly Oct 8, 2024
48b5e43
N-dimensional indexing uses recursive go parsing.
rcoreilly Oct 9, 2024
49a9941
fix comment handling
rcoreilly Oct 9, 2024
e223197
fix comment handling for real, good tests
rcoreilly Oct 9, 2024
9d3db3e
gosl: support tensor pointers for global vars
rcoreilly Oct 9, 2024
2cdc6b8
base/generate and enumgen were filtering out generated files, which e…
rcoreilly Oct 9, 2024
35497ec
goal: dec is same as inc
rcoreilly Oct 9, 2024
9a7d941
gosl & goal have better error reporting and gosl inserts //line comme…
rcoreilly Oct 10, 2024
684904f
gosl: auto Get* functions for global vars, that GPU re-interprets, to…
rcoreilly Oct 11, 2024
69f246b
use gosl imports -- works great!
rcoreilly Oct 11, 2024
3fa7bc0
key bugfix: was not removing imported package prefixes
rcoreilly Oct 11, 2024
5f84974
must do vars file first to get vars; still not quite working for pl.I…
rcoreilly Oct 11, 2024
f7e1ea1
gosl tensor handles SetAdd etc properly.
rcoreilly Oct 12, 2024
2e82b9f
get type of Get* temp vars, looking up in type package scope.
rcoreilly Oct 12, 2024
9b2bbb5
start on atomic -- needs atomic type -- will require some infra for t…
rcoreilly Oct 12, 2024
2ebb515
major reorganization to generate only those functions that are used i…
rcoreilly Oct 13, 2024
b96d530
fix tmpvar name for Get -> Set
rcoreilly Oct 13, 2024
6a9a4d6
add package.function calls for callgraph -- fixes FastExp
rcoreilly Oct 14, 2024
00be93f
get path type for Get temp vars
rcoreilly Oct 14, 2024
c9c5807
set global var from temp _before_ final return statement
rcoreilly Oct 14, 2024
95082fd
prevent redundant include, fix tests and exampels.
rcoreilly Oct 14, 2024
9711018
important fix for enumgen, typegen: exclude enumgen.go, typegen.go fi…
rcoreilly Oct 17, 2024
ecf906c
in process logic for commands / builtins to be able to do pipe output…
rcoreilly Oct 25, 2024
215e3df
pipe working for builtin but not commands -- args fixed -- unclear wh…
rcoreilly Oct 25, 2024
7ceb537
Set builtin automatically does home path expansion and dedupe, as doe…
rcoreilly Oct 25, 2024
433561d
goal: a bit more robustness for crashing but still not dealing with s…
rcoreilly Oct 25, 2024
d10c186
goal: & of tensor -> ValuePtr -- needed for atomic exprs
rcoreilly Oct 31, 2024
e02a82b
full atomic support in place
rcoreilly Oct 31, 2024
2b46ead
goal: add atomic test case and const slice test case, and rename atom…
rcoreilly Nov 1, 2024
cd0f474
add Editable to texteditor context menu when in read only mode
rcoreilly Nov 1, 2024
1fbfb70
gosl properly handles global array vars as consts.
rcoreilly Nov 1, 2024
afc747f
gosl: enumgen exports the N const with //gosl:start, end wrapper -- n…
rcoreilly Nov 1, 2024
8a57518
gosl: for range expr translation
rcoreilly Nov 2, 2024
ded4517
GPUInit is safe to multiple calls; README docs updates
rcoreilly Nov 4, 2024
1de1aee
Merge branch 'main' into goal
rcoreilly Nov 4, 2024
ab2169d
Merge branch 'main' into goal
rcoreilly Nov 5, 2024
febe06c
plot styler implementation -- seems reasonable
rcoreilly Nov 6, 2024
fd42b32
plots: new functions don't return err so direct Add works
rcoreilly Nov 6, 2024
844be5a
plots: gearing up to test goal api for plotting using planets data
rcoreilly Nov 6, 2024
a2f6978
ploteditor styling functions
rcoreilly Nov 6, 2024
5167ef5
updated datafs-sim example with stat funcs that do everything in one …
rcoreilly Nov 6, 2024
462bfdf
first pass on new unified style, only for plots for now; got rid of s…
rcoreilly Nov 7, 2024
9974fe1
XY is the common Plotter type for Line and Scatter, just sets Line vs…
rcoreilly Nov 7, 2024
1ecc504
plot styles mostly in place and working -- need styler logic etc.
rcoreilly Nov 7, 2024
967e939
new styling plan in place for how to combine plot and element level s…
rcoreilly Nov 7, 2024
75e27b8
plot: all styling in place, elements updated, plots replicating. next…
rcoreilly Nov 8, 2024
003f149
plot styling fully working including range; imagex/testing now saves …
rcoreilly Nov 8, 2024
b95d503
new plot data framework all in place and building, but tests are failing
rcoreilly Nov 9, 2024
c00873f
use Data type for map, much simpler call signature
rcoreilly Nov 9, 2024
8c171b0
plot.Data is the map, Valuer is the value interface -- use plot.Data{…
rcoreilly Nov 9, 2024
1bdcd3d
fix Xaxis style scaling
rcoreilly Nov 9, 2024
d028ce7
checklengths
rcoreilly Nov 9, 2024
71150b9
rest of register functions
rcoreilly Nov 9, 2024
90536d6
fix xerr
rcoreilly Nov 9, 2024
43c3157
update README
rcoreilly Nov 11, 2024
780dd78
styler metadata; metadata has Metadataer interface for grabing from a…
rcoreilly Nov 11, 2024
58000e0
tensor-attached plot stylers example, tests etc.
rcoreilly Nov 11, 2024
3c88bf9
plot: start on table based plotting -- not working
rcoreilly Nov 11, 2024
c293888
table plot working for each plot type; fix label plotting; fix minmax…
rcoreilly Nov 12, 2024
f75d485
error bars use Y range properly, and range more generally; Low is opt…
rcoreilly Nov 12, 2024
a725107
fix inverted scale -> needs underlying scale
rcoreilly Nov 12, 2024
45890e0
ploteditor taking shape -- just need a reflectx copy named fields fun…
rcoreilly Nov 12, 2024
22c985b
ploteditor: CopyFields is working to set changed values, but color co…
rcoreilly Nov 12, 2024
ee023f4
reflectx image pointer copying now working properly -- CopyFields nee…
rcoreilly Nov 13, 2024
915f134
ploteditor default styling reasonable
rcoreilly Nov 13, 2024
b4b8278
overall plot styling working
rcoreilly Nov 13, 2024
f3bd93c
set columns buttons working; style switches with line color
rcoreilly Nov 13, 2024
05fc348
global x axis and auto legend
rcoreilly Nov 13, 2024
bc7464d
plot table: tricky logic for automatic X axis label working
rcoreilly Nov 13, 2024
a2d67fd
readme
rcoreilly Nov 13, 2024
4bded0c
bar plot striding logic; increase default nticks; cleanup old code
rcoreilly Nov 13, 2024
4531b30
panzoom post-processing -- better than before. also has shift = x, al…
rcoreilly Nov 13, 2024
de3e5e1
plot highlighting for kai
rcoreilly Nov 13, 2024
3e62411
tensor: only support one set of Row access methods, always taking cel…
rcoreilly Nov 14, 2024
d25dbd2
sim stats working much better: need loop phase input
rcoreilly Nov 14, 2024
90d672f
add AppendRowFloat, Int, String -- much cleaner for those cases
rcoreilly Nov 14, 2024
79dc4c5
better names and cleanup of datafs-sim
rcoreilly Nov 14, 2024
9c32594
add readme
rcoreilly Nov 14, 2024
fa11baa
core.tree and filetree: major update: Root is exported and is type Tr…
rcoreilly Nov 14, 2024
702d792
rest of fix for #1232 -- call update on tree when first ext is added.
rcoreilly Nov 14, 2024
fc1706a
yaegicore update and further browser plans
rcoreilly Nov 14, 2024
c18519b
databrowser separated, Basic pulled out
rcoreilly Nov 15, 2024
06d5c43
fix goal parsing of static initializer Field: expressions. databrowse…
rcoreilly Nov 15, 2024
5f34201
goal: some crash protections
rcoreilly Nov 15, 2024
28961a6
goal: plotting is robust to nil and plot update function in databrows…
rcoreilly Nov 16, 2024
7487521
key fix to databrowser tabs logic: target item is last widget in tab …
rcoreilly Nov 16, 2024
a82e893
gosl runs CPU functions using threaded calls
rcoreilly Nov 16, 2024
8d540d5
plot: fix hover to actually report data instead of pixels!
rcoreilly Nov 16, 2024
4a7f491
core.Tabs also needs a Tabber interface to get parent Tabs when it co…
rcoreilly Nov 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package atomiccounter
package atomicx

import (
"testing"
Expand All @@ -26,3 +26,13 @@ func TestCounter(t *testing.T) {
c.Set(2)
assert.Equal(t, int64(2), c.Value())
}

func TestMax(t *testing.T) {
a := int32(10)
MaxInt32(&a, 5)
assert.Equal(t, a, int32(10))
MaxInt32(&a, 10)
assert.Equal(t, a, int32(10))
MaxInt32(&a, 11)
assert.Equal(t, a, int32(11))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package atomiccounter implements a basic atomic int64 counter.
package atomiccounter
// Package atomicx implements misc atomic functions.
package atomicx

import (
"sync/atomic"
Expand Down
15 changes: 15 additions & 0 deletions base/atomicx/max.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2018, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package atomicx

import "sync/atomic"

// MaxInt32 performs an atomic Max operation: a = max(a, b)
func MaxInt32(a *int32, b int32) {
old := atomic.LoadInt32(a)
for old < b && !atomic.CompareAndSwapInt32(a, old, b) {
old = atomic.LoadInt32(a)
}
}
14 changes: 9 additions & 5 deletions base/exec/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ func (st *StdIO) Set(o *StdIO) *StdIO {
func (st *StdIO) SetToOS() *StdIO {
cur := &StdIO{}
cur.SetFromOS()
if sif, ok := st.In.(*os.File); ok {
os.Stdin = sif
} else {
fmt.Printf("In is not an *os.File: %#v\n", st.In)
}
os.Stdout = st.Out.(*os.File)
os.Stderr = st.Err.(*os.File)
os.Stdin = st.In.(*os.File)
return cur
}

Expand Down Expand Up @@ -98,13 +102,10 @@ func IsPipe(rw any) bool {
if rw == nil {
return false
}
w, ok := rw.(io.Writer)
_, ok := rw.(io.Writer)
if !ok {
return false
}
if w == os.Stdout {
return false
}
of, ok := rw.(*os.File)
if !ok {
return false
Expand Down Expand Up @@ -247,6 +248,9 @@ func (st *StdIOState) PopToStart() {
for len(st.InStack) > st.InStart {
st.PopIn()
}
for len(st.PipeIn) > 0 {
CloseReader(st.PipeIn.Pop())
}
}

// ErrIsInOut returns true if the given Err writer is also present
Expand Down
5 changes: 5 additions & 0 deletions base/fileinfo/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ type FileInfo struct { //types:add
// version control system status, when enabled
VCS vcs.FileStatus `table:"-"`

// Generated indicates that the file is generated and should not be edited.
// For Go files, this regex: `^// Code generated .* DO NOT EDIT\.$` is used.
Generated bool `table:"-"`

// full path to file, including name; for file functions
Path string `table:"-"`
}
Expand Down Expand Up @@ -143,6 +147,7 @@ func (fi *FileInfo) SetMimeInfo() error {
}
fi.Cat = UnknownCategory
fi.Known = Unknown
fi.Generated = IsGeneratedFile(fi.Path)
fi.Kind = ""
mtyp, _, err := MimeFromFile(fi.Path)
if err != nil {
Expand Down
16 changes: 15 additions & 1 deletion base/fileinfo/mimetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ package fileinfo
import (
"fmt"
"mime"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/h2non/filetype"
Expand Down Expand Up @@ -99,6 +101,18 @@ func MimeFromFile(fname string) (mtype, ext string, err error) {
return "", ext, fmt.Errorf("fileinfo.MimeFromFile could not find mime type for ext: %v file: %v", ext, fn)
}

var generatedRe = regexp.MustCompile(`^// Code generated .* DO NOT EDIT`)

func IsGeneratedFile(fname string) bool {
file, err := os.Open(fname)
if err != nil {
return false
}
head := make([]byte, 2048)
file.Read(head)
return generatedRe.Match(head)
}

// todo: use this to check against mime types!

// MimeToKindMapInit makes sure the MimeToKindMap is initialized from
Expand Down Expand Up @@ -316,7 +330,7 @@ var StandardMimes = []MimeType{
{"text/x-forth", []string{".frt"}, Code, Forth}, // note: ".fs" conflicts with fsharp
{"text/x-fortran", []string{".f", ".F"}, Code, Fortran},
{"text/x-fsharp", []string{".fs", ".fsi"}, Code, FSharp},
{"text/x-gosrc", []string{".go", ".mod", ".work", ".cosh"}, Code, Go},
{"text/x-gosrc", []string{".go", ".mod", ".work", ".goal"}, Code, Go},
{"text/x-haskell", []string{".hs", ".lhs"}, Code, Haskell},
{"text/x-literate-haskell", nil, Code, Haskell}, // todo: not sure if same or not

Expand Down
2 changes: 1 addition & 1 deletion base/fileinfo/typegen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions base/fsx/fsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"time"
)

// Filename is used to open a file picker dialog when used as an argument
// type in a function, or as a field value.
type Filename string

// GoSrcDir tries to locate dir in GOPATH/src/ or GOROOT/src/pkg/ and returns its
// full path. GOPATH may contain a list of paths. From Robin Elkind github.com/mewkiz/pkg.
func GoSrcDir(dir string) (absDir string, err error) {
Expand Down
22 changes: 17 additions & 5 deletions base/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,28 @@ func PrintHeader(w io.Writer, pkg string, imports ...string) {
}
}

// Inspect goes through all of the files in the given package
// and calls the given function on each node in files that
// are not generated. The bool return value from the given function
// ExcludeFile returns true if the given file is on the exclude list.
func ExcludeFile(pkg *packages.Package, file *ast.File, exclude ...string) bool {
fpos := pkg.Fset.Position(file.FileStart)
_, fname := filepath.Split(fpos.Filename)
for _, ex := range exclude {
if fname == ex {
return true
}
}
return false
}

// Inspect goes through all of the files in the given package,
// except those listed in the exclude list, and calls the given
// function on each node. The bool return value from the given function
// indicates whether to continue traversing down the AST tree
// of that node and look at its children. If a non-nil error value
// is returned by the given function, the traversal of the tree is
// stopped and the error value is returned.
func Inspect(pkg *packages.Package, f func(n ast.Node) (bool, error)) error {
func Inspect(pkg *packages.Package, f func(n ast.Node) (bool, error), exclude ...string) error {
for _, file := range pkg.Syntax {
if ast.IsGenerated(file) {
if ExcludeFile(pkg, file, exclude...) {
continue
}
var terr error
Expand Down
28 changes: 28 additions & 0 deletions base/iox/imagex/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"os"
"path/filepath"
"strings"

"cogentcore.org/core/base/num"
)

// TestingT is an interface wrapper around *testing.T
Expand Down Expand Up @@ -56,6 +58,25 @@ func CompareColors(cc, ic color.RGBA, tol int) bool {
return true
}

// DiffImage returns the difference between two images,
// with pixels having the abs of the difference between pixels.
func DiffImage(a, b image.Image) image.Image {
ab := a.Bounds()
di := image.NewRGBA(ab)
for y := ab.Min.Y; y < ab.Max.Y; y++ {
for x := ab.Min.X; x < ab.Max.X; x++ {
cc := color.RGBAModel.Convert(a.At(x, y)).(color.RGBA)
ic := color.RGBAModel.Convert(b.At(x, y)).(color.RGBA)
r := uint8(num.Abs(int(cc.R) - int(ic.R)))
g := uint8(num.Abs(int(cc.G) - int(ic.G)))
b := uint8(num.Abs(int(cc.B) - int(ic.B)))
c := color.RGBA{r, g, b, 255}
di.Set(x, y, c)
}
}
return di
}

// Assert asserts that the given image is equivalent
// to the image stored at the given filename in the testdata directory,
// with ".png" added to the filename if there is no extension
Expand All @@ -77,6 +98,7 @@ func Assert(t TestingT, img image.Image, filename string) {

ext := filepath.Ext(filename)
failFilename := strings.TrimSuffix(filename, ext) + ".fail" + ext
diffFilename := strings.TrimSuffix(filename, ext) + ".diff" + ext

if UpdateTestImages {
err := Save(img, filename)
Expand All @@ -87,6 +109,7 @@ func Assert(t TestingT, img image.Image, filename string) {
if err != nil {
t.Errorf("AssertImage: error removing old fail image: %v", err)
}
os.RemoveAll(diffFilename)
return
}

Expand Down Expand Up @@ -133,10 +156,15 @@ func Assert(t TestingT, img image.Image, filename string) {
if err != nil {
t.Errorf("AssertImage: error saving fail image: %v", err)
}
err = Save(DiffImage(img, fimg), diffFilename)
if err != nil {
t.Errorf("AssertImage: error saving diff image: %v", err)
}
} else {
err := os.RemoveAll(failFilename)
if err != nil {
t.Errorf("AssertImage: error removing old fail image: %v", err)
}
os.RemoveAll(diffFilename)
}
}
6 changes: 6 additions & 0 deletions base/keylist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# keylist

keylist implements an ordered list (slice) of items (Values), with a map from a Key (e.g., names) to indexes, to support fast lookup by name. There is also a Keys slice.

This is a different implementation of the [ordmap](../ordmap) package, and has the advantage of direct slice access to the values, instead of having to go through the KeyValue tuple struct in ordmap.

Loading