Skip to content

docs: compile with mago compile, add Iterable and Object, make output a call - #21

Merged
heyJordanParker merged 1 commit into
masterfrom
docs/shift-overflow
Oct 6, 2026
Merged

heyJordanParker merged 1 commit into
masterfrom
docs/shift-overflow

Conversation

@heyJordanParker

Copy link
Copy Markdown
Owner

docs: compile with mago compile, add Iterable and Object, make output a call

Typed compilation was approved without saying how code gets compiled and
run. A lazy plain PHP source such as a query cursor had no PHP# type, nor
did any object. And PHP's echo, print and die stayed outside the effect
system, with die("…") reporting success while it prints a failure.

Compile and run PHP# with mago compile:

  • vendor/bin/mago compile writes each accepted .sharp file as a .sharpc
    file in one .sharp/ folder at the project root, vendor included
  • The engine runs only current compiled files, and refuses a missing,
    stale or mismatched one with a message that names the fix
  • In development, sharp.compile_command compiles a stale file on demand
  • A type error or a broken structure rule stops the file from running
  • Rejected: each file compiles alone, and the engine receiving the types
    beside the source

Read anything a loop can read with Iterable:

  • List, Set and a Map's values are Iterable, compiled to PHP's iterable
  • filter, map and take are lazy, and run only when toList() or a loop
    reads them
  • A lazy plain PHP source is checked element by element as it is read
  • Rejected: an Iterable that only a loop reads

Hold any object with Object:

  • Object compiles to PHP's object, and Object? adds null
  • It has no members until is narrows it, and passes where Any is expected
  • Rejected: Swift's AnyObject

Print and exit with function calls:

  • echo and print are compile errors that name printf or fwrite
  • die is a compile error: write the message to STDERR, then exit(1)
  • exit(code) stays, skips finally blocks, and is not pure
  • Rejected: PHP's forms as they are

docs/
├── spec.md <- sections 8, 12, 17, 24, 27, 28 and 29
└── decisions/
├── 029-typed-compilation.md <- records mago compile and .sharp/
├── 033-iterable.md <- added, records lazy Iterable
├── 034-output-and-exit.md <- added, records output as calls
└── 035-object.md <- added, records Object

… a call

Typed compilation was approved without saying how code gets compiled and
run. A lazy plain PHP source such as a query cursor had no PHP# type, nor
did any object. And PHP's echo, print and die stayed outside the effect
system, with die("…") reporting success while it prints a failure.

Compile and run PHP# with mago compile:
- vendor/bin/mago compile writes each accepted .sharp file as a .sharpc
  file in one .sharp/ folder at the project root, vendor included
- The engine runs only current compiled files, and refuses a missing,
  stale or mismatched one with a message that names the fix
- In development, sharp.compile_command compiles a stale file on demand
- A type error or a broken structure rule stops the file from running
- Rejected: each file compiles alone, and the engine receiving the types
  beside the source

Read anything a loop can read with Iterable<T>:
- List, Set and a Map's values are Iterable<T>, compiled to PHP's iterable
- filter, map and take are lazy, and run only when toList() or a loop
  reads them
- A lazy plain PHP source is checked element by element as it is read
- Rejected: an Iterable that only a loop reads

Hold any object with Object:
- Object compiles to PHP's object, and Object? adds null
- It has no members until is narrows it, and passes where Any is expected
- Rejected: Swift's AnyObject

Print and exit with function calls:
- echo and print are compile errors that name printf or fwrite
- die is a compile error: write the message to STDERR, then exit(1)
- exit(code) stays, skips finally blocks, and is not pure
- Rejected: PHP's forms as they are

docs/
├── spec.md                          <- sections 8, 12, 17, 24, 27, 28 and 29
└── decisions/
    ├── 029-typed-compilation.md     <- records mago compile and .sharp/
    ├── 033-iterable.md              <- added, records lazy Iterable<T>
    ├── 034-output-and-exit.md       <- added, records output as calls
    └── 035-object.md                <- added, records Object
@heyJordanParker
heyJordanParker merged commit ff8b3f6 into master Oct 6, 2026
7 checks passed
@heyJordanParker
heyJordanParker deleted the docs/shift-overflow branch November 3, 2026 22:08
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.

1 participant