Skip to content

Commit

Permalink
[MOREL-27] Create objects for built-in structures List and String
Browse files Browse the repository at this point in the history
…, and allow `structure.name` references

Previously we had values structure_name, for example `List_hd`
and `List_tl`; these are now replaced with a value for each
structure.  For example value `List` has fields `hd`, `tl`.
Similarly `String`, `Sys`, `Relational`.
  • Loading branch information
julianhyde committed May 3, 2020
1 parent 93b9a0e commit 20d08bd
Show file tree
Hide file tree
Showing 20 changed files with 758 additions and 575 deletions.
13 changes: 12 additions & 1 deletion src/main/java/net/hydromatic/morel/ast/AstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,19 @@ public Ast.Aggregate aggregate(Pos pos, Ast.Exp aggregate, Ast.Exp argument,
return new Ast.Aggregate(pos, aggregate, argument, id);
}

/** Returns a reference to a built-in: either a name (e.g. "true")
* or a field reference (e.g. "#hd List"). */
private Ast.Exp ref(Pos pos, BuiltIn builtIn) {
if (builtIn.structure == null) {
return id(pos, builtIn.mlName);
} else {
return apply(id(pos, builtIn.structure),
id(pos, builtIn.mlName));
}
}

public Ast.Exp map(Pos pos, Ast.Exp e1, Ast.Exp e2) {
return apply(apply(id(pos, BuiltIn.LIST_MAP.mlName), e1), e2);
return apply(apply(ref(pos, BuiltIn.LIST_MAP), e1), e2);
}

public Ast.Order order(Pos pos, Iterable<Ast.OrderItem> orderItems) {
Expand Down
Loading

0 comments on commit 20d08bd

Please sign in to comment.