Git Product home page Git Product logo

inc's People

Contributors

khoborerkagoj avatar namin avatar

inc's Issues

Detect whether a binary primitive has only immediate arguments, and evaluate at compile time

(Originated in step5).
It is possible that we encounter an expression like (fx+ 3 4) which can be evaluated at compile time to simply emit

mov eax, 7  ; actually 28 because of fixnum representation

For now, we generate the code

mov eax, 3 ; actually 12 (fixnum)
add eax, 4 ; actually 16 (fixnum)

It is best to keep it the way it is for now (so the compiler code is exercised), but when the compiler code is mature, this can be added as an optimization.

Add return types, argument types for primitives.

From step2: It would be nice to have a return type for primitives, as also an "acceptable" type. For instance,

(emit-program '(fxadd1 (boolean? 32)))

does not make sense, as fxadd1 should only accept fixnums. If boolean? advertised itself as returning a
boolean, and fxadd1 advertised itself as only accepting a boolean, we could check for this and throw an error at compile time.

Don't force booleans to return #t/#f in if

From the tutorial exercise 1.4.3:
Consider the expression (if (fx> 3 4) (fxadd1 3) (fxlognot 5)):
fx> first compares it arguments, generates 0 or 1, and then returns #t or #f depending on the result.
if then evaluates the result, compares to #f, and then decides what to do.

The fix would be to have a different definition of emit-expr which would just generate 1 or 0 as the result of the boolean expression. This alternate form would be called only from the test expression of an if, so would not affect results. This would save us in the creation of the boolean.

Allow usage of ECX generally

The standard usage of scheme_entry is that it saves the callee's stack (the stack of the C main() function) in ECX before resetting the stack to the Scheme stack. On return from Scheme (the L_scheme_entry function), ESP is reset from the saved value in ECX.

However, this means that ECX is not available to the code we generate. One possibility would be to:

  • Save C stack pointer to ECX (as now)
  • Switch stack to the Scheme stack (as now)
  • Save ECX to the first element of the Scheme stack.
    • The push instruction will both do this and update ESP.
  • ECX is now free to be used by the Scheme-generated code.
    • Note that this means Scheme must restore the stack pointer to exactly where it was upon return. Previously, even if ESP was different, it would be restored from ECX anyway, so it did not matter.

Windows conventions for 32 bit dictate that we can trash EAX, ECX and EDX within a function call; other registers must be saved and restored before returning.

This is the convention used by Visual Studio 2015

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.