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

Std lib improvements: add std.slice and std.manifestJsonMinified, fix handling of numbers in manifestXmlJsonml, handling of code in extCode #171

Merged
merged 7 commits into from Jun 2, 2023

Conversation

lihaoyi-databricks
Copy link
Contributor

@lihaoyi-databricks lihaoyi-databricks commented May 30, 2023

Fixes #110 and #149 and #74 and #56 and #47 and #114 and #76

Mostly straightforward changes, though the constructor signature of Interpeter and Evaluator had to change a bit to satisfy the fixed extCode semantics. Added unit tests to assert the correct behaviors

@lihaoyi-databricks lihaoyi-databricks changed the title Add std.slice and std.manifestJsonMinified Add std.slice and std.manifestJsonMinified, Fix handling of numbers in manifestXmlJsonml May 30, 2023
@lihaoyi-databricks lihaoyi-databricks changed the title Add std.slice and std.manifestJsonMinified, Fix handling of numbers in manifestXmlJsonml Add std.slice and std.manifestJsonMinified, Fix handling of numbers in manifestXmlJsonml, code in extCode May 30, 2023
@lihaoyi-databricks lihaoyi-databricks changed the title Add std.slice and std.manifestJsonMinified, Fix handling of numbers in manifestXmlJsonml, code in extCode Std lib improvements: add std.slice and std.manifestJsonMinified, fix handling of numbers in manifestXmlJsonml, handling of code in extCode May 31, 2023
Comment on lines 748 to 751
val range = collection.immutable.Range(index, end, step)
val res = indexable match{
case Val.Str(pos0, s) => Val.Str(pos, new String(range.map(s.charAt).toArray))
case arr: Val.Arr => new Val.Arr(pos, range.map(arr.asArr.asLazy(_)).toArray)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks extremely inefficient for the 99% of cases with step = 1.

def evalRhs(arg1: Val, arg2: Val, arg3: Val, arg4: Val, ev: EvalScope, pos: Position): Val

override def apply(argVals: Array[_ <: Lazy], namedNames: Array[String], outerPos: Position)(implicit ev: EvalScope): Val =
if(namedNames == null && argVals.length == 3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be argVals.length == 4

@lihaoyi-databricks lihaoyi-databricks merged commit f630749 into master Jun 2, 2023
1 check passed
lihaoyi-databricks added a commit that referenced this pull request Jun 6, 2023
Similar to the `--ext-code` changes in
#171, `--tla-code` is meant
to be able to take arbitrary Jsonnet code just like `--ext-code` can,
and before this PR we limited it to only JSON

I refactored out the common `Interpreter#parseVar` logic so it can be
shared between both, and added new tests to exercise the new behavior.

The `override def evalDefault` for the `Val.Func` used for top-level
functions needed to be fixed; there was always a logical issue
evaluating the `--tla-code` expression using the main file's `ValScope`,
but it didn't matter since previously we only allowed JSON so there
weren't any identifiers to look up using it. Now that there are, the
correct thing to do is to evaluate the `--tla-code` expression using
`ValScope.empty`, since it is meant to be a standalone expression
without any existing local bindings in its lexical scope

Notably, `--tla-code` expressions cannot reference each other the way
`--ext-code` expressions can, so there is no equivalent to the
`stdExtVarRecursive` test case. They can still call `std` functions, so
the `std` test case remains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add std.manifestJsonMinified
2 participants