Crust Programming Language
- 49Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Which rule is part of the proposed Crust language variant?
Which rule is part of the proposed Crust language variant?
49 questions
- 1
Which rule is part of the proposed Crust language variant?
- A
Every function must use the standard library
- B
Every function must prohibit pointer operations
- C
Every function must use references
- D
Every function is treated as unsafe
Correct answer
DEvery function is treated as unsafe
Explanation
The proposed Crust rules include making every function unsafe, using pointers instead of references, and avoiding the standard library in favor of libc.
- A
- 2
How does Crust differ from ordinary Rust in its pointer model?
- A
Crust prohibits both pointers and references
- B
Crust uses pointers instead of references
- C
Crust allows references but prohibits mutable pointers
- D
Crust replaces pointers with garbage-collected objects
Correct answer
BCrust uses pointers instead of references
Explanation
One of the stated Crust rules is to avoid references and use pointers instead.
- A
- 3
Which library strategy does the proposed Crust variant use?
- A
It prohibits all external libraries
- B
It uses the Rust standard library instead of libc
- C
It uses only C++ standard-library components
- D
It uses libc instead of the Rust standard library
Correct answer
DIt uses libc instead of the Rust standard library
Explanation
The proposed variant avoids the standard library and uses libc.
- A
- 4
What is the intended primary use of Crust in the discussion?
- A
Financial systems requiring memory-safety guarantees
- B
Operating-system kernels requiring formal verification
- C
Recreational programming and experimentation
- D
Security-critical production services
Correct answer
CRecreational programming and experimentation
Explanation
The speaker explicitly describes Crust as being intended for recreational programming and warns against using it for security-critical applications.
- A
- 5
Why was Crust presented as potentially attractive to C developers?
- A
It automatically converts all C code into safe Rust
- B
It removes much of Rust's safety-related friction
- C
It requires developers to use more ownership annotations
- D
It replaces machine code with garbage-collected bytecode
Correct answer
BIt removes much of Rust's safety-related friction
Explanation
The proposed rules make Rust more similar to unsafe C-style programming by emphasizing pointers and removing standard-library and reference-based restrictions.
- A
- 6
Which earlier Crust examples were mentioned as completed exercises?
- A
A database engine and a web server
- B
A garbage collector and a virtual machine
- C
Hello World and dynamic arrays
- D
A kernel and a device driver
Correct answer
CHello World and dynamic arrays
Explanation
The earlier exercises included a simple Hello World program, dynamic arrays, and calls to array-related functions.
- A
- 7
What is the main purpose of the panic handler in a minimal no-standard-library Rust-like executable?
- A
To replace the linker with a parser
- B
To allocate every local variable on the heap
- C
To provide the program's command-line arguments
- D
To define what happens when a panic occurs
Correct answer
DTo define what happens when a panic occurs
Explanation
A panic handler is required in the minimal setup so the compiler knows how panic situations are handled when the standard runtime is absent.
- A
- 8
Why was an object file emitted when compiling the Crust source?
- A
Object files are used only to hold debugging warnings
- B
Object files are required to store source-code comments
- C
The compiler could not produce machine code from Rust-like syntax
- D
It had to be linked with other object files into the final executable
Correct answer
DIt had to be linked with other object files into the final executable
Explanation
The build process first produced an object file and then linked it with other objects and libraries to create the final executable.
- A
- 9
What is the historical relationship between B and C described in the content?
- A
B preceded C as an earlier programming language
- B
B was created as a replacement for modern C++
- C
B was derived from C after C became obsolete
- D
B and C were unrelated languages created simultaneously
Correct answer
AB preceded C as an earlier programming language
Explanation
B was described as a predecessor or prequel to C, created before the C programming language.
- A
- 10
Why is B described as genuinely dead compared with languages such as COBOL?
- A
It remains popular because its standard library is extensive
- B
It has essentially no current users or established codebase
- C
It is still widely used in financial legacy systems
- D
It is maintained by several major operating-system vendors
Correct answer
BIt has essentially no current users or established codebase
Explanation
The discussion contrasts B with COBOL: COBOL remains active because of substantial legacy code, whereas B is described as no longer being used.
- A
- 11
What limitation concerning B compilers was emphasized?
- A
There was no clearly established official compiler
- B
The official compiler was included in every C distribution
- C
The official compiler required a modern garbage collector
- D
B had too many competing official compilers
Correct answer
AThere was no clearly established official compiler
Explanation
The speaker stated that B had no known official compiler, although enthusiasts may have created implementations.
- A
- 12
What uncertainty surrounds the available reference material for B?
- A
The document was generated entirely by a modern compiler
- B
The reference was written as executable machine code
- C
Some text may have been distorted by optical character recognition
- D
The examples were translated from C++ automatically
Correct answer
CSome text may have been distorted by optical character recognition
Explanation
The reference was described as having been scanned and processed with OCR, so symbols or punctuation may have been misrecognized.
- A
- 13
What is the principal data type described for the B language?
- A
A dynamically tagged string
- B
A machine word
- C
A floating-point vector
- D
A garbage-collected object
Correct answer
BA machine word
Explanation
The discussion states that B effectively has one type: a word corresponding to a machine word.
- A
- 14
What happens when a B variable is declared under the one-word type model?
- A
It becomes a reference whose lifetime is checked statically
- B
It must be declared as either a character or a floating point
- C
It is treated as a variable containing a machine word
- D
It is automatically assigned a distinct structure type
Correct answer
CIt is treated as a variable containing a machine word
Explanation
Because B was described as having only a word type, declared variables are treated as machine-word values.
- A
- 15
What does the
autostorage class mean in the described B model?- A
Storage is allocated for each function invocation
- B
Storage is allocated only after a heap collection
- C
Storage is shared by all functions globally
- D
Storage persists across every program execution
Correct answer
AStorage is allocated for each function invocation
Explanation
Automatic storage is allocated for each function invocation, corresponding conceptually to stack storage.
- A
- 16
What distinguishes external storage from internal storage in the B description?
- A
External storage exists only during an invocation, while internal storage is always global
- B
External storage is read-only, while internal storage cannot be initialized
- C
External storage is available to functions broadly, while internal storage is local to one function
- D
External storage is heap-allocated, while internal storage is stored in registers only
Correct answer
CExternal storage is available to functions broadly, while internal storage is local to one function
Explanation
External storage is allocated before execution and can be available to functions, whereas internal storage is local to a function but persists across its invocations.
- A
- 17
What role does an external declaration serve in B?
- A
It declares names that are defined elsewhere
- B
It allocates every declared variable on the stack
- C
It prevents a name from being used by the linker
- D
It converts a function into a macro
Correct answer
AIt declares names that are defined elsewhere
Explanation
An external declaration identifies variables or functions that are externally defined and must be resolved during linking.
- A
- 18
Why can an external declaration act as a forward declaration?
- A
It copies the definition into every calling function
- B
It automatically defines the name with a default value
- C
It delays lexical analysis until program execution
- D
It allows a name to be declared before its definition is encountered
Correct answer
DIt allows a name to be declared before its definition is encountered
Explanation
The content explains that external declarations may introduce names before their actual definitions, allowing later resolution by the linker.
- A
- 19
What function was used as the example of an externally supplied B function?
- A
putchar - B
strlen - C
malloc - D
exit
Correct answer
AputcharExplanation
The example externally declared
putchar, which was assumed to print the character associated with an integer character code. - A
- 20
What does the example B program do with the values assigned to
aandb?- A
It adds them and passes the result to
putchar - B
It compares them and returns the larger value
- C
It multiplies them and stores the result in an array
- D
It subtracts them and uses the result as an address
Correct answer
AIt adds them and passes the result to
putcharExplanation
The example assigns values to
aandb, computesa + b, and passes the result toputchar. - A
- 21
What is the first major compilation phase proposed after reading the B source file?
- A
Dynamic linking
- B
Executable compression
- C
Tokenization
- D
Register allocation
Correct answer
CTokenization
Explanation
The discussion identifies tokenization as the usual first step after reading source text during compilation.
- A
- 22
What is the purpose of a lexer in the proposed B compiler?
- A
To link object files into an executable
- B
To convert source characters into tokens
- C
To execute generated assembly instructions
- D
To allocate stack slots for local variables
Correct answer
BTo convert source characters into tokens
Explanation
The lexer analyzes the source text and produces tokens such as identifiers, punctuation, literals, and keywords.
- A
- 23
Why was an existing single-header lexer considered useful?
- A
It automatically generated all assembly code for B
- B
It converted B directly into machine code without parsing
- C
It provided tokenization functionality that could be called through bindings
- D
It replaced the need for a linker and C runtime
Correct answer
CIt provided tokenization functionality that could be called through bindings
Explanation
The lexer library was used to tokenize the source, while the compiler itself remained responsible for interpreting those tokens and generating output.
- A
- 24
What does a lexer return when it reaches the end of the input?
- A
A new function declaration
- B
A linker relocation record
- C
A stack-allocation token
- D
An end-of-file token
Correct answer
DAn end-of-file token
Explanation
The implementation checks for a designated end-of-file token to determine when tokenization has finished.
- A
- 25
How were token values below 256 interpreted in the lexer discussion?
- A
They always represented function identifiers
- B
They represented external-linker directives
- C
They always represented parse errors
- D
They could represent individual character tokens
Correct answer
DThey could represent individual character tokens
Explanation
The discussion explains that tokens below 256 can be treated as character values, while larger values represent lexer-specific token kinds.
- A
- 26
What was the role of an
expecthelper in the compiler?- A
It allocated a new string buffer for each token
- B
It checked whether the next token matched an expected token
- C
It executed a function whenever a token was recognized
- D
It converted every token into an assembly instruction
Correct answer
BIt checked whether the next token matched an expected token
Explanation
The helper compared an obtained token with an expected token and reported an error if they differed.
- A
- 27
Why was source-location information useful in the compiler?
- A
It replaced the need for tokenization
- B
It automatically optimized arithmetic expressions
- C
It allowed syntax errors to report a file position
- D
It enabled the compiler to avoid all pointer operations
Correct answer
CIt allowed syntax errors to report a file position
Explanation
The compiler used lexer location information to report the file, line, and offset associated with an error.
- A
- 28
Why was obtaining a token's location described as potentially expensive?
- A
The lexer may scan from the beginning of the source to compute it
- B
The location is stored only in an external database
- C
The operation requires executing the generated program
- D
The operation requires rebuilding every object file
Correct answer
AThe lexer may scan from the beginning of the source to compute it
Explanation
The lexer’s location function was described as inefficient because it may scan the source from the beginning, making it more appropriate for error reporting than constant use.
- A
- 29
What compilation strategy was intentionally used for the initial B compiler?
- A
Start with a tiny example and expand the supported subset incrementally
- B
Implement the entire language specification before testing anything
- C
Generate optimized machine code before implementing parsing
- D
Begin with a complete standard library and add syntax later
Correct answer
AStart with a tiny example and expand the supported subset incrementally
Explanation
The approach was to support one very simple program first and then add more syntax and behavior incrementally.
- A
- 30
What is a single-pass compiler intended to do while reading source code?
- A
Perform linking before lexical analysis
- B
Execute every statement during compilation
- C
Parse constructs and generate output as it proceeds
- D
Read the entire program repeatedly before generating anything
Correct answer
CParse constructs and generate output as it proceeds
Explanation
The discussion describes B as being suitable for a single-pass approach in which the compiler generates code as it encounters declarations and statements.
- A
- 31
Why did the compiler need a table of automatic variables?
- A
To replace the generated assembly with bytecode
- B
To store every source token permanently
- C
To map variable names to their stack offsets
- D
To record which library provided each keyword
Correct answer
CTo map variable names to their stack offsets
Explanation
The compiler stored each automatic variable's name and offset so later assignments and reads could refer to the correct stack location.
- A
- 32
Why was a base pointer useful when compiling local variables?
- A
It automatically converted integers into character codes
- B
It provided a stable reference for calculating local-variable offsets
- C
It prevented the stack pointer from changing during calls
- D
It identified external functions during lexical analysis
Correct answer
BIt provided a stable reference for calculating local-variable offsets
Explanation
Because the stack pointer changes as storage is allocated, the base pointer was used as a stable point from which local-variable offsets could be calculated.
- A
- 33
What bug can occur if one local-variable table is reused across multiple functions without resetting it?
- A
Variables from different functions can interfere with one another
- B
Every function is forced to use the same return register
- C
The lexer can no longer recognize character tokens
- D
The linker automatically removes all external symbols
Correct answer
AVariables from different functions can interfere with one another
Explanation
Local-variable names and offsets belong to individual functions, so the compiler must reset or replace that state for each new function.
- A
- 34
Why was a linear dynamic array chosen instead of a hash table for local variables?
- A
It guaranteed constant-time lookup for every variable
- B
It was required by the B language specification
- C
It eliminated the need to store variable names
- D
It avoided the complexity of porting a macro-heavy hash-table library
Correct answer
DIt avoided the complexity of porting a macro-heavy hash-table library
Explanation
The discussion considered using a hash-table library but abandoned it because its macro-based interface and type-size issues would create a substantial implementation detour.
- A
- 35
What assembly representation was selected as the initial compiler backend?
- A
WebAssembly text format
- B
Flat Assembler-style x86-64 assembly
- C
Java bytecode
- D
ARM machine code
Correct answer
BFlat Assembler-style x86-64 assembly
Explanation
The compiler was designed to generate Flat Assembler-style assembly targeting x86-64.
- A
- 36
What is the purpose of the assembly prologue generated for a function?
- A
To resolve all external library names
- B
To tokenize the function body
- C
To convert character literals into source text
- D
To establish the function's stack frame
Correct answer
DTo establish the function's stack frame
Explanation
The prologue saves the previous base pointer, establishes a new base pointer, and prepares the stack frame for local variables.
- A
- 37
How were local variables initially allocated in the generated assembly?
- A
By placing every variable in the instruction stream
- B
By allocating every variable in a global heap
- C
By subtracting word-sized amounts from the stack pointer
- D
By assigning every variable to the same register
Correct answer
CBy subtracting word-sized amounts from the stack pointer
Explanation
The compiler allocated automatic variables by moving the stack pointer downward, using one machine-word-sized slot per variable.
- A
- 38
What does the function epilogue do with the space allocated for local variables?
- A
It leaves the stack pointer permanently changed
- B
It copies all local variables into the heap
- C
It converts the variables into external symbols
- D
It restores the stack pointer by adding back the allocated size
Correct answer
DIt restores the stack pointer by adding back the allocated size
Explanation
The epilogue reverses the stack allocation by adding the total local-variable size back to the stack pointer.
- A
- 39
Which register was used for the first integer or pointer function argument under the discussed x86-64 calling convention?
- A
RSP - B
RBP - C
RAX - D
RDI
Correct answer
DRDIExplanation
Under the discussed System V x86-64 convention, the first integer or pointer argument is passed in
RDI. - A
- 40
Which register was used for a function's return value in the generated x86-64 code?
- A
RSP - B
RBP - C
RAX - D
RDI
Correct answer
CRAXExplanation
The discussion states that x86-64 functions return values through
RAX. - A
- 41
Why was the C runtime linked into the generated B program?
- A
It converted all B variables into Rust references
- B
It provided the B lexer and parser automatically
- C
It eliminated the need for assembly output
- D
It supplied functions such as
putcharand startup behavior
Correct answer
DIt supplied functions such as
putcharand startup behaviorExplanation
Linking with the C runtime made functions such as
putcharavailable and allowed the program to use the runtime's startup and exit conventions. - A
- 42
What is the purpose of the Procedure Linkage Table, or PLT?
- A
It stores local variables on the stack
- B
It supports calls to externally linked functions
- C
It records the line number of every syntax error
- D
It converts source tokens into identifiers
Correct answer
BIt supports calls to externally linked functions
Explanation
The PLT provides a mechanism for calling external functions through dynamically linked symbol-resolution machinery.
- A
- 43
What does position-independent code allow an executable or object to do?
- A
Skip the assembly and linking stages
- B
Avoid using any external functions
- C
Store all variables in registers permanently
- D
Execute correctly regardless of its load address
Correct answer
DExecute correctly regardless of its load address
Explanation
Position-independent code is designed to work even when loaded at different memory addresses, often using mechanisms such as the GOT and PLT.
- A
- 44
What does the
externdeclaration in the generated assembly communicate?- A
A local variable must be allocated on the stack
- B
A token is the end of the source file
- C
A symbol is defined outside the current assembly unit
- D
A function must be inlined into every caller
Correct answer
CA symbol is defined outside the current assembly unit
Explanation
An external declaration tells the assembler and linker that the symbol will be supplied by another object file or library.
- A
- 45
Why did the compiler need to emit a public label for a function?
- A
The linker had to be able to resolve calls to that function
- B
The function could otherwise not contain local variables
- C
Public labels are required to represent integer literals
- D
The lexer could recognize only public identifiers
Correct answer
AThe linker had to be able to resolve calls to that function
Explanation
Making a function label public exposes it to the linker and allows other functions or object files to call it.
- A
- 46
What output demonstrated that the generated B program worked?
- A
Passing character code 69 produced a linker error
- B
Passing character code 69 to
putcharproducedE - C
Passing character code 69 caused the lexer to stop
- D
Passing character code 69 produced the string
B
Correct answer
BPassing character code 69 to
putcharproducedEExplanation
The ASCII code 69 corresponds to the character
E, so observingEconfirmed that the generated code, linking, and function call worked. - A
- 47
Why did the compiler initially need only one local-variable offset per variable?
- A
The compiler allocated variables only in global memory
- B
The lexer encoded every variable name as a fixed instruction
- C
All B variables were represented as equally sized machine words
- D
B variables were all stored as variable-length strings
Correct answer
CAll B variables were represented as equally sized machine words
Explanation
Because the discussed B model uses machine words as its fundamental type, each automatic variable occupies the same word-sized stack slot.
- A
- 48
What did adding an outer loop around function parsing enable?
- A
The compiler could avoid generating function labels
- B
The linker could eliminate all stack frames
- C
The compiler could process multiple function definitions
- D
The lexer could recognize multiple character encodings
Correct answer
CThe compiler could process multiple function definitions
Explanation
An outer loop allowed the compiler to parse one function after another, while an inner loop handled statements within each function.
- A
- 49
Why did recursive calls expose a bug after multiple functions were supported?
- A
The C runtime rejected all calls through
RDI - B
Function-local state was incorrectly shared across functions
- C
The lexer treated every closing brace as an external symbol
- D
The assembler could not encode the
returninstruction
Correct answer
BFunction-local state was incorrectly shared across functions
Explanation
The compiler initially reused variable-tracking state across functions, causing incorrect stack offsets and invalid generated behavior when functions interacted or called themselves.
- A

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