Skip to content

Commit 8caef68

Browse files
committed
✨ Compilation
1 parent c68b653 commit 8caef68

12 files changed

+886
-23
lines changed

gleam.toml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ gleam_stdlib = "~> 0.34 or ~> 1.0"
1717
chomp = { path = "../chomp-nibble" }
1818
gleam_community_ansi = ">= 1.4.0 and < 2.0.0"
1919
hug = "~> 1.0"
20+
glam = ">= 2.0.0 and < 3.0.0"
21+
dedent = ">= 1.0.0 and < 2.0.0"
2022

2123
[dev-dependencies]
2224
gleeunit = "~> 1.0"

manifest.toml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ packages = [
55
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
66
{ name = "birdie", version = "1.1.2", build_tools = ["gleam"], requirements = ["argv", "filepath", "glance", "gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "justin", "rank", "simplifile", "trie_again"], otp_app = "birdie", source = "hex", outer_checksum = "F9666AEB5F6EDFAE6ADF9DFBF10EF96A4EDBDDB84B854C29B9A3F615A6436311" },
77
{ name = "chomp", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], source = "local", path = "../chomp-nibble" },
8+
{ name = "dedent", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "dedent", source = "hex", outer_checksum = "591C78F019CFE8B4F138BDCA5DB57EB429D95F90CD12B51262A3FC6455EC1AEF" },
89
{ name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" },
910
{ name = "glam", version = "2.0.0", build_tools = ["gleam"], requirements = ["birdie", "gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "1C10BE5EA72659E409DC2325BA5E94E0CC92C6C50B2A1DBADE6D07E8C9484D51" },
1011
{ name = "glance", version = "0.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "4866132929EAA47649FBBDBD7C4FDBEB7E30938AA34561E4486640D8ABDE3C88" },
@@ -26,6 +27,8 @@ packages = [
2627

2728
[requirements]
2829
chomp = { path = "../chomp-nibble" }
30+
dedent = { version = ">= 1.0.0 and < 2.0.0" }
31+
glam = { version = ">= 2.0.0 and < 3.0.0" }
2932
gleam_community_ansi = { version = ">= 1.4.0 and < 2.0.0" }
3033
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
3134
gleeunit = { version = "~> 1.0" }

src/spark.gleam

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gleam/io
22
import gleam/result
3-
import pprint
3+
import spark/compile
44
import spark/error
55
import spark/lex
66
import spark/parse
@@ -54,7 +54,7 @@ pub fn main() {
5454
5555
def then\\action, f =
5656
@IO {
57-
perform: \\ -> action |> perform |> f |> perform
57+
perform: \\ -> f(action.perform()).perform()
5858
}
5959
6060
def perform\\action =
@@ -71,12 +71,13 @@ pub fn main() {
7171
let result = {
7272
use tokens <- result.try(lex.lex(source))
7373
use ast <- result.try(parse.parse(tokens))
74-
Ok(ast)
74+
let compiled = compile.compile(ast)
75+
Ok(compiled)
7576
}
7677

7778
case result {
78-
Ok(ast) -> {
79-
pprint.debug(ast)
79+
Ok(js) -> {
80+
io.println(js)
8081
Nil
8182
}
8283
Error(e) ->

src/spark/ast.gleam

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ pub type Module {
1818
/// - Any paths: ["bar", "baz"]
1919
/// - An optional rename: Some("blah")
2020
///
21+
/// The path list is guaranteed to have at least one element by the parser.
22+
///
2123
pub type Import {
22-
Import(base: String, path: List(String), rename: Option(String))
24+
Import(path: List(String), rename: Option(String))
2325
}
2426

2527
/// A declaration is something at the top-level of a module.
@@ -48,9 +50,12 @@ pub type Publicity {
4850
/// language.
4951
///
5052
pub type Expression {
51-
Number(value: Float)
53+
Int(value: Int)
54+
Float(value: Float)
5255
String(value: String)
5356
Variable(name: String)
57+
Atom(name: String, payload: List(Expression))
58+
Group(expression: Expression)
5459
ModuleAccess(module: String, field: String)
5560
List(values: List(Expression))
5661
Record(fields: List(#(String, Expression)), update: Option(Expression))
@@ -62,7 +67,6 @@ pub type Expression {
6267
Unop(op: Unop, operand: Expression)
6368
Case(subject: Expression, clauses: List(CaseClause))
6469
External(javascript_code: String)
65-
Atom(name: String, payload: List(Expression))
6670
}
6771

6872
/// Binary operators have two operands.
@@ -112,7 +116,8 @@ pub type Pattern {
112116
VariablePattern(name: String)
113117
NamedPattern(pattern: Pattern, name: String)
114118
IgnorePattern
115-
NumberPattern(value: Float)
119+
IntPattern(value: Int)
120+
FloatPattern(value: Float)
116121
StringPattern(value: String)
117122
AtomPattern(name: String, payload: List(Pattern))
118123
}

0 commit comments

Comments
 (0)