Commit Graph

67 Commits

Author SHA1 Message Date
Rafael Weinstein
1676707906 WriteValue returns RefBase 2016-04-11 17:09:25 -07:00
Erik Arvidsson
9e4266871e JS CodeGen: Add newSetOfT etc (#1195)
* JS CodeGen: Add newSetOfT etc

This generates convenience functions for new list/set/map.

Issue #1081
2016-04-08 15:01:08 -07:00
Erik Arvidsson
ea51e1ccfc Handle imports in js codegen
Issue #1081
2016-04-06 11:46:13 -07:00
Erik Arvidsson
1014573c7e Codegen for enum types
This generates a flow type for enums:

```noms
enum Handedness {
  right
  left
  switch
}
```

Generates

```js
type E =
  0 |  // right
  1 |  // left
  2;  // switch
```

Issue #1081
2016-04-05 15:12:04 -07:00
Erik Arvidsson
d1a6fbe0c7 Codegen for flow struct types.
This generates the a flow interface for structs defined in noms files

Issue #1157
Issue #1081
2016-04-05 14:19:08 -07:00
Erik Arvidsson
870f5b1420 NomDL JS CodeGen
This is the first step towards generating JS code from NomDL.

At this point, only the code to create and register the
Package is done.
2016-03-30 13:19:33 -07:00
Erik Arvidsson
31d1830dbe NomDL: Reenable codegen test
When we restructured the directory structure we failed to update the
tests and we lost some test coverage.
2016-03-29 15:40:41 -07:00
Chris Masone
119a56c3a9 Move ReadValue and WriteValue to DataStore
This patch is the first step in moving all reading and writing to the
DataStore API, so that we can validate data commited to Noms.

The big change here is that types.ReadValue() no longer exists and is
replaced with a ReadValue() method on DataStore. A similar
WriteValue() method deprecates types.WriteValue(), but fully removing
that is left for a later patch. Since a lot of code in the types
package needs to read and write values, but cannot import the datas
package without creating an import cycle, the types package exports
ValueReader and ValueWriter interfaces, which DataStore implements.
Thus, a DataStore can be passed to anything in the types package which
needs to read or write values (e.g. a collection constructor or
typed-ref)

Relatedly, this patch also introduces the DataSink interface, so that
some public-facing apis no longer need to provide a ChunkSink.

Towards #654
2016-03-17 12:57:44 -07:00
Aaron Boodman
2fbe923ee9 Remove unnecessary godep flag 2016-02-09 11:06:10 -08:00
Aaron Boodman
cff0de3696 non-vendor changes 2016-02-08 23:15:09 -08:00
Rafael Weinstein
6c3239a1d0 Collections no longer need a ChunkStore on creation 2016-02-02 13:39:26 -08:00
Erik Arvidsson
a44b2ff6e3 Merge pull request #883 from arv/codegen-ref-bug
Fix issue with canUseDef
2016-01-20 15:15:33 -08:00
Erik Arvidsson
4482eed74c Fix issue with canUseDef
We were not passing the package through when we called
containsComparable which made us lookup the type in the wrong package.

Fixes #869
2016-01-20 13:27:48 -08:00
Benjamin Kalman
833d581115 Add a -godep flag to codegen to can generate godep compatible code.
This specifies the name of the package using nomdl through godep, which
is applied as a prefix to github.com/attic-labs/noms imports.

For example, -godep=github.com/foo/bar generates imports to
"github.com/foo/bar/Godeps/_workspace/src/github.com/attic-labs/noms".
2016-01-19 11:40:26 -08:00
Dan Willhite
699cc2accc Fixes #687.
Make dataStoreCommon.doCommit() return an error instead of boolean.
2015-12-02 16:41:00 -08:00
Erik Arvidsson
61f14f8c9a Rename noms UInt* to Uint*
Fixes #673
2015-12-02 12:01:42 -05:00
Erik Arvidsson
ff8924db09 NomDL codegen: Fix clobbering
If two files depend on the same file we ended up overwriting the
first written file which is problematic because the "internal" types
would not be written the second time.
2015-12-01 15:02:04 -05:00
Rafael Weinstein
7caa08bc5c Complex Types embed a ChunkStore 2015-12-01 10:40:47 -08:00
Erik Arvidsson
a72ce41a1d Go: TypeRef -> Type
Remaining identifiers
2015-11-13 17:54:53 -05:00
Chris Masone
eda9b92870 Rename types.TypeRef to types.Type
There are probably still a lot of variable names and comments to fix,
but this updates all the Go code.

Towards #441
2015-11-09 08:26:32 -08:00
Erik Arvidsson
756b893e8f Remove FromVal functions
The generated objects are all type.Values now so FromVal is not needed
2015-11-04 12:13:55 -05:00
Erik Arvidsson
9aadd85004 Add types.Struct and improve typed structs
The generated code for typed structs now uses a Go struct which
implements Value directly. The fields in this struct uses the "user"
type. (The union value still uses types.Value though.)

When a typed struct is created by the decoder, it asks for a struct
builder which returns a channel that the values of the fields of the
struct are sent to.
2015-11-04 11:55:07 -05:00
Chris Masone
d3162c9081 Fix botched handling of -in with -out-dir
The output file should always be emitted relative to -out-dir. I was
incorrectly appending the path to the input file onto that provided in
-out-dir to construct the path to the output file.
2015-11-02 14:14:43 -08:00
Chris Masone
a64cee5aab Clean up codegen -out-dir flag handling
Get rid of -out and ensure that Go package names generated from -out-dir
are actually legal Go identifiers.

Fixes #476
2015-11-02 12:17:42 -08:00
Dan Willhite
42bac09422 Make sfcrime/quad_tree apps work with new nomsdl types.
Change generated files to <base>.noms.go
2015-10-30 10:23:15 -07:00
Dan Willhite
13b2cf5702 Three mods to codegen.
1) truncate filenames containing hash to only use first 7 chars of hash.
2) change output filename from <base>.go to <base>_noms.go
3) check for includes of file in same directory and don't generate twice.
2015-10-28 14:28:15 -07:00
Chris Masone
2cd6831598 Changes codegen.go to emit all code in a single Go package
Fixes #467
2015-10-23 16:42:54 -07:00
Erik Arvidsson
91e7ffb8e1 NomDL Codegen: Parameterize the types package
This allows us to use the codegen from types/ without manual touchups
2015-10-23 11:04:30 -04:00
Erik Arvidsson
91f720be81 NomDL: Need to include the deps in the package 2015-10-21 09:17:35 -04:00
Erik Arvidsson
d6869cef35 NomDL: Make Package a primitive type
This solves the bootstrapping problems we are encountering.

