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

Make supplier a library type instead of a built-in type #213

Open
3 tasks
MeAmAnUsername opened this issue Dec 16, 2021 · 0 comments
Open
3 tasks

Make supplier a library type instead of a built-in type #213

MeAmAnUsername opened this issue Dec 16, 2021 · 0 comments
Labels
Component: code base The code quality of the project (does not affect functionality) Component: DSL Something that concerns the design of PIE DSL Priority: low Status: proposal Enhancement in the proposal stage Type: enhancement New feature or request

Comments

@MeAmAnUsername
Copy link
Owner

Short description
Suppliers can be regular library types, their only special traits are that they are the return value of a task supplier call (task.supplier(args)) and that they generate special Java code.

Todo list

  • Add suppliers to PIE standard library and publish the library
  • Make the standard library definition of mb.pie.api.Supplier the return value of task suppliers
  • Modify compiler to generate correct code for Supplier#get

Reason
As a built-in type every part of the language definition needs to be aware of this type. Task suppliers do not require a special built-in supplier type (requires #157). This would remove the supplier type and function from the syntax and static semantics, and possibly a whole bunch of SPT tests for suppliers (we could keep them, although that would require access to the standard library from within SPT tests).
Making the language definition smaller also decreases the amount of special cases users need to remember when learning the language.

Implementation
Definition in the pie standard library:

data Supplier[T] = foreign java mb.pie.api.Supplier {
  func get() -> T
}
func supplier[T](value: T) -> Supplier[T] = foreign java constructor mb.pie.api.Supplier

The compiler can introduce a check in p2j-ast-call: QCall that checks the implementation of the type, and if it is mb.pie.api.Supplier, generate special code:

p2j-ast-call: QCall(exp, name, args) -> result
  where
    "get" := <remove-annotations> name
  ; ty := <get-type> exp
  ; decl := <get-decl> ty
  ;  ForeignJavaDataImpl(impl) := <get-implementation> decl
  ; "mb.pie.api.Supplier" := <remove-annotations> impl
  with
    // generate code for supplier.get call

p2j-ast-call: QCall(exp, name, args) -> result
  with
    // normal code generation for QCalls

    

Related issues

@MeAmAnUsername MeAmAnUsername added Type: enhancement New feature or request Status: proposal Enhancement in the proposal stage Component: DSL Something that concerns the design of PIE DSL Component: code base The code quality of the project (does not affect functionality) Priority: low labels Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: code base The code quality of the project (does not affect functionality) Component: DSL Something that concerns the design of PIE DSL Priority: low Status: proposal Enhancement in the proposal stage Type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant