Radicalc  Check-in [c16abe7c58]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:changed how returns work
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:c16abe7c58be0ce5cd630428d00cf1fd150b4794fed9e6ac81c6b3e0b241545d
User & Date: athaudia 2017-08-02 11:40:55
Context
2017-08-06
15:44
temporary copy of parameters check-in: d26be5d653 user: athaudia tags: trunk
2017-08-02
11:40
changed how returns work check-in: c16abe7c58 user: athaudia tags: trunk
2017-08-01
16:47
linking external functions check-in: e8c0955585 user: athaudia tags: trunk
Changes

Changes to src/llvm.js.

191
192
193
194
195
196
197
198

199
200
201
202
203

204
205

206
207
208
209
210
211
212
...
275
276
277
278
279
280
281







282
















283
284
285
286
287
288
289
			out.write("* ");
			outVar(out, stmt.var);
			out.write("\n");
			break;
		case 'return':
			if(stmt.expr) {
				var ret = outNode(out, stmt.expr);
				out.write("  ret ");

				outDataType(out, stmt.dataType);
				out.write(" ");
				out.write(ret);
				out.write("\n");
			} else {

				out.write("  ret void\n");
			}

			break;
		case 'stmtExpr':
			outNode(out, stmt.expr);
			break;
		case 'varDef':
			if(stmt.expr) {
				var tmp = outNode(out, stmt.expr);
................................................................................
		if(i > 0)
			out.write(", ");
		outDataType(out, p.dataType);
		out.write(" ");
		out.write(varStr(p));
	} 
	out.write(") {\n");







	outBlock(out, fun.block);
















	out.write("}\n\n");
}

function outExternalFunction(out, fun) {
	out.write("declare ");
	outDataType(out, fun.dataType);
	out.write(" ");







|
>
|

|
|
<
>
|

>







 







>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214
...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
			out.write("* ");
			outVar(out, stmt.var);
			out.write("\n");
			break;
		case 'return':
			if(stmt.expr) {
				var ret = outNode(out, stmt.expr);
				out.write("  store ");
				console.log(stmt.fun.dataType);
				outDataType(out, stmt.fun.dataType);
				out.write(" ");
				out.write(String(ret));
				out.write(", ");

				outDataType(out, stmt.fun.dataType);
				out.write("* %result\n")
			}
			out.write("  br label %return_"+stmt.fun.name+"\n")
			break;
		case 'stmtExpr':
			outNode(out, stmt.expr);
			break;
		case 'varDef':
			if(stmt.expr) {
				var tmp = outNode(out, stmt.expr);
................................................................................
		if(i > 0)
			out.write(", ");
		outDataType(out, p.dataType);
		out.write(" ");
		out.write(varStr(p));
	} 
	out.write(") {\n");

	if(fun.dataType.name != 'void') {
		out.write("  %result = alloca ");
		outDataType(out, fun.dataType);
		out.write("\n");
	}
	
	outBlock(out, fun.block);

	out.write("  br label %return_" + fun.name + "\n");
	out.write("return_" + fun.name + ":\n");
	if(fun.dataType.name == 'void') {
		out.write("  ret void\n");
	} else {
		tmp = newTmp();
		out.write("  " + tmp + " = load ");
		outDataType(out, fun.dataType);
		out.write(", ");
		outDataType(out, fun.dataType);
		out.write("* %result\n");
		out.write("  ret ");
		outDataType(out, fun.dataType);
		out.write(" "+tmp+"\n");
	}
	out.write("}\n\n");
}

function outExternalFunction(out, fun) {
	out.write("declare ");
	outDataType(out, fun.dataType);
	out.write(" ");

Changes to src/radicalc.js.

216
217
218
219
220
221
222

223
224
225
226
  	console.error(`exec error: ${error}`);
  	return;
  }
  console.log(stdout);
});

/* todo:

 - unsigned intrinsics
 - how to handle lack of returns?
 - strings?
*/







>

<


216
217
218
219
220
221
222
223
224

225
226
  	console.error(`exec error: ${error}`);
  	return;
  }
  console.log(stdout);
});

/* todo:
 - modulo operator
 - unsigned intrinsics

 - strings?
*/