Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A C implementation of Lox

NotificationsYou must be signed in to change notification settings

mrjameshamilton/clox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an implementation of the C Lox compiler fromCrafting Interpreters.The implementation is mostly the same as in the book but with the following changes:

  • Constants use 8 or 16-bit indices.
  • New instructions:
    • OP_ZERO push 0 onto the stack
    • OP_ONE push 1 onto the stack
    • OP_MINUS_ONE push -1 onto the stack
    • OP_INTEGER pushes an 8-bit integer onto the stack
    • OP_INTEGER_16 pushes a 16-bit integer onto the stack
    • OP_CONSTANT_16 push a 16-bit indexed constant onto the stack
  • New native functions:
    • read() reads a byte fromstdin ornil if end of stream
    • utf(byte, byte, byte, byte) converts 1, 2, 3, or 4 bytes into a UTF string
    • printerr(string) prints a string tostderr
    • exit(number) exits with the specific exit code

These additions allow runningLox.lox, an Lox interpreter written in Lox. In particular, Lox.lox introduces more constants than the original limit 255 per-chunk in the original clox implementation and requires the 4 native functions.

Build

$ gcc src/*.src -O3 -o clox

Run

$ ./clox examples/helloworld.lox

About

A C implementation of Lox

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp