Skip to content

Commit

Permalink
New C function
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoal committed Apr 7, 2024
1 parent 7202bb4 commit cb5fb46
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions c/inspect.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>

// A few global variables
int g0 = 1; // initialized
int g1[1000]; // uninitialized
int g2 = 3; // initialized
int g3; // uninitialized

// A little function with its own local variables
void f() {
double x; printf("x: %p\n", &x);
if (g2-- > 0) f();
}

// The main function has two local variables, p and q, and
// allocates two blocks of memory at run time.
int main() {
int* p = malloc(sizeof(int) * 20); // dynamically allocated
int* q = malloc(sizeof(int) * 50); // dynamically allocated
printf("g0: %p, g1: %p, g2: %p, g3: %p\n", &g0, g1, &g2, &g3);
f();
printf("main: %p, f: %p\n", &main, &f);
printf("&p: %p, &q: %p, p: %p, q: %p\n", &p, &q, p, q);

// C requires manual cleanup of dynamically allocated memory
free(p);
free(q);
return EXIT_SUCCESS;
}
5 changes: 4 additions & 1 deletion projects/bella/src/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export default function generate(program) {
}
})(new Map())

const gen = node => generators?.[node?.kind]?.(node) ?? node
function gen(node) {
// Node types without explicit handlers just "pass through"
return generators?.[node?.kind]?.(node) ?? node
}

const generators = {
// Key idea: when generating an expression, return the translated
Expand Down

0 comments on commit cb5fb46

Please sign in to comment.