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

(many) Use Perlang strings and native C functions for writing to stdout #389

Merged
merged 1 commit into from
Apr 22, 2023

Conversation

perlun
Copy link
Collaborator

@perlun perlun commented Apr 21, 2023

See #390 for the over-arching goal.

@perlun perlun added the enhancement New feature or request label Apr 21, 2023
@perlun perlun added this to the 0.4.0 milestone Apr 21, 2023
@perlun perlun force-pushed the feature/use-Perlang-strings-in-print-statement branch from 790226c to 2fdbb69 Compare April 22, 2023 17:49
@perlun perlun marked this pull request as ready for review April 22, 2023 18:32
@@ -19,12 +19,14 @@ namespace Perlang.Interpreter.Internals
/// </summary>
internal class AstPrinter : Expr.IVisitor<string>, Stmt.IVisitor<string>
{
// TODO: Return Perlang string instead
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// string as an AsciiString in the created Literal.
return new Expr.Literal(AsciiString.from(chars));
Lang.String nativeString = Lang.String.from(s);
return new Expr.Literal(nativeString);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code that used to be here was pretty much inlined in String.from, to make it be generically usable from elsewhere.


public void WriteStdoutLine(String s)
{
int bytesWritten = Libc.Internal.write(Libc.Internal.STDOUT_FILENO, s.Bytes, (int)s.Length);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly enough, this approach seems to work on both Linux and windows (tested on Windows 10). 😲 If we don't need to write platform-dependent code, we should obviously not be writing platform-dependent code...

(Reading keypresses might be a bigger challenge. We'll get to that eventually, trying to do without Console.ReadKey)

@perlun perlun merged commit d64f556 into master Apr 22, 2023
@perlun perlun deleted the feature/use-Perlang-strings-in-print-statement branch April 22, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant