polycomp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.toml CHANGED
@@ -17,6 +17,7 @@ cranelift-module = "0.137"
17
17
  cranelift-native = "0.137"
18
18
  ed25519-dalek = "2.2"
19
19
  getrandom = "0.2"
20
+ regex = "1"
20
21
  rustc-hash = "2.1"
21
22
 
22
23
  [profile.release]
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polycomp",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "PolyComp Universal Polyglot Compiler, Lazy VM, Cranelift JIT, and Armored UTF-8 IR Runtime",
5
5
  "main": "./js/index.cjs",
6
6
  "module": "./js/index.mjs",
package/src/ast.rs CHANGED
@@ -6,7 +6,11 @@ pub enum Language {
6
6
  Rust,
7
7
  Python,
8
8
  JavaScript,
9
+ TypeScript,
9
10
  C,
11
+ Cpp,
12
+ CSharp,
13
+ Go,
10
14
  }
11
15
 
12
16
  impl Language {
@@ -15,8 +19,12 @@ impl Language {
15
19
  match ext.as_str() {
16
20
  "rs" => Some(Language::Rust),
17
21
  "py" => Some(Language::Python),
18
- "js" | "mjs" | "cjs" | "ts" => Some(Language::JavaScript),
22
+ "js" | "mjs" | "cjs" => Some(Language::JavaScript),
23
+ "ts" | "mts" | "cts" | "tsx" => Some(Language::TypeScript),
19
24
  "c" | "h" => Some(Language::C),
25
+ "cpp" | "cc" | "cxx" | "hpp" | "hxx" | "hh" => Some(Language::Cpp),
26
+ "cs" => Some(Language::CSharp),
27
+ "go" => Some(Language::Go),
20
28
  _ => None,
21
29
  }
22
30
  }
@@ -26,9 +34,17 @@ impl Language {
26
34
  Language::Rust => "Rust",
27
35
  Language::Python => "Python",
28
36
  Language::JavaScript => "JavaScript",
37
+ Language::TypeScript => "TypeScript",
29
38
  Language::C => "C",
39
+ Language::Cpp => "C++",
40
+ Language::CSharp => "C#",
41
+ Language::Go => "Go",
30
42
  }
31
43
  }
44
+
45
+ pub fn is_brace_language(self) -> bool {
46
+ self != Language::Python
47
+ }
32
48
  }
33
49
 
34
50
  #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
@@ -40,6 +56,9 @@ pub enum TypeHint {
40
56
  Int,
41
57
  Float,
42
58
  Str,
59
+ Regex,
60
+ Array,
61
+ Object,
43
62
  }
44
63
 
