Skip to content

Commit 824a6b8

Browse files
committed
Feature(runtime): Implement console_log for number/str/bool
1 parent 6f805a8 commit 824a6b8

6 files changed

Lines changed: 31 additions & 7 deletions

File tree

packages/runtime/helpers.bc

3.52 KB
Binary file not shown.

packages/runtime/helpers.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
#include <string>
2-
#include <sstream>
3-
#include <iostream>
1+
#include <stdio.h>
42

53
#include "helpers.h"
64

7-
__attribute__ ((visibility ("default"))) const char* number2string(double number) {
5+
LIBRARY_EXPORT const char* number2string(double number) {
86
char* result = new char[100];
97

108
sprintf(result, "%f", number);
119

1210
return result;
1311
}
12+
13+
LIBRARY_EXPORT void console_log(double number) {
14+
puts(number2string(number));
15+
}
16+
17+
LIBRARY_EXPORT void console_log(const char *str) {
18+
puts(str);
19+
}
20+
21+
LIBRARY_EXPORT void console_log(bool boolean) {
22+
if (boolean) {
23+
puts("true");
24+
} else {
25+
puts("false");
26+
}
27+
}

packages/runtime/helpers.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
#ifndef HLVM_RUNTIME_HELPERS_H
33
#define HLVM_RUNTIME_HELPERS_H
44

5-
__attribute__ ((visibility ("default"))) const char* number2string(double number);
5+
#define LIBRARY_EXPORT __attribute__ ((visibility ("default")))
6+
7+
LIBRARY_EXPORT const char* number2string(double number);
8+
9+
LIBRARY_EXPORT void console_log(double number);
10+
LIBRARY_EXPORT void console_log(const char *str);
11+
LIBRARY_EXPORT void console_log(bool boolean);
612

713
#endif //HLVM_RUNTIME_HELPERS_H

packages/runtime/lib.runtime.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11

22
declare function number2string(value: number): string;
3+
4+
declare function console_log(value: number): void;
5+
declare function console_log(value: string): void;
6+
declare function console_log(value: boolean): void;

packages/runtime/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@static-script/runtime",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)