Skip to content

Pass through JSON #12

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

Merged
merged 2 commits into from
May 2, 2016
Merged

Conversation

sparkprime
Copy link
Collaborator

So the rabbit hole was deeper than I thought... But I believe this is all that is needed for objects, arrays, and strings. No tests. No regrets!

The desugarer is fully laid out but has lots of holes (marked with TODOs). There is no static analysis yet! This will become very important when evaluating functions and thunks, because it is the static analysis phase that fills in the freeVariables for each astNode. Without that, variable lookup will fail if the variable is captured from the environment (instead of being a direct parameter).

Simple objects are added to the interpreter, these are objects formed by { } and not with a comprehension and or by combining two objects with the + operator (a mixin). I left space to add the code for these, but it wasn't necessary for passing through JSON.

The stack is very different to in the C++ version in that it is only used for variable bindings and reconstructing stack traces in errors. It is not used to store partial execution. Likewise the inner interpreter loop is very different and much more readable as it uses simple recursion.

Fixes #11

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.3%) to 75.305% when pulling 6ba40a3 on sparkprime:json_pass_through into c3e4c80 on google:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.3%) to 75.305% when pulling 09c7c8c on sparkprime:json_pass_through into c3e4c80 on google:master.

@sparkprime
Copy link
Collaborator Author

About unit tests and coverage: For the interpreter I think we're good with end-to-end tests. For the desugarer, some unit tests are probably a good idea for development purposes. I'm pretty confident we can get good coverage all the way through with just end-to-end tests (or if not, we can construct more end-to-end tests to get good coverage). However for development, it's nice to have tests that validate particular areas of the code. However, I haven't done this yet.

@jbeda
Copy link
Collaborator

jbeda commented Apr 7, 2016

I've started looking at this but don't have a ton of bandwidth right now (moving, vacation). Let me know if you need me to hurry up.

@sparkprime
Copy link
Collaborator Author

Nah there's no particular pressure on this. I intend to integrate Jsonnet with helm but for a first release of Helm it's fine to use the C++ code, and then we can swap it out for the Go version later when security becomes a concern. I am quite happy with the progress on go-jsonnet so far.

// TODO(jbeda): Add constructor helpers here
// TODO(jbeda): Add the remaining constructor helpers here

func astObjectFieldLocal(methodSugar bool, id *identifier, ids identifiers, trailingComma bool, body astNode) astObjectField {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter: This function is currently unused.

@jbeda
Copy link
Collaborator

jbeda commented Apr 22, 2016

My editor is using gometalinter so that might be useful for annoying to remember golang stuff.

gometalinter --vendor --fast --disable=gocyclo ./...

Looking at code more carefully now. Hopefully I'll be done by end of day. Sorry it took me so long to pick this up again.

// TODO(dcunnin): Remove all uses of unimplErr.
unimplErr := makeStaticError(fmt.Sprintf("Desugarer does not yet implement ast: %s", reflect.TypeOf(ast)), *ast.Loc())

var err error // Make all recursive calls of the form err = desugar, rather than some being err := desugar
Copy link
Collaborator

@jbeda jbeda Apr 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can define this variable as part of the return --

func foo(...) (err error)

Then you can either just return or still return err.

@jbeda
Copy link
Collaborator

jbeda commented Apr 22, 2016

LGTM -- I'm a noob here but it looks reasonable.

@coveralls
Copy link

coveralls commented May 2, 2016

Coverage Status

Coverage decreased (-5.3%) to 75.284% when pulling c5225a1 on sparkprime:json_pass_through into c3e4c80 on google:master.

@sparkprime
Copy link
Collaborator Author

Thanks for review. Took me over a week to actually find time to act on it :) Do you use vim? I just tried gometalinter on the commandline but had problems with errors like this:

static_error.go:20:2:error: could not import fmt (reading export data: /usr/lib/go/pkg/linux_amd64/fmt.a: go archive does not begin with __.SYMDEF or __.GOSYMDEF) (gotype)

and then tons of other errors that I suspect are a knock-on from that.

@sparkprime sparkprime merged commit 70da0b8 into google:master May 2, 2016
@jbeda
Copy link
Collaborator

jbeda commented May 2, 2016

@sparkprime -- I'm using Atom for this project -- just switched for fun. The go support seems pretty good. Sorry I can't help you with vim.

gometalinter isn't a must -- it is probably overkill. Just thought I'd point it out since some of the stuff looks useful.

@sparkprime sparkprime deleted the json_pass_through branch February 16, 2018 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants