1. Home
  2. Explore
  3. Computer Science
  4. Crust Programming Language

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Crust Programming Language

  • 61Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Crust Principles
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is Crust?

Tap to flipClick to flipspace

Crust is an unsafe-oriented variant of Rust designed to be more comfortable for C developers and recreational programming.

Or swipe the card

61 cards

  1. What is Crust?

    Crust is an unsafe-oriented variant of Rust designed to be more comfortable for C developers and recreational programming.

  2. What are the main rules of Crust?

    Every function is unsafe, references are avoided in favor of pointers, and the standard library is not used; libc is used instead.

  3. Why was Crust created?

    To provide a Rust-based language that C developers could use without dealing with Rust's borrow-checking and safety restrictions.

  4. For what kinds of applications is Crust not recommended?

    Security-critical applications, because its unsafe pointer-based model does not provide Rust's usual memory-safety guarantees.

  5. What earlier Crust projects were mentioned?

    A Hello World program, dynamic arrays, and calls to array-related functions.

  6. How does Crust differ from ordinary Rust regarding the standard library?

    Crust avoids the standard library and instead relies on libc and explicitly defined foreign-function bindings.

  7. What is one major cost of using Crust?

    The programmer must manually manage pointers, FFI declarations, memory layout, linking, and low-level runtime details.

  8. What safety observation was made after several hours of Crust development?

    No segmentation fault had occurred during the demonstration, even though the code was not memory-safe.

  9. What is the relationship between B and C?

    B was created before C and served as a predecessor or prequel to C.

  10. Who created the B programming language?

    Ken Thompson.

  11. Why was B described as a genuinely dead programming language?

    Unlike languages preserved by large legacy codebases, B is no longer used in practice and has no known official compiler.

  12. What made the B reference difficult to use?

    It was digitized from scanned paper using OCR, so some syntax—such as punctuation or initialization symbols—might have been misread.

  13. What data type does B primarily use?

    A machine word; variables are effectively word-sized integers rather than explicitly typed values.

  14. What is the purpose of the B auto storage class?

    It declares automatic storage, meaning the variable is allocated for a function invocation and released when the function exits.

  15. What are B's three storage classes?

    Automatic, external, and internal storage.

  16. What does B external storage represent?

    Storage allocated before execution and accessible to any function.

  17. What does B internal storage most closely resemble in C?

    A static local variable: it is local to one function but remains available across all invocations of that function.

  18. What is an external declaration in B?

    A declaration listing names with external storage that must appear before their first use and correspond to external definitions.

  19. What does the B extern declaration for putchar indicate?

    It tells the compiler that putchar is defined elsewhere, such as in the C runtime library.

  20. What role does putchar play in the example B program?

    It outputs the character associated with an integer character code.

  21. What example B program was initially targeted by the compiler?

    A program that declares automatic variables a and b, assigns them values, adds them, and calls putchar with the result.

  22. What is the usual incremental strategy used to implement a compiler?

    Start with one very simple valid program, implement enough of the compiler to translate it, and gradually add more language features.

  23. What is the first major phase of compiling a B program?

    Tokenization, or lexing the source code into tokens.

  24. What library was used for tokenizing the B source?

    stb_c_lexer.

  25. How does the lexer indicate that it has reached the end of the file?

    Its token-retrieval function returns zero.

  26. How are single-character tokens represented by the lexer?

    If the token value is below 256, it can be interpreted as a character.

  27. What is the purpose of an expect helper in the compiler?

    It verifies that the next token has the expected value and reports an error if it does not.

  28. Why were separate token retrieval and token-expectation operations retained?

    Parsing sometimes requires retrieving a token first and deciding how to interpret it before validating it.

  29. What information can be included in a compiler diagnostic?

    The expected token, the actual token, the source file, the line number, and the character offset.

  30. Why should lexer location lookup be used selectively?

    The demonstrated location function scans from the beginning of the source, making it inefficient when called for every token.

  31. What external C libraries were integrated into the Crust compiler?

    knob for file operations and stb_c_lexer for lexing.

  32. Why can C header-only libraries not always be used directly from Crust?

    They may contain C implementations and macros that must first be compiled as C code and then exposed through FFI bindings.

  33. How was a C implementation from a header compiled into an object file?

    The implementation macro was defined and the C compiler was invoked in compile-only mode, producing an object file rather than a final executable.

  34. What is required to call a C function from Crust?

    A C-compatible external declaration, matching parameter and return types, and correct symbol-linking information.

  35. Why was a C representation specified for imported structures?

    To ensure that the Crust structure has the same memory layout as the corresponding C structure.

  36. What was the purpose of a link-name attribute?

    To tell Crust the actual external symbol name when the local Rust-like function name differs from the C symbol.

  37. How was an entire file read through the imported C library?

    A string-builder structure was allocated, passed by mutable pointer to the C file-reading function, and then its item buffer and count were used.

  38. Why did the compiler need a panic handler and a no-standard-library configuration?

    Because the Crust program was built without the normal Rust runtime and standard library, so required runtime behavior had to be supplied explicitly.

  39. What is a key benefit of Crust's module namespaces compared with C prefixes?

    Names can be accessed through modules instead of manually embedding prefixes in every identifier.

  40. What is the purpose of the compiler's generated assembly prologue?

    It emits the assembly format, executable section, external declarations, and entry-point or function labels required for later assembly and linking.

  41. What assembler output format was generated?

    64-bit ELF assembly for the x86-64 target.

  42. How was the C runtime used by the generated B program?

    The generated code used main as the entry point and linked with the C compiler/runtime so that functions such as putchar could be called.

  43. How is a function's return value passed on x86-64 System V systems?

    It is returned in the rax register.

  44. Which register is used for the first integer or pointer function argument under the x86-64 System V convention?

    rdi.

  45. What is the purpose of the procedure linkage table, or PLT?

    It provides an indirect mechanism for calling externally defined functions, especially when using position-independent code.

  46. What does position-independent code mean?

    Code that can execute correctly regardless of where it is loaded in memory.

  47. Why was a frame pointer used for local variables?

    The stack pointer changes as variables are allocated, so a stable frame pointer provides a fixed base for calculating local-variable offsets.

  48. How were B automatic variables represented in the generated assembly?

    Each variable occupied one machine word on the stack, and the compiler tracked its offset from the function's frame pointer.

  49. Why were local-variable offsets reset for each function?

    Variables belong to individual function stack frames and must not be shared between separate functions.

  50. What does the generated function epilogue do?

    It releases local stack storage, restores the previous frame pointer, places the return value in rax, and executes ret.

  51. What minimal B subset was eventually compiled?

    External declarations, automatic variable declarations, integer assignments, variable reads, function calls, multiple functions, and recursive calls.

  52. How were duplicate automatic-variable declarations detected?

    The compiler linearly searched its dynamic array of variables by name before adding a new declaration.

  53. Why was a linear array used instead of a hash table for variable lookup?

    Using a linear array was simpler and avoided spending time porting a macro-heavy C hash-table library.

  54. What happened when an assignment referenced an undeclared variable?

    The compiler reported that it could not find the variable and included its source location.

  55. What was the first successful observable result of the generated B program?

    The program printed E by passing the ASCII code 69 to putchar.

  56. How did the compiler support multiple functions?

    An outer loop parsed function definitions, while an inner loop parsed the statements within each function body.

  57. What caused an illegal instruction or incorrect behavior when multiple functions were added?

    Local-variable state and stack offsets were incorrectly shared across functions.

  58. What additional function-call feature was added after the first working compiler?

    Calls to functions with no arguments, in addition to calls with one variable argument.

  59. What limitation remained in the demonstrated compiler?

    It lacked many core language features, including general expressions, conditionals, loops, global variables, and full parameter handling.

  60. What did successful recursive calls demonstrate?

    The generated calling and stack mechanisms were sufficient to support recursion, although uncontrolled recursion could overflow the stack.

  61. Why was the compiler developed as a single-pass-style compiler?

    B's syntax and simple storage model make it possible to parse constructs and emit assembly as they are encountered.

Card 1 of 61
Card 1 of 61

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent