Daniel's Stuff

I write code

Month: June 2014

I finished another PIC32 proto board

It is a lot smaller that my previous one and fits better into the breadboard 🙂
I think I have also figured out why many of my PIC32 projects were crashing randomly.  It appears I was setting the oscillator up incorrectly which was causing the lower spec PIC32MX2xx to try to run at the same speed as the higher spec PIC32MX7xx.  Oops 😉
The interesting thing is the PIC32MX2xx parts will run at the same speed as the higher ones as long as you keep them cool.  Unfortunately my office has no air conditioning so during the summer months it is not uncommon for it to get into the 40C range.  During the winter months as I am currently experiencing this isn’t a problem 😉

Swift Parser Generation

I’ve been fascinated by the Scala language since I first saw it. I’ve been fortunate enough to be able to use Scala in a couple of projects. One of the parts of the Scala standard library I really like is the parser combinator stuff.  I’ve been spending a bit of time recently playing with some ideas as to how something like it could be made for the new Swift language from Apple and I’ve made a first cut here.

It still needs a lot of work, but at the moment it is usable.  What I’m thinking is I will use it as the basis of a much nicer one that follows the Scala version more closely now that I have a better understanding of how Swift works.  I doubt I’ll be able to make it a nice as the Scala one, but I may be able to get close with any luck 🙂

 

The first stage of my port of pegged to Swift is successful :)

I have managed to get the Objective-C version of pegged to spit out a parser using Swift rather than Objective-C 🙂

It’s getting late, so I really should get some sleep.

I finally figured out what was causing the compiler to crash.  The following code will crash the Swift compiler unless the inout parameter to the block type is removed.

typealias MathFunction = (a: Double, b:Double, inout x:Int) -> Double
var counter = 0
class Executor {
    var fn: MathFunction
    init(fn: MathFunction) {
        self.fn = fn
    }
    func execute(a: Double, b: Double) -> Double {
        return fn(a: a, b: b, x: &counter)
    }
}

Swift compiler is crashing for me :(

I’ve been spending a bit of time having a play with Apple’s Swift.  So far I find the language to be interesting.

It seems to be missing a few things.  Working with strings is a real pain 🙁  Hopefully this will be fixed in later versions of the language/compiler.

I’m also hitting many problems with the Xcode 6.0 beta crashing, but more annoyingly after getting a fairly large amount of Swift code ready it seems to be crashing the compiler 🙁

I’m trying to port the pegged parser generator to swift.  The first step is to update the existing tool to generate swift as output.  This I got working fairly quickly, then it was down to fixing the various syntax errors and learning how things are done in Swift.  Now there are no syntax errors, but it still won’t compile 🙁  Ah well.  Maybe I should just have a go at writing one from scratch 😉