Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kode4food committed Dec 29, 2024
1 parent b9eff65 commit c14508c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
18 changes: 10 additions & 8 deletions internal/compiler/ir/optimize/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func (m *inlineMapper) transformArgs(
return c
}
case 1:
if canImmediatelyPop(c) {
return immediatelyPop(c)
if res, ok := immediatelyPop(c); ok {
return res
}
fallthrough
default:
Expand Down Expand Up @@ -299,12 +299,14 @@ func argInstructionPred(i isa.Instruction) bool {
}
}

func canImmediatelyPop(c isa.Instructions) bool {
return len(c) > 0 && c[0] == isa.Arg.New(0) && !hasAnyArgInstruction(c[1:])
}

func immediatelyPop(c isa.Instructions) isa.Instructions {
return c[1:]
func immediatelyPop(c isa.Instructions) (isa.Instructions, bool) {
if len(c) != 0 || c[0] != isa.Arg.New(0) {
return nil, false
}
if res := c[1:]; !hasAnyArgInstruction(res) {
return res, true
}
return nil, false
}

func canMapArgsToLocals(c isa.Instructions, argc isa.Operand) bool {
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/internal/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const (
// arguments provided doesn't match any of the declared parameter cases
ErrUnmatchedCase = "got %d arguments, expected %s"

// ErrNoMatchingParamPattern is raised when none of the parameter patterns for
// a Lambda were capable of being matched
// ErrNoMatchingParamPattern is raised when none of the parameter patterns
// for a Lambda were capable of being matched
ErrNoMatchingParamPattern = "no matching parameter pattern"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/core/source/10_sequences.ale
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
[r (rest coll)])
(last-inner r f))
prev)))
coll '()))
coll null))

(define-lambda fold-left
[(func init coll)
Expand All @@ -101,7 +101,7 @@
(define (reverse! coll)
(if (reversible? coll)
(reverse coll)
(fold-left conj '() coll)))
(fold-left conj null coll)))

(define :private (swap-args func)
(lambda (l r) (func r l)))
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/source/14_exceptions.ale
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

(lambda-rec try-parse (clauses)
(unless (seq? clauses)
{:block '() :catch '() :finally []}
{:block null :catch null :finally []}
(let* ([f (first clauses)]
[r (rest clauses)]
[p (try-parse r)])
Expand Down
4 changes: 2 additions & 2 deletions pkg/data/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type (
// Pairs represents multiple pairs
Pairs []Pair

// Cons cells are the standard implementation of a Pair. Unlike
// other Pairs (ex: List, Vector), it is not treated as a Sequence
// Cons cells are the standard implementation of a Pair. Unlike other Pairs
// (ex: List, Vector), it is not treated as a Sequence
Cons struct {
car Value
cdr Value
Expand Down
4 changes: 2 additions & 2 deletions pkg/ffi/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func WrapType(t reflect.Type) (Wrapper, error) {
s := new(struct{ Wrapper })
cache.put(t, s)

// register the final Wrapper, and wire it into the stub for those
// Wrappers that may refer to it
// register the final Wrapper, and wire it into the stub for those Wrappers
// that may refer to it
w, err := makeWrappedType(t)
if err != nil {
return nil, err
Expand Down

0 comments on commit c14508c

Please sign in to comment.