Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
- Remove pattern record.
- Remove return call and only keep it for statements.
- Added general await expression.
- Added checks for the children property.
- Remove obselete JS and ObjectSerializer classes.
  • Loading branch information
gdotdesign committed Aug 5, 2024
1 parent 7da5eb1 commit a2b73e0
Show file tree
Hide file tree
Showing 62 changed files with 342 additions and 992 deletions.
32 changes: 4 additions & 28 deletions runtime/src/pattern_matching.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { compare } from "./equality";

// This is a pattern for destructuring records.
class PatternRecord {
constructor(patterns) {
this.patterns = patterns;
}
}

// This is a pattern for destructuring types.
class Pattern {
constructor(variant, pattern) {
Expand All @@ -17,7 +10,6 @@ class Pattern {

// Export functions for creating various patterns.
export const pattern = (variant, pattern) => new Pattern(variant, pattern);
export const patternRecord = (patterns) => new PatternRecord(patterns);

// Symbols to use during pattern matching.
export const patternVariable = Symbol("Variable");
Expand Down Expand Up @@ -94,32 +86,16 @@ export const destructure = (value, pattern, values = []) => {
// This branch covers type variants.
} else if (pattern instanceof Pattern) {
if (value instanceof pattern.variant) {
if (pattern.pattern instanceof PatternRecord) {
if (!destructure(value, pattern.pattern, values)) {
for (let index in pattern.pattern) {
if (
!destructure(value[`_${index}`], pattern.pattern[index], values)
) {
return false;
}
} else {
for (let index in pattern.pattern) {
if (
!destructure(value[`_${index}`], pattern.pattern[index], values)
) {
return false;
}
}
}
} else {
return false;
}
// This branch covers type variants as records.
} else if (pattern instanceof PatternRecord) {
for (let index in pattern.patterns) {
const item = pattern.patterns[index];

if (!destructure(value[item[0]], item[1], values)) {
return false;
}
}
// We compare anything else.
} else {
if (!compare(value, pattern)) {
return false;
Expand Down
1 change: 1 addition & 0 deletions runtime/src/variant.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const variant = (input) => {

for (let index = 0; index < input.length; index++) {
this[input[index]] = args[index];
this[`_${index}`] = args[index];
}
} else {
this.length = input;
Expand Down
11 changes: 0 additions & 11 deletions spec/compilers2/block_with_early_return_2

This file was deleted.

13 changes: 7 additions & 6 deletions spec/compilers2/case_await
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
component Main {
fun render : String {
case await "Hello" {
"test" => true
"Hello" => false
=> false
{
case await "Hello" {
"test" => true
"Hello" => false
=> false
}
}

""
Expand All @@ -14,8 +16,7 @@ import { match as B } from "./runtime.js";

export const A = () => {
(async () => {
let a = await `Hello`;
return B(a, [
return B(await `Hello`, [
[
`test`,
() => {
Expand Down
13 changes: 6 additions & 7 deletions spec/compilers2/destructuring
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ component Main {
key: "KEY")

case item {
Test.Item(content) => content
Test.Item(_, content) => content
Test.None => ""
}
}
}
--------------------------------------------------------------------------------
import {
patternVariable as I,
patternRecord as H,
patternVariable as H,
newVariant as E,
pattern as G,
variant as B,
Expand All @@ -41,10 +40,10 @@ export const
const a = E(A)(`MATCHSTRING`, `CONTENT`, `KEY`);
return F(a, [
[
G(A, H([[
`content`,
I
]])),
G(A, [
null,
H
]),
(b) => {
return b
}
Expand Down
11 changes: 5 additions & 6 deletions spec/compilers2/if_let_await
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ component Main {
--------------------------------------------------------------------------------
import {
patternVariable as H,
newVariant as E,
newVariant as F,
pattern as G,
variant as B,
match as F
match as E
} from "./runtime.js";

export const
A = B(1),
C = B(0),
D = () => {
(async () => {
let a = await E(A)(``);
return F(a, [
return E(await F(A)(``), [
[
G(A, [H]),
(b) => {
return b
(a) => {
return a
}
],
[
Expand Down
27 changes: 10 additions & 17 deletions spec/compilers2/type_with_variants
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
type A {
B(name : String, color : String)
B(name : String, age : Number)
C
}

component Main {
fun render : String {
case (A.B(name: "Joe", color: "Blue")) {
A.B(color, name) => color
case (A.B(name: "Joe", age: 32)) {
A.B(name, age) => name
A.C => ""
}
}
}
--------------------------------------------------------------------------------
import {
patternVariable as I,
patternRecord as H,
patternVariable as H,
newVariant as F,
pattern as G,
variant as B,
Expand All @@ -24,22 +23,16 @@ import {
export const
A = B([
"name",
"color"
"age"
]),
C = B(0),
D = () => {
return E(F(A)(`Joe`, `Blue`), [
return E(F(A)(`Joe`, 32), [
[
G(A, H([
[
`color`,
I
],
[
`name`,
I
]
])),
G(A, [
H,
H
]),
(a, b) => {
return a
}
Expand Down
31 changes: 31 additions & 0 deletions spec/errors/property_children_default_requried
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
component Test {
property children : Array(Html)

fun render : Html {
<div/>
}
}

component Main {
fun render : Html {
<Test/>
}
}
--------------------------------------------------------------------------------
░ ERROR (PROPERTY_CHILDREN_DEFAULT_REQUIRED) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

There should be a default value for the children property:

[]

The property in question is here:

┌ ./spec/errors/property_children_default_requried:2:3
├─────────────────────────────────────────────────────
1│ component Test {
2│ property children : Array(Html)
│ ⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃
3│
4│ fun render : Html {
5│ <div/>
6│ }
35 changes: 35 additions & 0 deletions spec/errors/property_children_mismatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
component Test {
property children : String

fun render : Html {
<div/>
}
}

component Main {
fun render : Html {
<Test/>
}
}
--------------------------------------------------------------------------------
░ ERROR (PROPERTY_CHILDREN_MISMATCH) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

The type of the children property must be:

Array(Html)

Instead it is:

String

The property in question is here:

┌ ./spec/errors/property_children_mismatch:2:3
├─────────────────────────────────────────────
1│ component Test {
2│ property children : String
│ ⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃
3│
4│ fun render : Html {
5│ <div/>
6│ }
14 changes: 0 additions & 14 deletions spec/errors/return_call_expected_expression

This file was deleted.

22 changes: 0 additions & 22 deletions spec/errors/return_call_invalid

This file was deleted.

4 changes: 2 additions & 2 deletions spec/errors/statement_return_type_mismatch
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ I was expecting:

It return call in question is here:

┌ ./spec/errors/statement_return_type_mismatch:9:26
┌ ./spec/errors/statement_return_type_mismatch:9:33
├──────────────────────────────────────────────────
5│
6│ component Main {
7│ fun render : String {
8│ let Test.B(x) =
9│ Test.A("Hello") or return 0
⌃⌃⌃⌃⌃⌃⌃
10│
11│ x
12│ }
Expand Down
19 changes: 19 additions & 0 deletions spec/examples/await
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
component Main {
fun render : String {
{
await "Hello"
}

""
}
}
--------------------------------------------------------------------------------
component Main {
fun render : String {
{
"asd" |> await defer (value : String) { value }
}

""
}
}
3 changes: 3 additions & 0 deletions spec/examples/pipe
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ component Main {
"Hello"
|> await pipe
|> await pipe
|> await pipe
|> await pipe
|> await pipe

value == "asd"
}
Expand Down
14 changes: 14 additions & 0 deletions spec/examples/property
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ component Test {
}
}

component Main {
fun render : Html {
<Test/>
}
}
-----------------------------------------------------property_children_mismatch
component Test {
property children : String

fun render : Html {
<div/>
}
}

component Main {
fun render : Html {
<Test/>
Expand Down
Loading

0 comments on commit a2b73e0

Please sign in to comment.