mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-07 23:07:14 +02:00
* Interpreter & runtime - minimal usable version Accomplishments in this commit: * Majority of language features implemented: * Unary operators * Binary operators * Conditionals * Errors * Indexing arrays * Indexing objects * Object inheritance * Imports * Functions * Function calls * There is a quite nice way for creating builtins * Static analyzer is there with most of the functionality * Standard library is included and parts unaffected by missing features work * Some bugs in existing parts fixed * Most positive tests from C++ version pass, the rest is failing mostly due to missing builtins and comprehensions. * Some initial structure was created that should allow more incremental and focused changes in the future PRs. * Some comments/explanations added * Panics translated to a little bit more gentle internal errors (with a link to issues on github). What still sucks: * Stack traces & error messages (there's some stuff in place) * Almost everything is in the same package * Stuff is exported or unexporeted randomly (see above) * Missing a few lexing/parsing features * Missing builtins * Missing support for extvars and top-level-args * Checking function arguments is missing * No clean Go API that commandline and compatibility layer to C can use * No compatibility layer to C * Assertions don't work (desugaring level, assertEquals works). * Manifestation stack traces (and generally it could use some work). * The way environments are constructed is sometimes suboptimal/clumsy.
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
/*
|
|
Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package jsonnet
|
|
|
|
// RuntimeError is an error discovered during evaluation of the program
|
|
type RuntimeError struct {
|
|
StackTrace []TraceFrame
|
|
Msg string
|
|
}
|
|
|
|
func makeRuntimeError(msg string, stackTrace []TraceFrame) RuntimeError {
|
|
return RuntimeError{
|
|
Msg: msg,
|
|
StackTrace: stackTrace,
|
|
}
|
|
}
|
|
|
|
func (err RuntimeError) Error() string {
|
|
return "RUNTIME ERROR: " + err.Msg
|
|
}
|
|
|
|
// The stack
|
|
|
|
// TraceFrame is tracing information about a single frame of the call stack.
|
|
// TODO(sbarzowski) the difference from TraceElement. Do we even need this?
|
|
type TraceFrame struct {
|
|
Loc LocationRange
|
|
Name string
|
|
}
|
|
|
|
func traceElementToTraceFrame(trace *TraceElement) TraceFrame {
|
|
tf := TraceFrame{Loc: *trace.loc}
|
|
if trace.context != nil {
|
|
// TODO(sbarzowski) maybe it should never be nil
|
|
tf.Name = trace.context.Name
|
|
} else {
|
|
tf.Name = ""
|
|
}
|
|
return tf
|
|
}
|
|
|
|
type TraceContext struct {
|
|
|
|
// Human readable name - e.g. function <foo>
|
|
Name string
|
|
}
|
|
|
|
// TODO(sbarzowski) better name
|
|
type TraceElement struct {
|
|
loc *LocationRange
|
|
context *TraceContext
|
|
}
|