Previously Package was a Struct but structs depend on Package.
2015-10-20 10:26:00 -04:00
cmasone-attic
272a4632c5 Merge pull request #429 from cmasone-attic/issue420
pkg.Parsed should embed a types.Package, not a types.PackageDef
2015-10-19 11:26:04 -07:00
Chris Masone
e249f11347 pkg.Parsed should embed a types.Package, not a types.PackageDef
Doing so makes it so we don't create new Package instances all over codegen.go

Fixes #420
2015-10-19 11:22:16 -07:00
Chris Masone
f9e39f1b89 NewDataset() should refuse to accept "" as the datasetID
Also, update codegen.go to use a sensical default if nothing is provided
on the command line.
2015-10-19 10:45:53 -07:00
Chris Masone
9b225dce9b Introduce UnresolvedKind, so TypeRefKind isn't overloaded.
We'd wound up in a spot where serialization code used 'TypeRefKind' to
mean one of two very different things...either an actual value that
describes some Noms type, or a reference to a type definition that
lives somewhere else. To get rid of this ambiguity, we introduce
'UnresolvedKind' to take over the latter meaning. Now, TypeRefKind
means _only_ a value that describes a type. If you want to point off
to a type definition elsewhere in the type package, or in another
type package, use UnresolvedKind.
2015-10-19 09:58:27 -07:00
Erik Arvidsson
e9f5b1e2b5 NomDL codegen: Clean up write and improve ordering
Now we write the named types first, then the using types and finally
the inline type defs in the order that they were defined.
2015-10-19 11:39:58 -04:00
Erik Arvidsson
ba5139a5c4 NomDL codegen: Followup cleanup
Just renaming the parameters back to normal names
2015-10-19 09:35:34 -04:00
Erik Arvidsson
36d9362628 NomDL: Use ordinal for unresolved type refs
Instead of using the name of the type we now use the index of the type
in the Package that defines it.
2015-10-16 17:46:15 -04:00
Chris Masone
3e43c58320 Import .noms files by path
.noms files can now import other .noms files by relative or absolute path.

