Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default functions like print() #12

Closed
timwaterman opened this issue Dec 4, 2015 · 3 comments
Closed

Default functions like print() #12

timwaterman opened this issue Dec 4, 2015 · 3 comments
Assignees
Labels

Comments

@timwaterman
Copy link
Collaborator

Print is weird. I have a skeleton set up inside the semantic analyzer for it, but we need to nail down its arguments. We have 3 options:
-Let it only take in Strings
-Let it take in any type, and have a new "polymorphic" type to compensate
-Let it keep using printf args, and try to figure out how to type check variadic functions in our own type checker (seems really hard, so lets not do this one)

@timwaterman timwaterman changed the title Fdecl() Default functions like print() Dec 5, 2015
@danhcole
Copy link
Owner

danhcole commented Dec 6, 2015

So, right now print is set up to be 'psudo-polymorphic'. When the semantic analyzer checks a function call, if the call is named 'print', it handles it specially. If the type is an int, float, char or string, it passes it, otherwise it throws an exception.

In the generator, when it prints the call, if the call is to print, it manually inserts the correct printf statement.

Right now, this only works with ints. If you pull the current code, and run the test suite, the first four or five tests pass. When the suite gets to the 'hello world' test, it fails. I need to go in and add type-checking to the generator, to correctly format the printf statements, which shouldn't be too hard to do. Something similar can be done for other built-in's.

@danhcole danhcole self-assigned this Dec 6, 2015
@danhcole
Copy link
Owner

danhcole commented Dec 6, 2015

Now works for int, float, char, string and id. Still needs other exprs

@danhcole
Copy link
Owner

danhcole commented Dec 6, 2015

Works for all other exprs. All tests up to and including ops1.stch work.

@danhcole danhcole closed this as completed Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants