This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
from collections import deque | |
from pr01 import prefixParser | |
USAGE_MESSAGE = "pr01 [file]" | |
EXTENDED_MESSAGE = ''' | |
Takes a file as an argument or on stdin, parses it as an expression tree, and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_instructions(pattern_list): | |
"""Takes a list of regex patterns and compiles them to a list of VM | |
instructions via the lexc tool, and then returns that list.""" | |
# The lexing compiler should be in the same folder as us | |
lexexec = os.path.abspath(os.path.join(sys.path[0], "lexc")) | |
# (Yes, this giant chain of os.path things checks that) | |
if not os.path.isfile(os.path.abspath(os.path.join(sys.path[0], "lexc"))): | |
print lexexec | |
raise IOError("Lexc executable not in same folder as program.") | |
command = [lexexec] + ["--pattern=%s" % str(pattern) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Found the Vertex shader, loading it. | |
Found the Control shader, loading it. | |
ERROR: 0:4: Invalid use of layout 'vertices' | |
ERROR: 0:15: Use of undeclared identifier 'gl_InvocationID' | |
ERROR: 0:15: Use of undeclared identifier 'gl_InvocationID' | |
ERROR: 0:17: Use of undeclared identifier 'gl_InvocationID' | |
ERROR: 0:18: Use of undeclared identifier 'gl_TessLevelInner' | |
ERROR: 0:19: Use of undeclared identifier 'gl_TessLevelInner' | |
ERROR: 0:20: Use of undeclared identifier 'gl_TessLevelOuter' | |
ERROR: 0:21: Use of undeclared identifier 'gl_TessLevelOuter' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with NamedTemporaryFile(suffix=".s", mode='rw+b') as asm_temp: | |
asm_temp.write(get_asm(source_file)) | |
asm_temp.write(get_lib()) | |
log("> Compiling with gcc...") | |
subprocess.call(["gcc", | |
"-m32", | |
"-o", output_file.name, | |
asm_temp.name | |
]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("a.s", "w") as asm_temp: | |
asm_temp.write(get_asm(source_file)) | |
asm_temp.write(get_lib()) | |
with open("a.s", "r") as asm_temp: | |
log("> Compiling with gcc...") | |
subprocess.call(["gcc", | |
"-m32", | |
"-o", output_file.name, | |
asm_temp.name | |
]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int fib(int n) | |
{ | |
if (n <= 2) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return fib(n - 1) + fib(n - 2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char path[PATH_MAX]; | |
// We use this getpwuid(geteuid()) construct instead of cuserid() | |
// for portability (Works on OS X and Linux) | |
printf("I ran in the directory %s, as effective user %s, real user %s.\n", | |
getcwd(path, PATH_MAX), | |
getpwuid(geteuid())->pw_name, | |
getpwuid(getuid())->pw_name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int shm_id = shmget(SHM_KEY, 1024, 0777); | |
my_shared = (struct common *)shmat(shm_id, 0, 0); | |
if ((my_shared->bridge_dir == GOING_EAST || | |
my_shared->bridge_dir == NONE) && | |
(my_shared->xed_count < 4 && | |
(my_shared->xed_count + my_shared->xing_count) < 5)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shm_id = shmget(SHM_KEY, 1024, 0777|IPC_CREAT); | |
shared = (struct common *)shmat(shm_id, 0, 0); | |
shared->xing_count = 0; | |
shared->xed_count = 0; | |
shared->eastbound_wait = 0; | |
shared->westbound_wait = 0; | |
shared->bridge_dir = NONE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void eastbound_car() { | |
printf("Eastbound Car (PID: %d) spawned\n", getpid()); | |
// Get the Semaphore set | |
int sem_set_id = semget(SEM_KEY, NUM_SEMS, 0777); | |
// Get the Shared Memory | |
struct common *my_shared; | |
int shm_id = shmget(SHM_KEY, 0, 0); | |
my_shared = (struct common *)shmat(shm_id, 0, 0); | |
printf("Cars crossed: %d\n", my_shared->xed_count); | |
printf("Bridge Direction: %d\n", my_shared->bridge_dir); |