Skip to content

Commit

Permalink
ast: rename the elems field as exprs of the SliceExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 24, 2024
1 parent be42549 commit 2b20598
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions std/jule/ast/node.jule
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ pub struct KeyValPair {
// Also represents array initiating expression.
pub struct SliceExpr {
pub token: Token
pub elems: []&Expr
pub exprs: []&Expr
}

impl SliceExpr {
// Reports whether slice is empty.
pub fn is_empty(self): bool {
ret self.elems.len == 0
ret self.exprs.len == 0
}
}

Expand Down
4 changes: 2 additions & 2 deletions std/jule/parser/expr.jule
Original file line number Diff line number Diff line change
Expand Up @@ -858,12 +858,12 @@ impl ExprBuilder {
ret slc
}

slc.elems = make([]&Expr, 0, parts.len)
slc.exprs = make([]&Expr, 0, parts.len)
for (_, mut p) in parts {
if p.len == 0 {
continue
}
slc.elems = append(slc.elems, self.build_from_tokens(p))
slc.exprs = append(slc.exprs, self.build_from_tokens(p))
}

ret slc
Expand Down
23 changes: 11 additions & 12 deletions std/jule/sema/eval.jule
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,10 @@ impl Eval {

let mut filled = false

if s.elems.len == 2 {
match type s.elems[1].kind {
if s.exprs.len == 2 {
match type s.exprs[1].kind {
| &VariadicExpr:
if (&VariadicExpr)(s.elems[1].kind).expr != nil {
if (&VariadicExpr)(s.exprs[1].kind).expr != nil {
break
}
// Filled.
Expand All @@ -810,11 +810,11 @@ impl Eval {
}

filled = true
s.elems = s.elems[:1]
s.exprs = s.exprs[:1]
}
}

arr.n = s.elems.len
arr.n = s.exprs.len
if !pt.auto {
if arr.n > pt.n {
self.push_err(s.token, LogMsg.OverflowLimits)
Expand All @@ -825,12 +825,12 @@ impl Eval {

let mut model = &ArrayExprModel{
kind: arr,
elems: make([]ExprModel, 0, if filled { 2 } else { s.elems.len }),
elems: make([]ExprModel, 0, if filled { 2 } else { s.exprs.len }),
}

let mut prefix = self.prefix
self.prefix = arr.elem
for (_, mut elem) in s.elems {
for (_, mut elem) in s.exprs {
let mut d = self.eval_expr_kind(elem)
if d == nil {
continue
Expand Down Expand Up @@ -862,17 +862,16 @@ impl Eval {

let mut model = &SliceExprModel{
elem_kind: elem_type,
elems: make([]ExprModel, 0, s.elems.len),
elems: make([]ExprModel, 0, s.exprs.len),
}

let mut prefix = self.prefix
self.prefix = slc.elem
for (_, mut elem) in s.elems {
for (_, mut elem) in s.exprs {
let mut d = self.eval_expr_kind(elem)
if d == nil {
continue
}

_ = self.s.check_assign_type(false, slc.elem, d, s.token)
model.elems = append(model.elems, d.model)
}
Expand Down Expand Up @@ -902,12 +901,12 @@ impl Eval {
let mut prefix = self.prefix
self.prefix = nil

if s.elems.len == 0 {
if s.exprs.len == 0 {
self.push_err(s.token, LogMsg.DynamicTypeAnnotationFailed)
ret nil
}

let mut first_elem = self.eval_expr_kind(s.elems[0])
let mut first_elem = self.eval_expr_kind(s.exprs[0])
if first_elem == nil {
ret nil
}
Expand Down

0 comments on commit 2b20598

Please sign in to comment.