45
64
  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -50,6 +69,7 @@ pub enum BinOp {
50
69
  Div,
51
70
  FloorDiv,
52
71
  Mod,
72
+ Pow,
53
73
  Eq,
54
74
  Ne,
55
75
  Lt,
@@ -58,6 +78,7 @@ pub enum BinOp {
58
78
  Ge,
59
79
  And,
60
80
  Or,
81
+ NullCoal,
61
82
  BitAnd,
62
83
  BitOr,
63
84
  BitXor,
@@ -118,11 +139,28 @@ pub struct StructDecl {
118
139
  pub span: Span,
119
140
  }
120
141
 
142
+ #[derive(Debug, Clone)]
143
+ pub struct EnumDecl {
144
+ pub name: String,
145
+ pub variants: Vec<(String, Expr)>,
146
+ pub span: Span,
147
+ }
148
+
121
149
  #[derive(Debug, Clone)]
122
150
  pub enum AssignTarget {
123
151
  Var(String),
124
152
  Field(Box<Expr>, String),
125
153
  Index(Box<Expr>, Box<Expr>),
154
+ Tuple(Vec<String>),
155
+ }
156
+
157
+ #[derive(Debug, Clone)]
158
+ pub enum TemplatePart {
159
+ Literal(String),
160
+ Expr {
161
+ expr: Expr,
162
+ format_spec: Option<String>,
163
+ },
126
164
  }
127
165
 
128
166
  #[derive(Debug, Clone)]
@@ -134,6 +172,12 @@ pub enum Stmt {
134
172
  is_function_scoped: bool,
135
173
  span: Span,
136
174
  },
175
+ MultiVarDecl {
176
+ names: Vec<String>,
177
+ init: Expr,
178
+ is_function_scoped: bool,
179
+ span: Span,
180
+ },
137
181
  Assign {
138
182
  target: AssignTarget,
139
183
  op: Option<BinOp>,
@@ -141,6 +185,7 @@ pub enum Stmt {
141
185
  span: Span,
142
186
  },
143
187
  If {
188
+ init: Option<Box<Stmt>>,
144
189
  cond: Expr,
145
190
  then_body: Vec<Stmt>,
146
191
  else_body: Vec<Stmt>,
@@ -161,11 +206,27 @@ pub enum Stmt {
161
206
  span: Span,
162
207
  },
163
208
  ForIn {
209
+ index_var: Option<String>,
164
210
  var: String,
165
211
  iter: Expr,
166
212
  body: Vec<Stmt>,
167
213
  span: Span,
168
214
  },
215
+ Switch {
216
+ expr: Option<Expr>,
217
+ cases: Vec<(Vec<Expr>, Vec<Stmt>)>,
218
+ default: Vec<Stmt>,
219
+ span: Span,
220
+ },
221
+ TryCatch {
222
+ try_body: Vec<Stmt>,
223
+ catch_var: Option<String>,
224
+ catch_body: Vec<Stmt>,
225
+ finally_body: Vec<Stmt>,
226
+ span: Span,
227
+ },
228
+ Throw(Expr, Span),
229
+ Defer(Expr, Span),
169
230
  Return(Option<Expr>, Span),
170
231
  Break(Span),
171
232
  Continue(Span),
@@ -180,11 +241,26 @@ pub enum Expr {
180
241
  Int(i64, Span),
181
242
  Float(f64, Span),
182
243
  Str(String, Span),
244
+ Regex {
245
+ pattern: String,
246
+ flags: String,
247
+ span: Span,
248
+ },
249
+ TemplateStr {
250
+ parts: Vec<TemplatePart>,
251
+ span: Span,
252
+ },
183
253
  Var(String, Span),
184
254
  Array(Vec<Expr>, Span),
255
+ Tuple(Vec<Expr>, Span),
185
256
  ObjectLit(Option<String>, Vec<(String, Expr)>, Span),
186
257
  Unary(UnaryOp, Box<Expr>, Span),
187
258
  Binary(BinOp, Box<Expr>, Box<Expr>, Span),
259
+ Cast {
260
+ ty: TypeHint,
261
+ expr: Box<Expr>,
262
+ span: Span,
263
+ },
188
264
  Update {
189
265
  name: String,
190
266
  inc: bool,
@@ -199,6 +275,7 @@ pub enum Expr {
199
275
  Member {
200
276
  object: Box<Expr>,
201
277
  field: String,
278
+ optional: bool,
202
279
  span: Span,
203
280
  },
204
281
  Index {
@@ -222,11 +299,15 @@ impl Expr {
222
299
  | Expr::Int(_, s)
223
300
  | Expr::Float(_, s)
224
301
  | Expr::Str(_, s)
302
+ | Expr::Regex { span: s, .. }
303
+ | Expr::TemplateStr { span: s, .. }
225
304
  | Expr::Var(_, s)
226
305
  | Expr::Array(_, s)
306
+ | Expr::Tuple(_, s)
227
307
  | Expr::ObjectLit(_, _, s)
228
308
  | Expr::Unary(_, _, s)
229
309
  | Expr::Binary(_, _, _, s)
310
+ | Expr::Cast { span: s, .. }
230
311
  | Expr::Update { span: s, .. }
231
312
  | Expr::Call { span: s, .. }
232
313
  | Expr::Member { span: s, .. }
@@ -240,6 +321,8 @@ impl Expr {
240
321
  pub struct ModuleAst {
241
322
  pub language: Language,
242
323
  pub imports: Vec<ImportDecl>,
324
+ pub using_namespaces: Vec<String>,
325
+ pub enums: Vec<EnumDecl>,
243
326
  pub structs: Vec<StructDecl>,
244
327
  pub functions: Vec<FunctionDecl>,
245
328
  pub top_level: Vec<Stmt>,