-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start cosmoc syntax definition (#2)
* checkpoint 1 * wip: AST construction from json * dev: move on parser.cos * feat: test iter traits * feat: draft deserializer * feat: add macro highlighting * test: review case tests * feat: refactor Item and Module * feat: initialize select test * feat: setup testing --------- Co-authored-by: seven-mile <[email protected]>
- Loading branch information
1 parent
8e46a54
commit 5b409ea
Showing
48 changed files
with
1,025 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function RunCosmo { | ||
node '--enable-source-maps' ./cmd/cosmo/main.js $args | ||
node '--enable-source-maps' ./cmd/cosmo/main.js $args | ||
} | ||
|
||
Set-Alias cosmo RunCosmo | ||
Set-Alias cosmo RunCosmo | ||
|
||
function RunCosmoPerf { | ||
npx "0x" "--" node '--enable-source-maps' ./cmd/cosmo/main.js $args | ||
} | ||
|
||
Set-Alias cosmo-perf RunCosmoPerf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
== Features: default type parameters | ||
|
||
https://contributors.scala-lang.org/t/generic-defaults-clazz-t-int/4759/11 | ||
|
||
An important thing to consider is that IIRC, defaults for type parameters prevent type inference for these parameters in TypeScript, which is a pretty big restriction, and may not fly in Scala. Or maybe it’s not so important for the use cases considered, who knows? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class T { val x = 1; } | ||
----- | ||
T().x | ||
T(x: T().x).x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
class CppIter[E, T] { | ||
var curr: T; | ||
var eof: T; | ||
|
||
def begin(&self): any = self.curr | ||
def end(&self): any = self.eof | ||
} | ||
|
||
impl[E, T<: cstd.Deref[E]] Iter[&E] for CppIter[E, T] { | ||
def next(&mut self): Option[&E] = { | ||
if (self.curr == self.eof) { | ||
Option[&E]::None | ||
} else { | ||
val result = cstd.deref(self.curr); | ||
cstd.inc(self.curr); | ||
Option[&E]::Some(result) | ||
} | ||
} | ||
} | ||
|
||
class CppIterMut[E, T] { | ||
var curr: T; | ||
var eof: T; | ||
|
||
def begin(&self): any = self.curr | ||
def end(&self): any = self.eof | ||
} | ||
|
||
impl[T, E<: cstd.DerefMut[E]] Iter[&mut E] for CppIterMut[E, T] { | ||
def next(&mut self): Option[&mut E] = { | ||
if (self.curr == self.eof) { | ||
Option[&mut E]::None | ||
} else { | ||
var result = cstd.deref_mut(self.curr); | ||
cstd.inc(self.curr); | ||
Option[&mut E]::Some(result) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/cosmo/snapshots/ParserTests/samples/ControlFlow/forIn.cos-ast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/cosmo/snapshots/Types/fixtures/Type/dispatches/HelloWorld.cos-ast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[T().x] => instance T(Opaque(Some(kDefault),None)).x, type: i32, err: "" | ||
[T(x: T().x).x] => instance T(instance T(Opaque(Some(kDefault),None)).x).x, type: i32, err: "" |
8 changes: 4 additions & 4 deletions
8
packages/cosmo/snapshots/Types/fixtures/Type/matches/class.cos-ast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[T(x: 1, y: 2) match { | ||
case T(x, y) => x + y | ||
}] => block { | ||
ClassDestruct(ins (class(T))(Integer(1), Integer(2)),class(T),List((var x_56:56 = NoneKind(0)), (var y_57:57 = NoneKind(0)))) | ||
var x@52: i32 = var x_56@56: i32 = _ | ||
var y@53: i32 = var y_57@57: i32 = _ | ||
"+"(var x@52: i32 = _, var y@53: i32 = _) | ||
ClassDestruct(ins (class(T))(Int32(1), Int32(2)),class(T),List((var x_58:58 = NoneKind(0)), (var y_59:59 = NoneKind(0)))) | ||
var x@54: i32 = var x_58@58: i32 = _ | ||
var y@55: i32 = var y_59@59: i32 = _ | ||
"+"(var x@54: i32 = _, var y@55: i32 = _) | ||
}, err: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.