Fixes #399
2015-10-14 15:03:50 -07:00
Erik Arvidsson
6185ea1ddb NomDL: Use a list for the types in the package
This does not yet update the serialization to use the ordinal.
2015-10-14 14:49:04 -04:00
Chris Masone
56cd548328 Support compounding types with imported types.
Sets, Lists, Refs and Maps of imported types work now.

This PR also factors some of codegen.go into a separate package, to slim down
that file a bit.

Towards issue #294
2015-10-12 15:29:45 -07:00
Chris Masone
bccdcc22ad Remove commented out test code
And replace it with something that verifies that generated dependency code
is imported correctly.

Also address other nits.
2015-10-09 17:09:04 -07:00
Chris Masone
cc15992778 Initial support for importing type pacakges by ref
Towards #294
2015-10-09 15:19:06 -07:00
Dan Willhite
b20b1c42cd Add MaybeGet method to generated Map types. 2015-10-07 13:40:34 -07:00
Erik Arvidsson
2dec53453e NomDL: Add new serialization format
The new serialization format use "t " as in typed. The rest of the
message is a JSON array describing the typed data. The type is
described by types.TypeRef

Fixes #384
Issues #281, #304
2015-10-06 15:56:10 -07:00
Chris Masone
646519131c Address comments 2015-10-05 15:40:35 -07:00
Chris Masone
3dc61b673c Add functions to codegen.go for generating dependency code
This adds code for finding imported type packages and generating
code for them, but does not yet handle generating code that uses
those types.

Towards issue #294
2015-10-04 18:05:50 -04:00
Erik Arvidsson
8c2caa3b27 NomDL Codegen: Add TypeRef method to typed objects 2015-09-30 17:48:32 -04:00
Chris Masone
9168a902f9 Modify codegen to include pacakge refs for unresolved types
Also, switch to using a ref.Ref when getting/setting the package
ref in a TypeRef. Using a types.Ref just led to lots of manual
boxing and unboxing every time I wanted to use the reference.

Toward issue #294
2015-09-29 12:58:56 -07:00
Chris Masone
5ce93dad2e Beginning of import support in NomDL
This patch mostly merges parse.Package and types.Package, though it
can't quite go all the way. A types.Package doesn't have 'using'
declarations, while the parsed representation of a .noms file needs to
have that information. Hence, the parse package is moved to the 'pkg'
package, and pkg.Parsed is introduced. This type embeds types.Package
and adds the necessary additional information.

To make inroads on handling imports, I enhanced ParsePackage() (now
called ParseNomDL()) to actually process the 'alias' and 'import'
statements in the input and go replace namespaced type names in the
package with refs of imported packages. For example, the TypeRef for
'Bar' generated in the following package

alias Foo = import "sha1-ffffffff"

struct Bar {
  f: Foo.RockinStruct
}

will actually return types.Ref{sha1-ffffffff} when you call PackageRef()
on it.

In addition, I've added a function to the new 'pkg' package,
which allows the caller to get the dependencies of a type package
from a chunk store.

Fixes issue #353, towards issue #294
2015-09-28 16:08:22 -07:00
Chris Masone
c80a1c55b3 Merge parse.TypeRef and types.TypeRef
These were two representations of, essentially, the same information.
They were separate because they provided different APIs to similar
information, but the APIs became more similar once we started using
native types (as opposed to Noms types) for the various Make*TypeRef()
functions.

Unifying these is a big step to unifying parse.Package and types.Package,
which is pretty necessary for dealing with imported packages.

Fixes issue #338
2015-09-25 15:17:49 -07:00