Skip to content

Commit

Permalink
unioned dir and embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
millergarym committed Apr 27, 2023
1 parent a09b0ca commit bc5c6ab
Show file tree
Hide file tree
Showing 23 changed files with 2,100 additions and 237 deletions.
49 changes: 39 additions & 10 deletions adl/adlc/adlc/packaging.adl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import sys.adlast2.ScopedName;
import sys.adlast2.Module1;

// AdlWorkspace0 is the serilization format
type AdlWorkspace0 = AdlWorkspace<AdlPackageRef>;
type AdlWorkspace0 = AdlWorkspace<Payload0>;
type AdlWorkspace1 = AdlWorkspace<Payload1>;
type AdlWorkspace2 = AdlWorkspace<Payload2>;

type LoaderWorkspace = AdlWorkspace<LoaderRef>;

type Payload0 = AdlPackageRef;

struct Payload1 {
AdlPackageRef p_ref;
AdlPackage pkg;
Expand All @@ -31,7 +33,7 @@ struct AdlWorkspace<T> {
String adlc;
Vector<T> use;
Vector<RuntimeOpts> runtimes = [];
Maybe<T> embedded_sys_loader;
// Maybe<T> embedded_sys_loader;
};

// = {
Expand Down Expand Up @@ -71,22 +73,54 @@ struct TsWriteRuntime {

/// The struct in AdlWorkspace::use required by the WorkspaceLoader
struct LoaderRef {
String path;
Nullable<String> global_alias = null;
LoaderRefType ref;
InjectAnnotations loader_inject_annotate = [];
InjectAnnotations resolver_inject_annotate = [];
};

union LoaderRefType {
DirLoaderRef dir;
EmbeddedLoaderRef embedded;
};

struct DirLoaderRef {
String path;
Nullable<String> global_alias = null;
};

struct EmbeddedLoaderRef {
EmbeddedPkg alias;
};

type InjectAnnotations = Vector<InjectAnnotation>;

union InjectAnnotation {
Pair<ScopedName,Json> module_;
};

struct AdlPackageRef {
AdlPackageRefType ref;
Nullable<TypescriptGenOptions> ts_opts = null;
};

union AdlPackageRefType {
DirectoryRef dir;
/// An ADL module embed in the ADL compiler
EmbeddedRef embedded;
};

struct EmbeddedRef {
EmbeddedPkg alias;
};

union EmbeddedPkg {
Void sys;
Void adlc;
};

struct DirectoryRef {
// path must be to a directory directly under the folder containing the `adl.work.json` file.
String path;
Nullable<TypescriptGenOptions> ts_opts = null;
};

struct TypescriptGenOptions {
Expand Down Expand Up @@ -227,11 +261,6 @@ struct TsCompilerOptions {
Vector<String> lib;
};

// union DependencySpec {
// Void workspace;
// VersionSpec semverSpec;
// };

struct NpmPackageRef {
String name;
VersionSpec version;
Expand Down
122 changes: 102 additions & 20 deletions rust/compiler/src/adlgen/adlc/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

use crate::adlgen::sys::adlast2::Module1;
use crate::adlgen::sys::adlast2::ScopedName;
use crate::adlrt::custom::sys::types::maybe::Maybe;
use crate::adlrt::custom::sys::types::pair::Pair;
use serde::Deserialize;
use serde::Serialize;

pub type AdlWorkspace0 = AdlWorkspace<AdlPackageRef>;
pub type AdlWorkspace0 = AdlWorkspace<Payload0>;

pub type AdlWorkspace1 = AdlWorkspace<Payload1>;

pub type AdlWorkspace2 = AdlWorkspace<Payload2>;

pub type LoaderWorkspace = AdlWorkspace<LoaderRef>;

pub type Payload0 = AdlPackageRef;

#[derive(Clone,Debug,Deserialize,Eq,PartialEq,Serialize)]
pub struct Payload1 {
pub p_ref: AdlPackageRef,
Expand Down Expand Up @@ -62,17 +63,14 @@ pub struct AdlWorkspace<T> {

#[serde(default="AdlWorkspace::<T>::def_runtimes")]
pub runtimes: Vec<RuntimeOpts>,

pub embedded_sys_loader: Maybe<T>,
}

impl<T> AdlWorkspace<T> {
pub fn new(adlc: String, r#use: Vec<T>, embedded_sys_loader: Maybe<T>) -> AdlWorkspace<T> {
pub fn new(adlc: String, r#use: Vec<T>) -> AdlWorkspace<T> {
AdlWorkspace {
adlc: adlc,
r#use: r#use,
runtimes: AdlWorkspace::<T>::def_runtimes(),
embedded_sys_loader: embedded_sys_loader,
}
}

Expand Down Expand Up @@ -129,10 +127,8 @@ impl TsWriteRuntime {
*/
#[derive(Clone,Debug,Deserialize,PartialEq,Serialize)]
pub struct LoaderRef {
pub path: String,

#[serde(default="LoaderRef::def_global_alias")]
pub global_alias: Option<String>,
#[serde(rename="ref")]
pub r#ref: LoaderRefType,

#[serde(default="LoaderRef::def_loader_inject_annotate")]
pub loader_inject_annotate: InjectAnnotations,
Expand All @@ -142,19 +138,14 @@ pub struct LoaderRef {
}

impl LoaderRef {
pub fn new(path: String) -> LoaderRef {
pub fn new(r#ref: LoaderRefType) -> LoaderRef {
LoaderRef {
path: path,
global_alias: LoaderRef::def_global_alias(),
r#ref: r#ref,
loader_inject_annotate: LoaderRef::def_loader_inject_annotate(),
resolver_inject_annotate: LoaderRef::def_resolver_inject_annotate(),
}
}

pub fn def_global_alias() -> Option<String> {
None
}

pub fn def_loader_inject_annotate() -> InjectAnnotations {
vec![]
}
Expand All @@ -164,6 +155,49 @@ impl LoaderRef {
}
}

#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub enum LoaderRefType {
#[serde(rename="dir")]
Dir(DirLoaderRef),

#[serde(rename="embedded")]
Embedded(EmbeddedLoaderRef),
}

#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub struct DirLoaderRef {
pub path: String,

#[serde(default="DirLoaderRef::def_global_alias")]
pub global_alias: Option<String>,
}

impl DirLoaderRef {
pub fn new(path: String) -> DirLoaderRef {
DirLoaderRef {
path: path,
global_alias: DirLoaderRef::def_global_alias(),
}
}

pub fn def_global_alias() -> Option<String> {
None
}
}

#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub struct EmbeddedLoaderRef {
pub alias: EmbeddedPkg,
}

impl EmbeddedLoaderRef {
pub fn new(alias: EmbeddedPkg) -> EmbeddedLoaderRef {
EmbeddedLoaderRef {
alias: alias,
}
}
}

pub type InjectAnnotations = Vec<InjectAnnotation>;

#[derive(Clone,Debug,Deserialize,PartialEq,Serialize)]
Expand All @@ -174,16 +208,17 @@ pub enum InjectAnnotation {

#[derive(Clone,Debug,Deserialize,Eq,PartialEq,Serialize)]
pub struct AdlPackageRef {
pub path: String,
#[serde(rename="ref")]
pub r#ref: AdlPackageRefType,

#[serde(default="AdlPackageRef::def_ts_opts")]
pub ts_opts: Option<TypescriptGenOptions>,
}

impl AdlPackageRef {
pub fn new(path: String) -> AdlPackageRef {
pub fn new(r#ref: AdlPackageRefType) -> AdlPackageRef {
AdlPackageRef {
path: path,
r#ref: r#ref,
ts_opts: AdlPackageRef::def_ts_opts(),
}
}
Expand All @@ -193,6 +228,53 @@ impl AdlPackageRef {
}
}

#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub enum AdlPackageRefType {
#[serde(rename="dir")]
Dir(DirectoryRef),

/**
* An ADL module embed in the ADL compiler
*/
#[serde(rename="embedded")]
Embedded(EmbeddedRef),
}

#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub struct EmbeddedRef {
pub alias: EmbeddedPkg,
}

impl EmbeddedRef {
pub fn new(alias: EmbeddedPkg) -> EmbeddedRef {
EmbeddedRef {
alias: alias,
}
}
}

#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub enum EmbeddedPkg {
#[serde(rename="sys")]
Sys,

#[serde(rename="adlc")]
Adlc,
}

#[derive(Clone,Debug,Deserialize,Eq,Hash,PartialEq,Serialize)]
pub struct DirectoryRef {
pub path: String,
}

impl DirectoryRef {
pub fn new(path: String) -> DirectoryRef {
DirectoryRef {
path: path,
}
}
}

#[derive(Clone,Debug,Deserialize,Eq,PartialEq,Serialize)]
pub struct TypescriptGenOptions {
pub npm_pkg_name: String,
Expand Down
Loading

0 comments on commit bc5c6ab

Please sign in to comment.