Skip to content

Commit 953d9da

Browse files
committed
std/jule/token: refactoring with reimplemented API
1 parent 47f7b40 commit 953d9da

26 files changed

+1011
-1090
lines changed

src/julec/obj/cxx/expr.jule

+25-25
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ impl exprCoder {
228228
self.oc.write(")(")
229229
self.oc.write(xVar)
230230
match op.Id {
231-
| token::Id.Solidus
232-
| token::Id.SolidusEq:
231+
| token::Solidus
232+
| token::SolidusEq:
233233
self.oc.write(" / ")
234-
| token::Id.Percent
235-
| token::Id.PercentEq:
234+
| token::Percent
235+
| token::PercentEq:
236236
self.oc.write(" % ")
237237
}
238238
self.oc.write(yVar)
@@ -242,7 +242,7 @@ impl exprCoder {
242242
// Tries to handle binary expressions with dynamic types and reports whether
243243
// it successful. Should support all dynamic types.
244244
fn unsafeDynamicBinary(mut &self, mut &buf: strings::Builder,
245-
mut l: sema::OperandExpr, mut r: sema::OperandExpr, op: token::Id): bool {
245+
mut l: sema::OperandExpr, mut r: sema::OperandExpr, op: int): bool {
246246
// Return immediately if binary expression is not contain dynamic type.
247247
// Handle traits separately, see documentation of obj::IsAny.
248248
// They handled as <any> type, but not have pure any type implementation,
@@ -281,7 +281,7 @@ impl exprCoder {
281281
})
282282

283283
buf.WriteByte('(')!
284-
if op == token::Id.NotEq {
284+
if op == token::NotEq {
285285
buf.WriteByte('!')!
286286
}
287287
i := self.oc.pushAnyType(t)
@@ -307,14 +307,14 @@ impl exprCoder {
307307
}
308308

309309
fn _unsafeBinaryNoDynamic(mut &self, mut &buf: strings::Builder, &l: str,
310-
&r: str, mut &lk: &sema::Type, mut &rk: &sema::Type, op: token::Id, kind: str) {
310+
&r: str, mut &lk: &sema::Type, mut &rk: &sema::Type, op: int, kind: str) {
311311
match {
312312
| lk.Array() != nil:
313313
// If this binary operator comparing array type.
314314
// The left operand is will be array one always.
315315
arr := lk.Array()
316316
mut ins := obj::FindFuncGenericInstance(meta::Program.Runtime.ArrayCmp, arr.Elem)
317-
if op == token::Id.NotEq {
317+
if op == token::NotEq {
318318
buf.WriteByte('!')!
319319
}
320320
identCoder.funcIns(buf, ins)
@@ -336,9 +336,9 @@ impl exprCoder {
336336

337337
// guarantee integer wrap around if expressions is not a condition
338338
match op {
339-
| token::Id.Gt | token::Id.GtEq
340-
| token::Id.Lt | token::Id.LtEq
341-
| token::Id.Eqs | token::Id.NotEq:
339+
| token::Gt | token::GtEq
340+
| token::Lt | token::LtEq
341+
| token::DblEq | token::NotEq:
342342
// No op.
343343
|:
344344
lp := lk.Prim()
@@ -363,9 +363,9 @@ impl exprCoder {
363363
}
364364

365365
fn _unsafeBinary(mut &self, mut &buf: strings::Builder, mut l: sema::OperandExpr,
366-
mut r: sema::OperandExpr, op: token::Id, kind: str) {
366+
mut r: sema::OperandExpr, op: int, kind: str) {
367367
// Special cases for comparable types.
368-
if (op == token::Id.Eqs || op == token::Id.NotEq) && self.unsafeDynamicBinary(buf, l, r, op) {
368+
if (op == token::DblEq || op == token::NotEq) && self.unsafeDynamicBinary(buf, l, r, op) {
369369
ret
370370
}
371371
ls := writeAndReadFromBuf(self.oc.Buf, fn() { self.possibleRefExpr(l.Model) })
@@ -439,15 +439,15 @@ impl exprCoder {
439439

440440
fn binary(mut &self, mut m: &sema::BinaryExpr) {
441441
match m.Op.Id {
442-
| token::Id.Solidus | token::Id.Percent:
442+
| token::Solidus | token::Percent:
443443
if env::Safety {
444444
self.divByZeroBinary(m.Op, m.Left, m.Right)
445445
ret
446446
}
447-
| token::Id.Shl:
447+
| token::Shl:
448448
self.shl(m.Left, m.Right)
449449
ret
450-
| token::Id.Shr:
450+
| token::Shr:
451451
self.shr(m.Left, m.Right)
452452
ret
453453
}
@@ -477,7 +477,7 @@ impl exprCoder {
477477
fn unary(mut &self, mut m: &sema::UnaryExpr) {
478478
// guarantee integer wrap around
479479
match m.Op.Id {
480-
| token::Id.Plus | token::Id.Minus | token::Id.Caret:
480+
| token::Plus | token::Minus | token::Caret:
481481
lp := m.Expr.Type.Prim()
482482
if lp != nil && types::IsInt(lp.Kind) {
483483
self.oc.write("(")
@@ -490,12 +490,12 @@ impl exprCoder {
490490
}
491491

492492
match m.Op.Id {
493-
| token::Id.Caret:
493+
| token::Caret:
494494
self.oc.write("(~(")
495495
self.possibleRefExpr(m.Expr.Model)
496496
self.oc.write("))")
497497
ret
498-
| token::Id.Star:
498+
| token::Star:
499499
if env::Production || m.Expr.Type.Sptr() == nil {
500500
break
501501
}
@@ -1569,7 +1569,7 @@ impl exprCoder {
15691569
match type m.Err.Model {
15701570
| &sema::Var:
15711571
v := m.Err.Model.(&sema::Var)
1572-
if v.Ident == token::Kind.Error {
1572+
if v.Ident == "error" {
15731573
if hasDefer {
15741574
self.oc.write(deferStackName + ".call();\n")
15751575
self.oc.indent()
@@ -1585,7 +1585,7 @@ impl exprCoder {
15851585
match type m.Err.Model {
15861586
| &sema::Var:
15871587
v := m.Err.Model.(&sema::Var)
1588-
if v.Ident == token::Kind.Error {
1588+
if v.Ident == "error" {
15891589
self.oc.write(">{.error=except.error}")
15901590
ret
15911591
}
@@ -2378,11 +2378,11 @@ fn utoa(mut &s: strings::Builder, x: u64) {
23782378
}
23792379

23802380
fn structBinary(mut &buf: strings::Builder, mut &s: &sema::StructIns, &l: str,
2381-
&r: str, op: token::Id, kind: str) {
2382-
if op != token::Id.Eqs && op != token::Id.NotEq {
2381+
&r: str, op: int, kind: str) {
2382+
if op != token::DblEq && op != token::NotEq {
23832383
panic("cxx: unsupported token occurred for structure binary, this is an implementation mistake")
23842384
}
2385-
if op == token::Id.NotEq {
2385+
if op == token::NotEq {
23862386
buf.WriteByte('!')!
23872387
}
23882388
identCoder.structureIns(buf, s)
@@ -2457,7 +2457,7 @@ struct useExprMemory {
24572457
DestType: &sema::Type
24582458
Model: sema::Expr
24592459
Type: int
2460-
OpId: token::Id
2460+
OpId: int
24612461
OpKind: str
24622462
}
24632463

src/julec/obj/cxx/ident.jule

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use "env"
66
use "obj"
77
use "std/conv"
8+
use "std/jule"
89
use "std/jule/build"
910
use "std/jule/directive"
1011
use "std/jule/sema"
@@ -113,7 +114,7 @@ impl identCoder {
113114
}
114115

115116
static fn param(mut &buf: strings::Builder, &p: &sema::Param) {
116-
if token::IsAnonIdent(p.Ident) || token::IsIgnoreIdent(p.Ident) {
117+
if jule::IsAnon(p.Ident) || jule::IsBlank(p.Ident) {
117118
ret
118119
}
119120
if p.IsSelf() {
@@ -151,7 +152,7 @@ impl identCoder {
151152
buf.WriteStr(f.Ident)!
152153
ret
153154
}
154-
if token::IsIgnoreIdent(f.Ident) {
155+
if jule::IsBlank(f.Ident) {
155156
// If the identifier is blank, there may be other fields like that.
156157
// So handle them with unique identifier, avoid duplication.
157158
buf.WriteStr("_field_")!
@@ -167,9 +168,9 @@ impl identCoder {
167168
match {
168169
| v.Binded:
169170
buf.WriteStr(v.Ident)!
170-
| v.Ident == token::Kind.Error:
171+
| v.Ident == "error":
171172
buf.WriteStr("except.error")!
172-
| v.Ident == token::Kind.Self:
173+
| v.Ident == "self":
173174
buf.WriteStr(identSelf)!
174175
| v.RetOrder == -1:
175176
// The single return variable is just this one.

src/julec/obj/cxx/object.jule

+8-8
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl ObjectCoder {
555555
self.anyObj.WriteStr("_eq(void *alloc, void *other) noexcept { ")!
556556
if comparable {
557557
self.anyObj.WriteStr("return ")!
558-
self.ec._unsafeBinaryNoDynamic(self.anyObj, lmodel, rmodel, t, t, token::Id.Eqs, token::Kind.Eqs)
558+
self.ec._unsafeBinaryNoDynamic(self.anyObj, lmodel, rmodel, t, t, token::DblEq, "==")
559559
self.anyObj.WriteStr("; }\n")!
560560
} else {
561561
self.anyObj.WriteStr(`__jule_panic((`)!
@@ -934,7 +934,7 @@ impl ObjectCoder {
934934
identCoder.field(fIdent, f.Decl)
935935
lmodel += fIdent.Str()
936936
rmodel += fIdent.Str()
937-
self.ec._unsafeBinaryNoDynamic(self.Buf, lmodel, rmodel, f.Type, f.Type, token::Id.Eqs, token::Kind.Eqs)
937+
self.ec._unsafeBinaryNoDynamic(self.Buf, lmodel, rmodel, f.Type, f.Type, token::DblEq, "==")
938938
lmodel = lmodel[:len(lmodel)-fIdent.Len()]
939939
rmodel = rmodel[:len(rmodel)-fIdent.Len()]
940940
}
@@ -1072,7 +1072,7 @@ impl ObjectCoder {
10721072
for (_, mut m) in hash.methods {
10731073
mut ins := m.Instances[0]
10741074
for (i, mut ip) in ins.Params[1:] {
1075-
if token::IsAnonIdent(ip.Decl.Ident) {
1075+
if jule::IsAnon(ip.Decl.Ident) {
10761076
ip.Decl.Ident = "_" + conv::Itoa(i)
10771077
}
10781078
}
@@ -1163,8 +1163,8 @@ impl ObjectCoder {
11631163
DestType: v.TypeSym.Type,
11641164
Model: v,
11651165
Type: useExprPlain,
1166-
OpId: token::Id.Eq,
1167-
OpKind: token::Kind.Eq,
1166+
OpId: token::Eq,
1167+
OpKind: "=",
11681168
})
11691169
} else {
11701170
identCoder.var(self.Buf, v)
@@ -1175,7 +1175,7 @@ impl ObjectCoder {
11751175
}
11761176

11771177
fn var(mut &self, mut v: &sema::Var) {
1178-
if token::IsIgnoreIdent(v.Ident) {
1178+
if jule::IsBlank(v.Ident) {
11791179
ret
11801180
}
11811181
if v.ValueSym != nil && v.ValueSym.Expr != nil {
@@ -1491,7 +1491,7 @@ impl ObjectCoder {
14911491
for (_, mut v) in self.ir.Ordered.Globals {
14921492
// Skip blank identifiers, do not declare them.
14931493
// Initialization expressions will be executed when variables initializing.
1494-
if token::IsIgnoreIdent(v.Ident) {
1494+
if jule::IsBlank(v.Ident) {
14951495
continue
14961496
}
14971497
self.tc.kind(self.Buf, v.TypeSym.Type)
@@ -1614,7 +1614,7 @@ impl ObjectCoder {
16141614
}
16151615
self.Buf.WriteByte(indentKind)!
16161616
// If variable have blank identifier, just execute the initialization expression.
1617-
if token::IsIgnoreIdent(v.Ident) {
1617+
if jule::IsBlank(v.Ident) {
16181618
self.ec.model(v.ValueSym.Value.Model)
16191619
self.write(";\n")
16201620
continue

src/julec/obj/cxx/scope.jule

+13-13
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,9 @@ impl scopeCoder {
644644
// handle it like the equal operator
645645
mut op := a.Op.Id
646646
mut kind := a.Op.Kind
647-
if a.Op.Id == token::Id.ColonEq {
648-
op = token::Id.Eq
649-
kind = token::Kind.Eq
647+
if a.Op.Id == token::ColonEq {
648+
op = token::Eq
649+
kind = "="
650650
}
651651

652652
mut fc := isExceptionalResult(a.Right.Model)
@@ -662,15 +662,15 @@ impl scopeCoder {
662662
}
663663

664664
match a.Op.Id {
665-
| token::Id.SolidusEq | token::Id.PercentEq:
665+
| token::SolidusEq | token::PercentEq:
666666
if env::Safety {
667667
self.divByZeroAssign(a)
668668
ret
669669
}
670-
| token::Id.ShlEq:
670+
| token::ShlEq:
671671
self.shl(a)
672672
ret
673-
| token::Id.ShrEq:
673+
| token::ShrEq:
674674
self.shr(a)
675675
ret
676676
}
@@ -833,8 +833,8 @@ impl scopeCoder {
833833
Ident: assignResultName,
834834
},
835835
Type: useExprPlain,
836-
OpId: token::Id.Eq,
837-
OpKind: token::Kind.Eq,
836+
OpId: token::Eq,
837+
OpKind: "=",
838838
}
839839
self.oc.write(" " + assignResultName + ";\n")
840840
self.oc.indent()
@@ -982,7 +982,7 @@ impl scopeCoder {
982982
Model: expr.Model,
983983
Type: expr.Type,
984984
}
985-
self.oc.ec._unsafeBinary(self.oc.Buf, l, r, token::Id.Eqs, token::Kind.Eqs)
985+
self.oc.ec._unsafeBinary(self.oc.Buf, l, r, token::DblEq, "==")
986986
|:
987987
self.oc.write(matchExpr)
988988
mut tk := expr.Model.(&sema::Type)
@@ -1281,8 +1281,8 @@ impl scopeCoder {
12811281
Ident: resultName,
12821282
},
12831283
Type: useExprPlain,
1284-
OpId: token::Id.Eq,
1285-
OpKind: token::Kind.Eq,
1284+
OpId: token::Eq,
1285+
OpKind: "=",
12861286
}
12871287
self.oc.ec.handleExceptionalCallWithData(fc, dest)
12881288
self.oc.write("\n")
@@ -1342,8 +1342,8 @@ impl scopeCoder {
13421342
DestType: r.Func.Result,
13431343
Model: rv,
13441344
Type: useExprPlain,
1345-
OpId: token::Id.Eq,
1346-
OpKind: token::Kind.Eq,
1345+
OpId: token::Eq,
1346+
OpKind: "=",
13471347
}
13481348
self.oc.ec.handleExceptionalCallWithData(fc, dest)
13491349
} else {

src/julec/obj/ir.jule

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn buildCompileInfo(): importer::CompileInfo {
220220
fn pushRuntimeToAST(mut &f: &ast::AST) {
221221
mut decl := &ast::Use{
222222
Token: nil, // Nil token is a flag for implicit declaration.
223-
Path: &token::Token{Id: token::Id.Lit, Kind: `"std/runtime"`},
223+
Path: &token::Token{Id: token::Lit, Kind: `"std/runtime"`},
224224
Alias: nil,
225225
Binded: false,
226226
}

src/julec/opt/boundary.jule

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn fitsSize(mut e1: sema::Expr, mut e2: sema::Expr): bool {
119119
| &sema::UnaryExpr:
120120
mut uem1 := e1.(&sema::UnaryExpr)
121121
mut uem2 := e2.(&sema::UnaryExpr)
122-
if uem1.Op.Id != token::Id.Star || uem1.Op.Id != uem2.Op.Id {
122+
if uem1.Op.Id != token::Star || uem1.Op.Id != uem2.Op.Id {
123123
ret false
124124
}
125125
ret fitsSize(uem1.Expr.Model, uem2.Expr.Model)
@@ -179,7 +179,7 @@ fn getBoundaryVar(m: sema::Expr): uintptr {
179179
ret uintptr(m.(&sema::StructSubIdentExpr).Field)
180180
| &sema::UnaryExpr:
181181
uem := m.(&sema::UnaryExpr)
182-
if uem.Op.Id == token::Id.Star { // Dereferencing.
182+
if uem.Op.Id == token::Star { // Dereferencing.
183183
ret getBoundaryVar(uem.Expr.Model)
184184
}
185185
}

src/julec/opt/dynamic.jule

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn getDynamicVar(m: sema::Expr): uintptr {
127127
ret uintptr(m.(&sema::StructSubIdentExpr).Field)
128128
| &sema::UnaryExpr:
129129
uem := m.(&sema::UnaryExpr)
130-
if uem.Op.Id == token::Id.Star { // Dereferencing.
130+
if uem.Op.Id == token::Star { // Dereferencing.
131131
ret getDynamicVar(uem.Expr.Model)
132132
}
133133
}

0 commit comments

Comments
 (0)