Codebase list surgescript / 560aba6
New upstream snapshot. Debian Janitor 1 year, 4 months ago
72 changed file(s) with 164 addition(s) and 178 deletion(s). Raw diff Collapse all Expand all
+0
-12
.github/FUNDING.yml less more
0 # These are supported funding model platforms
1
2 github: alemart # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3 patreon: # Replace with a single Patreon username
4 open_collective: # Replace with a single Open Collective username
5 ko_fi: # Replace with a single Ko-fi username
6 tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
7 community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
8 liberapay: # Replace with a single Liberapay username
9 issuehunt: # Replace with a single IssueHunt username
10 otechie: # Replace with a single Otechie username
11 custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+0
-34
.gitignore less more
0 # Specifies intentionally untracked files to ignore when using Git
1 # http://git-scm.com/docs/gitignore
2
3 # vscode
4 .vscode
5 .vscode/*
6 !.vscode/settings.json
7 !.vscode/tasks.json
8 !.vscode/launch.json
9 !.vscode/extensions.json
10
11 # msvc
12 .vs/
13 out/
14 CMakeSettings.json
15
16 # vim
17 # swap
18 [._]*.s[a-v][a-z]
19 [._]*.sw[a-p]
20 [._]s[a-v][a-z]
21 [._]sw[a-p]
22 # session
23 Session.vim
24 # temporary
25 .netrwhist
26 *~
27
28 # mine
29 docs_html/
30 build/
31 private/
32 CMakeFiles/
33 !src/**
00 # Release Notes
1
2 ## 0.5.6.1 - September 22nd, 2022
3
4 * Tweaks to the build system
15
26 ## 0.5.6 - September 1st, 2022
37
77 cmake_minimum_required(VERSION 3.2)
88 project(
99 surgescript
10 VERSION 0.5.6
10 VERSION 0.5.7
1111 LANGUAGES C
1212 )
1313 include(GNUInstallDirs)
130130 generate_file("misc/info.c")
131131 generate_file("util/version.h")
132132
133 # Use relative paths in __FILE__
134 function(drop_compilation_paths TARGET)
135 if(NOT MSVC)
136 target_compile_options(${TARGET} PUBLIC "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.")
137 endif()
138 endfunction()
139
133140 # Build the library
134141 if(NOT WANT_SHARED AND NOT WANT_STATIC)
135142 message(FATAL_ERROR "Options WANT_SHARED and WANT_STATIC are both set to OFF. Nothing to do.")
144151 target_link_libraries(surgescript m)
145152 endif()
146153 set_target_properties(surgescript PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${LIB_SOVERSION})
147 install(TARGETS surgescript DESTINATION "${CMAKE_INSTALL_LIBDIR}")
154 drop_compilation_paths(surgescript)
148155 endif()
149156
150157 if(WANT_STATIC)
155162 target_link_libraries(surgescript-static m)
156163 endif ()
157164 set_target_properties(surgescript-static PROPERTIES VERSION ${PROJECT_VERSION})
158 install(TARGETS surgescript-static DESTINATION "${CMAKE_INSTALL_LIBDIR}")
159 endif()
160
161 # Install headers
165 drop_compilation_paths(surgescript-static)
166 endif()
167
168 # Install the headers
162169 install(DIRECTORY src/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.h")
163170 install(DIRECTORY "${CMAKE_BINARY_DIR}/src/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.h")
171
172 # Install the library
173 if(WANT_SHARED)
174 install(TARGETS surgescript DESTINATION "${CMAKE_INSTALL_LIBDIR}")
175 endif()
176
177 if(WANT_STATIC)
178 install(TARGETS surgescript-static DESTINATION "${CMAKE_INSTALL_LIBDIR}")
179 endif()
164180
165181 # Build the SurgeScript CLI
166182 if(WANT_EXECUTABLE)
176192 set(LIBTHREAD "")
177193 set(ENABLE_THREADS 0)
178194 if(WANT_EXECUTABLE_MULTITHREAD)
179 message(STATUS "Will use multithreading on the SurgeScript CLI")
180
181 # hmmmm...
182 set(LIBTHREAD "pthread")
183 set(ENABLE_THREADS 1)
195
196 # Header search
197 find_path(THREADS_H NAMES "threads.h" PATHS "${CMAKE_INCLUDE_PATH}")
198 if(NOT THREADS_H)
199 message(WARNING "Can't find threads.h. Will not use multithreading on the SurgeScript CLI")
200 else()
201 message(STATUS "Will use multithreading on the SurgeScript CLI")
202 set(ENABLE_THREADS 1)
203
204 # hmmmm...
205 set(LIBTHREAD "pthread")
206 endif()
207
184208 endif()
185209
186210 # Create the executable
190214 target_link_libraries(surgescript.bin ${LIBSURGESCRIPT} ${LIBTHREAD})
191215 target_include_directories(surgescript.bin PRIVATE src)
192216 set_target_properties(surgescript.bin PROPERTIES OUTPUT_NAME surgescript)
217 drop_compilation_paths(surgescript.bin)
193218
194219 # WebAssembly
195220 if(EMSCRIPTEN)
0 surgescript (0.5.6-1) UNRELEASED; urgency=low
0 surgescript (0.5.6.1+git20221022.1.eec5a3d-1) UNRELEASED; urgency=low
11
22 * New upstream release.
3 * New upstream snapshot.
34
4 -- Debian Janitor <janitor@jelmer.uk> Thu, 08 Sep 2022 11:22:06 -0000
5 -- Debian Janitor <janitor@jelmer.uk> Mon, 19 Dec 2022 10:08:55 -0000
56
67 surgescript (0.5.4.4-1) unstable; urgency=medium
78
00 //
11 // package.ss
22 // Package example
3 // Copyright 2018, 2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 // Copyright 2018-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
44 //
55
66 // import the package
00 //
11 // unit_testing.ss
22 // A Unit Testing Script for SurgeScript
3 // Copyright (C) 2017-2020 Alexandre Martins <alemartf(at)gmail(dot)com>
3 // Copyright 2017-2020 Alexandre Martins <alemartf(at)gmail(dot)com>
44 //
55
66 object "Application"
22 site_author: 'Alexandre Martins'
33 site_description: 'SurgeScript is a scripting language for games.'
44 site_dir: 'docs_html/'
5 copyright: 'SurgeScript is a scripting language for games. Copyright © 2016-2021 Alexandre Martins.'
5 copyright: 'SurgeScript is a scripting language for games. Copyright © 2016-2022 Alexandre Martins.'
66 google_analytics: ['UA-120511928-1', 'opensurge2d.org']
77 repo_url: 'https://github.com/alemart/surgescript'
88 strict: false
1919 */
2020
2121 #include <surgescript.h>
22 #include <locale.h>
2223 #include <string.h>
2324 #include <stdio.h>
2425
5152 int main(int argc, char* argv[])
5253 {
5354 uint64_t time_limit = DEFAULT_TIME_LIMIT;
55
56 /* SurgeScript uses UTF-8 */
57 setlocale(LC_ALL, "en_US.UTF-8");
5458
5559 /* Create the VM and compile the input file(s) */
5660 surgescript_vm_t* vm = make_vm(argc, argv, &time_limit);
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
2222 #include <stdlib.h>
2323 #include <string.h>
2424 #include <locale.h>
25 #include <errno.h>
2625 #include <ctype.h>
2726 #include "parser.h"
2827 #include "lexer.h"
182181 return ssfree(parser);
183182 }
184183
184
185185 /*
186 * surgescript_parser_parsefile()
187 * Parse a script file; returns false on error
186 * surgescript_parser_parse()
187 * Parse a script stored in memory
188 * You may pass NULL to the (optional) filename if the script doesn't belong to a (possibly virtual) file
188189 */
189 bool surgescript_parser_parsefile(surgescript_parser_t* parser, const char* absolute_path)
190 {
191 FILE* fp = surgescript_util_fopen_utf8(absolute_path, "rb"); /* use binary mode, so offsets don't get messed up */
192 if(fp) {
193 const size_t BUFSIZE = 1024;
194 char* data = NULL;
195 size_t read_chars = 0, data_size = 0;
196
197 /* read file to data[] */
198 sslog("Reading file %s...", absolute_path);
199 do {
200 data_size += BUFSIZE;
201 data = ssrealloc(data, data_size + 1);
202 read_chars += fread(data + read_chars, sizeof(char), BUFSIZE, fp);
203 data[read_chars] = '\0';
204 } while(read_chars == data_size);
205 fclose(fp);
206
207 /* parse it */
208 ssfree(parser->filename);
209 parser->filename = ssstrdup(surgescript_util_basename(absolute_path));
210 surgescript_lexer_set(parser->lexer, data);
211 parse(parser);
212
213 /* done! */
214 ssfree(data);
215 return true;
216 }
217 else {
218 ssfatal("Parse Error: can't read file \"%s\": %s", absolute_path, strerror(errno));
219 return false;
220 }
221 }
222
223 /*
224 * surgescript_parser_parsemem()
225 * Parse a script stored in memory
226 */
227 bool surgescript_parser_parsemem(surgescript_parser_t* parser, const char* code_in_memory)
190 bool surgescript_parser_parse(surgescript_parser_t* parser, const char* code_in_memory, const char* filename)
228191 {
229192 ssfree(parser->filename);
230 parser->filename = ssstrdup("<memory>");
193 parser->filename = ssstrdup(filename != NULL ? filename : "<memory>");
231194 surgescript_lexer_set(parser->lexer, code_in_memory);
232195 parse(parser);
233196 return true;
234197 }
198
199
235200
236201 /*
237202 * surgescript_parser_filename()
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
148148 surgescript_parser_t* surgescript_parser_destroy(surgescript_parser_t* parser);
149149
150150 /* operations */
151 bool surgescript_parser_parsefile(surgescript_parser_t* parser, const char* absolute_path); /* parse a script file */
152 bool surgescript_parser_parsemem(surgescript_parser_t* parser, const char* code_in_memory); /* parse a script (in memory) */
151 bool surgescript_parser_parse(surgescript_parser_t* parser, const char* code_in_memory, const char* filename); /* parse a script in memory with an optional filename */
153152 void surgescript_parser_foreach_plugin(surgescript_parser_t* parser, void* data, void (*fun)(const char*,void*)); /* foreach plugin object found in any parsed script, run fun(object_name, data) */
154153 void surgescript_parser_set_flags(surgescript_parser_t* parser, surgescript_parser_flags_t flags); /* set parser options (flags) */
155154 surgescript_parser_flags_t surgescript_parser_get_flags(surgescript_parser_t* parser); /* get parser flags */
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
340340
341341 /* generate the bytecode to access the plugin */
342342 surgescript_program_add_line(program, SSOP_MOVO, SSOPu(0), SSOPu(plugin_object));
343 while(next = strchr(tok, '.')) {
343 while((next = strchr(tok, '.')) != NULL) {
344344 *next = 0;
345345 surgescript_program_add_line(program, SSOP_PUSH, SSOPu(0), SSOPu(0));
346346 surgescript_program_add_line(program, SSOP_CALL, SSOPu(
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 #!/bin/bash
11 # This utility packs the Windows build of SurgeScript
2 # Copyright 2016-2021 Alexandre Martins
32
43 UNIX2DOS="todos" #"unix2dos"
54 SOURCE_FOLDER="../../.."
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019, 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018, 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018, 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018, 2020 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2020 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2020 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019, 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019, 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018, 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
1818 * SurgeScript Virtual Machine - Runtime Engine
1919 */
2020
21 #include <locale.h>
21 #include <string.h>
22 #include <errno.h>
2223 #include <time.h>
2324 #include "vm.h"
2425 #include "stack.h"
142143 */
143144 bool surgescript_vm_compile(surgescript_vm_t* vm, const char* absolute_path)
144145 {
145 return surgescript_parser_parsefile(vm->parser, absolute_path);
146 const size_t BUFSIZE = 1024;
147 size_t read_chars = 0, data_size = 0;
148 char* data = NULL;
149
150 /* open the file in binary mode, so that offsets don't get messed up */
151 FILE* fp = surgescript_util_fopen_utf8(absolute_path, "rb");
152 if(!fp) {
153 ssfatal("Can't read file \"%s\": %s", absolute_path, strerror(errno));
154 return false;
155 }
156
157 /* read file to data[] */
158 sslog("Reading file %s...", absolute_path);
159 do {
160 data_size += BUFSIZE * sizeof(char);
161 data = ssrealloc(data, data_size + 1);
162 read_chars += fread(data + read_chars, sizeof(char), BUFSIZE, fp);
163 data[read_chars] = '\0';
164 } while(read_chars == data_size);
165 fclose(fp);
166
167 /* parse it */
168 bool success = surgescript_parser_parse(vm->parser, data, absolute_path);
169
170 /* done! */
171 ssfree(data);
172 return success;
146173 }
147174
148175 /*
149176 * surgescript_vm_compile_code_in_memory()
150 * Compiles the given code, stored in memory
177 * Compiles the given code stored in memory
151178 * Returns true on success; false otherwise
152179 */
153180 bool surgescript_vm_compile_code_in_memory(surgescript_vm_t* vm, const char* code)
154181 {
155 return surgescript_parser_parsemem(vm->parser, code);
182 return surgescript_parser_parse(vm->parser, code, NULL);
183 }
184
185 /*
186 * surgescript_vm_compile_virtual_file()
187 * Compiles the given code stored in memory and specify a virtual filename or filepath
188 * Returns true on success; false otherwise
189 */
190 bool surgescript_vm_compile_virtual_file(surgescript_vm_t* vm, const char* code, const char* filename)
191 {
192 return surgescript_parser_parse(vm->parser, code, filename);
156193 }
157194
158195 /*
173210 /* Already launched? */
174211 if(surgescript_vm_is_active(vm))
175212 return;
176
177 /* SurgeScript uses UTF-8 */
178 setlocale(LC_ALL, "en_US.UTF-8");
179213
180214 /* Setup the pseudo-number generator */
181215 surgescript_util_srand(time(NULL));
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018, 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
4242 /* SurgeScript Compiler */
4343 bool surgescript_vm_compile(surgescript_vm_t* vm, const char* absolute_path); /* compiles a file */
4444 bool surgescript_vm_compile_code_in_memory(surgescript_vm_t* vm, const char* code); /* compiles the given code */
45 bool surgescript_vm_compile_virtual_file(surgescript_vm_t* vm, const char* code, const char* filename); /* compiles the given code specifying a virtual filename */
4546
4647 /* VM lifecycle */
4748 bool surgescript_vm_is_active(surgescript_vm_t* vm); /* is the vm active? (i.e., turned on) */
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2018 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2019 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
00 /*
11 * SurgeScript
22 * A scripting language for games
3 * Copyright 2016-2021 Alexandre Martins <alemartf(at)gmail(dot)com>
3 * Copyright 2016-2022 Alexandre Martins <alemartf(at)gmail(dot)com>
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.