Skip to content

Releases: c0c0n3/learning.stack-machine-revival

Integer arithmetic

Choose a tag to compare

@c0c0n3 c0c0n3 released this 11 Mar 11:43
bd8248d

We keep developing our pocket calculator to make it support any integer arithmetic expression.

Our arithmetic language lets us work with integer arithmetic expressions---a.k.a. arithmetic without fractions. Expressions involve sums, subtractions, products, and divisions among integer values. Since we're only dealing with integers, the result of evaluating an expression should still be an integer. For this reason, x/y is an integer division which returns the quotient q of Euclidean division of x by y---i.e. x = y*q + r, 0 <= r < |y|.

Notice how extending the Expr data type with more cases in the Lang module caused a ripple effect in all the others. This is an instance of the "expression problem" which is a bit too hard to solve with what we know at this stage. But we'll revisit this problem again in a few months from now and put in place a mind-bending solution :-)

Teaser

Choose a tag to compare

@c0c0n3 c0c0n3 released this 09 Mar 19:52
dee12e8

We explore the concepts of language, interpreters, compilers, and hardware architecture by building a simple pocket calculator.

These are the components that make up our calculator:

  • An arithmetic language embedded into Haskell.
  • Language interpreters to work out the value of an expression and pretty print it.
  • A virtual stack machine to simulate the calculator hardware.
  • A compiler to transform language expressions into low-level instructions the machine can run.

Even though this is just a toy, it should give us a fairly good idea of how to conceptualise the problem and design a solution.