CoclSystemDependent.icl 2.89 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1 2 3 4
// this is for Unix
implementation module CoclSystemDependent

import StdEnv
5 6 7 8
import StdDebug
import ArgEnv
import ipc
from filesystem import ensureDirectoryExists
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
9

10
import code from "cDirectory.o"
11
import code from "ipc_c.o"
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25

PathSeparator
	:==	':'
DirectorySeparator
	:== '/'

SystemDependentDevices :: [a]
SystemDependentDevices
		=	[]

SystemDependentInitialIO :: [a]
SystemDependentInitialIO
		=	[]

26 27 28
set_compiler_id :: Int -> Int
set_compiler_id compiler_id = compiler_id

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
29 30 31 32 33
ensureCleanSystemFilesExists :: !String !*Files -> (!Bool, !*Files)
// returned bool: now there is such a subfolder
ensureCleanSystemFilesExists path env
	= ensureDirectoryExists path env

34
	
35
compiler_loop :: ([{#Char}] *st -> *(Bool, *st)) *st -> (!Bool, !*st)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
compiler_loop compile compile_state
	| length commandArgs==3 && commandArgs!!0=="--pipe"
		# commands_name= (commandArgs!!1);
		# results_name= (commandArgs!!2);
		= (True,compile_loop compile commands_name results_name compile_state)
		# (r,compile_state)=compile commandArgs compile_state
		= (r,compile_state)
	where
		commandArgs
			=	tl [arg \\ arg <-: getCommandLine]
// ... Unix

string_to_args string
	= string_to_args 0;
	where
		l=size string;
		
		string_to_args i
			# end_spaces_i=skip_spaces i;
			| end_spaces_i==l
				= []
			| string.[end_spaces_i]=='"'
				# next_double_quote_i=skip_to_double_quote (end_spaces_i+1)
				| next_double_quote_i>=l
					= [string % (end_spaces_i,l-1)]
					# arg=string % (end_spaces_i+1,next_double_quote_i-1);
					= [arg : string_to_args (next_double_quote_i+1)];
				# space_i=skip_to_space (end_spaces_i+1)
				| space_i>=l
					= [string % (end_spaces_i,l-1)]
					# arg=string % (end_spaces_i,space_i-1);
					= [arg : string_to_args (space_i+1)];

		skip_spaces i
			| i>=l
				= l;
			# c=string.[i];
			| c==' ' || c=='\t'
				= skip_spaces (i+1);
				= i;

		skip_to_space i
			| i>=l
				= l;
			# c=string.[i];
			| c==' ' || c=='\t'
				= i;
				= skip_to_space (i+1);

		skip_to_double_quote i
			| i>=l
				= l;
			# c=string.[i];
			| c=='"'
				= i;
				= skip_to_double_quote (i+1);


94
compile_loop :: ([{#Char}] *st -> *(Bool, *st)) {#Char} {#Char} *st -> *st
95 96 97 98 99 100
compile_loop compile commands results compile_state
	# r=open_pipes commands results;
	| r<>0
		= abort ("compile_loop\n");
	=	compile_files compile compile_state

101
compile_files :: ([{#Char}] *st -> *(Bool, *st)) *st -> *st
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
compile_files compile compile_state
	# n = get_command_length;
	| n==(-1)
		= abort "compile_files 1";
	# string=createArray n '\0';
	# r=get_command string;
	| r<>0
		= abort ("compile_files 2 ");
	# args=string_to_args (string % (0,size string-2))
	= case args of
		["cocl":cocl_args]
			# (ok,compile_state)=compile cocl_args compile_state
			# result=if ok 0(-1);
			# r=send_result result
			| r<>0
				-> abort "compile_files 3";
				-> compile_files compile compile_state
		["quit"]
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
120
			-> /* trace_n "quiting" */ compile_state;
121 122
		_
				-> abort "compile_files 4"